-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcreate-execution-observer.int.test.ts
More file actions
41 lines (34 loc) · 1.44 KB
/
create-execution-observer.int.test.ts
File metadata and controls
41 lines (34 loc) · 1.44 KB
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
import { expect } from 'vitest';
import { executeProcess } from '@code-pushup/utils';
import { createExecutionObserver } from './create-execution-observer.js';
describe('createExecutionObserver', () => {
const message = 'This is stdout';
const error = 'This is stderr';
it('should use execute process and use observer to capture stdout message and stderr will be empty', async () => {
const { stdout, stderr } = await executeProcess({
command: 'node',
args: ['-e', `"console.log('${message}');"`],
observer: createExecutionObserver(),
});
expect(stdout).toMatch(message);
expect(stderr).toMatch('');
});
it('should use execute process and use observer to capture stdout message and stderr will be error', async () => {
const { stdout, stderr } = await executeProcess({
command: 'node',
args: ['-e', `"console.log('${message}'); console.error('${error}');"`],
observer: createExecutionObserver(),
});
expect(stdout).toMatch(message);
expect(stderr).toMatch(error);
});
it('should use execute process and use observer to capture stderr error and ignore stdout message', async () => {
const { stdout, stderr } = await executeProcess({
command: 'node',
args: ['-e', `"console.log('${message}'); console.error('${error}');"`],
observer: createExecutionObserver({ silent: true }),
});
expect(stdout).toMatch('');
expect(stderr).toMatch(error);
});
});