|
1 | 1 | import winston from 'winston'; |
2 | | -import { expect, test as fancy } from '@oclif/test'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { runCommand } from '@oclif/test'; |
| 4 | +import fancy from 'fancy-test'; |
3 | 5 | import { FileTransportInstance } from 'winston/lib/winston/transports'; |
4 | 6 |
|
5 | 7 | import { AuditBaseCommand } from '../../../src/audit-base-command'; |
6 | | - |
7 | 8 | describe('Audit command', () => { |
8 | 9 | const fsTransport = class FsTransport { |
9 | 10 | filename!: string; |
10 | 11 | } as FileTransportInstance; |
11 | 12 |
|
12 | 13 | describe('Audit run method', () => { |
13 | | - const test = fancy.loadConfig({ root: process.cwd() }); |
14 | | - test |
| 14 | + fancy |
15 | 15 | .stdout({ print: process.env.PRINT === 'true' || false }) |
16 | 16 | .stub(winston.transports, 'File', () => fsTransport) |
17 | 17 | .stub(winston, 'createLogger', () => ({ log: () => {}, error: () => {} })) |
18 | 18 | .stub(AuditBaseCommand.prototype, 'start', () => {}) |
19 | | - .command(['cm:stacks:audit']) |
20 | | - .it('should trigger AuditBaseCommand start method', ({ stdout }) => { |
| 19 | + .it('should trigger AuditBaseCommand start method', async () => { |
| 20 | + const { stdout } = await runCommand(['cm:stacks:audit'], { root: process.cwd() }); |
21 | 21 | expect(stdout).to.be.string; |
22 | 22 | }); |
23 | 23 |
|
24 | | - test |
| 24 | + fancy |
25 | 25 | .stderr({ print: false }) |
26 | 26 | .stdout({ print: process.env.PRINT === 'true' || false }) |
27 | 27 | .stub(winston.transports, 'File', () => fsTransport) |
28 | 28 | .stub(winston, 'createLogger', () => ({ log: console.log, error: console.error })) |
29 | 29 | .stub(AuditBaseCommand.prototype, 'start', () => Promise.reject('process failed')) |
30 | | - .command(['cm:stacks:audit']) |
31 | | - .exit(1) |
32 | | - .it('should log any error and exit with status code 1'); |
| 30 | + .it('should log any error and exit with status code 1', async () => { |
| 31 | + await runCommand(['cm:stacks:audit'], { root: process.cwd() }); |
| 32 | + }); |
33 | 33 |
|
34 | | - test |
| 34 | + fancy |
35 | 35 | .stderr({ print: false }) |
36 | 36 | .stdout({ print: process.env.PRINT === 'true' || false }) |
37 | 37 | .stub(winston.transports, 'File', () => fsTransport) |
38 | 38 | .stub(winston, 'createLogger', () => ({ log: console.log, error: console.error })) |
39 | 39 | .stub(AuditBaseCommand.prototype, 'start', () => { |
40 | 40 | throw Error('process failed'); |
41 | 41 | }) |
42 | | - .command(['cm:stacks:audit']) |
43 | | - .exit(1) |
44 | | - .it('should log the error objet message and exit with status code 1'); |
| 42 | + .it('should log the error objet message and exit with status code 1', async () => { |
| 43 | + await runCommand(['cm:stacks:audit'], { root: process.cwd() }); |
| 44 | + }); |
45 | 45 | }); |
46 | 46 | }); |
0 commit comments