/
progress.spec.ts
30 lines (22 loc) · 940 Bytes
/
progress.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
import { ChildProcessWithoutNullStreams } from 'child_process';
import { verifyAllOptions } from '../../src/validators';
import {mockSpawnProcess, URI, DESTINATION} from '../test.helpers';
import Recorder, { RecorderEvents } from '../../src/recorder';
jest.mock('../../src/validators');
let fakeProcess: ChildProcessWithoutNullStreams;
let eventHandler: () => void;
beforeEach(() => {
jest.mocked(verifyAllOptions).mockReturnValue([]);
fakeProcess = mockSpawnProcess();
eventHandler = jest.fn().mockName('onProgress');
});
test('should return any ffmpeg progress message', async () => {
new Recorder(URI, DESTINATION)
.on(RecorderEvents.PROGRESS, eventHandler)
.start();
// We have to wait next tick
await Promise.resolve(true);
fakeProcess.stderr.emit('data', Buffer.from('Random progress message', 'utf8'));
expect(eventHandler).toBeCalledTimes(1);
expect(eventHandler).toBeCalledWith('Random progress message');
});