-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathmonitored-process_spec.ts
50 lines (44 loc) · 1.64 KB
/
monitored-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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { dirname } from 'path';
import { toArray } from 'rxjs/operators';
import { Command } from './command';
import { LocalMonitoredProcess } from './monitored-process';
describe('LocalMonitoredProcess', () => {
const cmd = new Command(
'node',
['test-script.js'],
dirname(require.resolve('./test/test-script.js')),
);
it('works', async () => {
const process = new LocalMonitoredProcess(cmd);
const res = await process.run().pipe(toArray()).toPromise();
expect(res).toEqual([0]);
});
it('captures stdout', async () => {
const process = new LocalMonitoredProcess(cmd);
const stdoutOutput: string[] = [];
process.stdout$.subscribe(data => stdoutOutput.push(data.toString()));
await process.run().pipe().toPromise();
expect(stdoutOutput).toEqual(['stdout start\n', 'stdout end\n']);
});
it('captures stderr', async () => {
const process = new LocalMonitoredProcess(cmd);
const stdoutOutput: string[] = [];
process.stderr$.subscribe(data => stdoutOutput.push(data.toString()));
await process.run().pipe().toPromise();
expect(stdoutOutput).toEqual(['stderr start\n', 'stderr end\n']);
});
it('captures stats', async () => {
const process = new LocalMonitoredProcess(cmd);
const statsOutput: string[] = [];
process.stderr$.subscribe(data => statsOutput.push(data.toString()));
await process.run().pipe().toPromise();
expect(statsOutput.length).toBeGreaterThan(0);
});
});