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