/
output-handler.spec.ts
34 lines (26 loc) · 1.04 KB
/
output-handler.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createTestContext, setUpInit, SimpleGitTestContext, wait } from '@simple-git/test-utils';
describe('outputHandler', function () {
let context: SimpleGitTestContext;
beforeEach(async () => (context = await createTestContext()));
beforeEach(async () => {
await setUpInit(context);
await context.files('aaa.txt', 'bbb.txt', 'ccc.other');
});
it('using the outputHandler to count currently running processes', async () => {
let processes = new Set();
const currentlyRunning = () => processes.size;
const git = context.git.outputHandler((_x, stdout, stderr) => {
const start = new Date();
const onClose = () => processes.delete(start);
stdout.on('close', onClose);
stderr.on('close', onClose);
processes.add(start);
});
expect(currentlyRunning()).toBe(0);
const queue = [git.init(), git.add('*.txt')];
await wait(0);
expect(currentlyRunning()).toBe(2);
await Promise.all(queue);
expect(currentlyRunning()).toBe(0);
});
});