|
| 1 | +import { expect } from 'vitest'; |
| 2 | +import { executeProcess } from '@code-pushup/utils'; |
| 3 | +import { createExecutionObserver } from './create-execution-observer.js'; |
| 4 | + |
| 5 | +describe('createExecutionObserver', () => { |
| 6 | + const message = 'This is stdout'; |
| 7 | + const error = 'This is stderr'; |
| 8 | + |
| 9 | + it('should use execute process and use observer to capture stdout message and stderr will be empty', async () => { |
| 10 | + const { stdout, stderr } = await executeProcess({ |
| 11 | + command: 'node', |
| 12 | + args: ['-e', `"console.log('${message}');"`], |
| 13 | + observer: createExecutionObserver(), |
| 14 | + }); |
| 15 | + |
| 16 | + expect(stdout).toMatch(message); |
| 17 | + expect(stderr).toMatch(''); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should use execute process and use observer to capture stdout message and stderr will be error', async () => { |
| 21 | + const { stdout, stderr } = await executeProcess({ |
| 22 | + command: 'node', |
| 23 | + args: ['-e', `"console.log('${message}'); console.error('${error}');"`], |
| 24 | + observer: createExecutionObserver(), |
| 25 | + }); |
| 26 | + |
| 27 | + expect(stdout).toMatch(message); |
| 28 | + expect(stderr).toMatch(error); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should use execute process and use observer to capture stderr error and ignore stdout message', async () => { |
| 32 | + const { stdout, stderr } = await executeProcess({ |
| 33 | + command: 'node', |
| 34 | + args: ['-e', `"console.log('${message}'); console.error('${error}');"`], |
| 35 | + observer: createExecutionObserver({ silent: true }), |
| 36 | + }); |
| 37 | + |
| 38 | + expect(stdout).toMatch(''); |
| 39 | + expect(stderr).toMatch(error); |
| 40 | + }); |
| 41 | +}); |
0 commit comments