/
process.spec.ts
59 lines (51 loc) · 1.71 KB
/
process.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {mockSpawnProcess, URI, DESTINATION} from './test.helpers';
import Recorder from '../src/recorder';
import { verifyAllOptions } from '../src/validators';
import { Options } from '../src/types';
jest.mock('../src/validators');
beforeEach(() => {
jest.mocked(verifyAllOptions).mockReturnValue([]);
});
it('Spawn arguments with no additional options defined', () => {
function onSpawn (command: string, args: ReadonlyArray<string>, options: Options) {
expect(command).toEqual('ffmpeg');
expect(args).toEqual([
'-rtsp_transport', 'tcp',
'-i', URI,
'-reset_timestamps', '1',
'-c:a', 'aac',
'-strftime', '1',
'-strftime_mkdir', '1',
'-hls_time', '600',
'-hls_list_size', '0',
'-hls_segment_filename', '"%Y.%m.%d/%H.%M.%S.mp4"',
'"./$(date +%Y.%m.%d-%H.%M.%S).m3u8"',
]);
expect(options).toEqual({ detached: false, shell: true, cwd: DESTINATION });
}
// @ts-ignore
mockSpawnProcess({ onSpawn });
new Recorder(URI, DESTINATION).start();
});
it('Spawn arguments with options defined', () => {
function onSpawn (command: string, args: ReadonlyArray<string>, options: Options) {
expect(command).toEqual('ffmpeg');
expect(args).toEqual([
'-rtsp_transport', 'tcp',
'-i', URI,
'-reset_timestamps', '1',
'-metadata', 'title="Any video title"',
'-an',
'-strftime', '1',
'-strftime_mkdir', '1',
'-hls_time', '1000',
'-hls_list_size', '0',
'-hls_segment_filename', '"%Y.%m.%d/%H.%M.%S.mp4"',
'"./$(date +%Y.%m.%d-%H.%M.%S).m3u8"',
]);
expect(options).toEqual({ detached: false, shell: true, cwd: DESTINATION });
}
// @ts-ignore
mockSpawnProcess({ onSpawn });
new Recorder(URI, DESTINATION, { title: 'Any video title', segmentTime: 1000, noAudio: true }).start();
});