|
1 | | -import { PassThrough } from 'stream'; |
2 | | -import cli from './cli'; |
3 | | - |
4 | | -describe('cli()', () => { |
5 | | - it('should return stdout with exitcode=0', async () => { |
6 | | - const stdout = new PassThrough(); |
7 | | - const stderr = new PassThrough(); |
8 | | - const outData = jest.fn(); |
9 | | - stdout.on('data', outData); |
10 | | - const errData = jest.fn(); |
11 | | - stderr.on('data', errData); |
12 | | - expect( |
13 | | - await cli({ |
14 | | - filename: 'test/assets/test.txt', |
15 | | - stdout, |
16 | | - stderr |
17 | | - }) |
18 | | - ).toEqual(0); |
19 | | - expect(outData.mock.calls.length).toEqual(1); |
20 | | - expect(outData.mock.calls[0][0].toString('utf8')).toEqual( |
21 | | - 'test/assets/test.txt: 15 chars\n' |
22 | | - ); |
23 | | - expect(errData.mock.calls.length).toEqual(0); |
24 | | - }); |
25 | | - it('should return stderr with exitcode=1', async () => { |
26 | | - const stdout = new PassThrough(); |
27 | | - const stderr = new PassThrough(); |
28 | | - const outData = jest.fn(); |
29 | | - stdout.on('data', outData); |
30 | | - const errData = jest.fn(); |
31 | | - stderr.on('data', errData); |
32 | | - expect( |
33 | | - await cli({ |
34 | | - filename: 'test/assets/fail.txt', |
35 | | - stdout, |
36 | | - stderr |
37 | | - }) |
38 | | - ).toEqual(1); |
39 | | - expect(outData.mock.calls.length).toEqual(0); |
40 | | - expect(errData.mock.calls.length).toEqual(2); |
41 | | - expect(errData.mock.calls[0][0].toString('utf8')).toEqual( |
42 | | - "Error: ENOENT: no such file or directory, open 'test/assets/fail.txt'" |
43 | | - ); |
44 | | - expect(errData.mock.calls[1][0].toString('utf8')).toEqual('\n'); |
45 | | - }); |
46 | | -}); |
| 1 | +import { PassThrough } from 'stream'; |
| 2 | +import cli from './cli'; |
| 3 | + |
| 4 | +describe('cli()', () => { |
| 5 | + it('should return stdout with exitcode=0', async () => { |
| 6 | + const stdout = new PassThrough(); |
| 7 | + const stderr = new PassThrough(); |
| 8 | + const outData = jest.fn(); |
| 9 | + stdout.on('data', outData); |
| 10 | + const errData = jest.fn(); |
| 11 | + stderr.on('data', errData); |
| 12 | + expect( |
| 13 | + await cli({ |
| 14 | + filename: 'test/assets/test.txt', |
| 15 | + stdout, |
| 16 | + stderr |
| 17 | + }) |
| 18 | + ).toEqual(0); |
| 19 | + expect(outData.mock.calls.length).toEqual(1); |
| 20 | + expect(outData.mock.calls[0][0].toString('utf8')).toEqual( |
| 21 | + 'test/assets/test.txt: 15 chars\n' |
| 22 | + ); |
| 23 | + expect(errData.mock.calls.length).toEqual(0); |
| 24 | + }); |
| 25 | + it('should return stderr with exitcode=1', async () => { |
| 26 | + const stdout = new PassThrough(); |
| 27 | + const stderr = new PassThrough(); |
| 28 | + const outData = jest.fn(); |
| 29 | + stdout.on('data', outData); |
| 30 | + const errData = jest.fn(); |
| 31 | + stderr.on('data', errData); |
| 32 | + expect( |
| 33 | + await cli({ |
| 34 | + filename: 'test/assets/fail.txt', |
| 35 | + stdout, |
| 36 | + stderr |
| 37 | + }) |
| 38 | + ).toEqual(1); |
| 39 | + expect(outData.mock.calls.length).toEqual(0); |
| 40 | + expect(errData.mock.calls.length).toEqual(2); |
| 41 | + expect(errData.mock.calls[0][0].toString('utf8')).toEqual( |
| 42 | + "Error: ENOENT: no such file or directory, open 'test/assets/fail.txt'" |
| 43 | + ); |
| 44 | + expect(errData.mock.calls[1][0].toString('utf8')).toEqual('\n'); |
| 45 | + }); |
| 46 | +}); |
0 commit comments