|
| 1 | +import { Output } from './output' |
| 2 | + |
| 3 | +test(`lib/utility/output#Output`, () => { |
| 4 | + const m = { |
| 5 | + log: jest.fn(), |
| 6 | + error: jest.fn() |
| 7 | + } |
| 8 | + |
| 9 | + const exit = jest.fn() |
| 10 | + Object.assign(process, { exit }) |
| 11 | + |
| 12 | + const output = new Output(m, { verbose: false }) |
| 13 | + output.ok('ref', 'value') |
| 14 | + output.info('ref', 'value') |
| 15 | + output.error('string message' as any) |
| 16 | + output.error({ message: 'error message', stack: 'error stack' } as any) |
| 17 | + |
| 18 | + expect(m.log.mock.calls).toEqual([ |
| 19 | + [ |
| 20 | + "%c ✓ %s: %c%s", |
| 21 | + "color:green", |
| 22 | + "ref", |
| 23 | + "color:grey", |
| 24 | + "value", |
| 25 | + ] |
| 26 | + ]) |
| 27 | + expect(m.error.mock.calls).toEqual([ |
| 28 | + [ |
| 29 | + "%c ✗ %s", |
| 30 | + "color:red", |
| 31 | + "string message", |
| 32 | + ], |
| 33 | + [ |
| 34 | + "", |
| 35 | + ], |
| 36 | + [ |
| 37 | + "%c ✗ %s", |
| 38 | + "color:red", |
| 39 | + "error message", |
| 40 | + ], |
| 41 | + [ |
| 42 | + "", |
| 43 | + ], |
| 44 | + ]) |
| 45 | + expect(exit.mock.calls).toEqual([ |
| 46 | + [1], |
| 47 | + [1], |
| 48 | + ]) |
| 49 | +}) |
| 50 | + |
| 51 | +test(`lib/utility/output#Output (verbose)`, () => { |
| 52 | + const m = { |
| 53 | + log: jest.fn(), |
| 54 | + error: jest.fn() |
| 55 | + } |
| 56 | + |
| 57 | + const exit = jest.fn() |
| 58 | + Object.assign(process, { exit }) |
| 59 | + |
| 60 | + const output = new Output(m, { verbose: true }) |
| 61 | + output.ok('ref', 'value') |
| 62 | + output.info('ref', 'value') |
| 63 | + output.error('string message' as any) |
| 64 | + output.error({ message: 'error message', stack: 'error stack' } as any) |
| 65 | + |
| 66 | + expect(m.log.mock.calls).toEqual([ |
| 67 | + [ |
| 68 | + "%c ✓ %s: %c%s", |
| 69 | + "color:green", |
| 70 | + "ref", |
| 71 | + "color:grey", |
| 72 | + "value", |
| 73 | + ], |
| 74 | + [ |
| 75 | + "%c ❭ %s: %c%s", |
| 76 | + "color:yellow", |
| 77 | + "ref", |
| 78 | + "color:grey", |
| 79 | + "value", |
| 80 | + ], |
| 81 | + ]) |
| 82 | + expect(m.error.mock.calls).toEqual([ |
| 83 | + [ |
| 84 | + "%c ✗ %s", |
| 85 | + "color:red", |
| 86 | + "string message", |
| 87 | + ], |
| 88 | + [ |
| 89 | + "%c%s", |
| 90 | + "color:grey", |
| 91 | + " NO STACK", |
| 92 | + ], |
| 93 | + [ |
| 94 | + "", |
| 95 | + ], |
| 96 | + [ |
| 97 | + "%c ✗ %s", |
| 98 | + "color:red", |
| 99 | + "error message", |
| 100 | + ], |
| 101 | + [ |
| 102 | + "%c%s", |
| 103 | + "color:grey", |
| 104 | + "error stack", |
| 105 | + ], |
| 106 | + [ |
| 107 | + "", |
| 108 | + ], |
| 109 | + ]) |
| 110 | + |
| 111 | + expect(exit.mock.calls).toEqual([ |
| 112 | + [1], |
| 113 | + [1], |
| 114 | + ]) |
| 115 | +}) |
0 commit comments