|
1 | 1 | import { describe, it } from 'node:test';
|
2 |
| -import console from '../../reporters/console.mjs'; |
3 | 2 | import assert from 'node:assert';
|
| 3 | +import reporter from '../../reporters/console.mjs'; |
4 | 4 | import { errorIssue, infoIssue, warnIssue } from '../fixtures/issues.mjs';
|
5 | 5 |
|
6 |
| -describe('console', () => { |
7 |
| - it('should write to stdout with the correct colors based on the issue level', t => { |
8 |
| - t.mock.method(process.stdout, 'write'); |
9 |
| - |
10 |
| - console(infoIssue); |
11 |
| - console(warnIssue); |
12 |
| - console(errorIssue); |
| 6 | +const testCases = [ |
| 7 | + { |
| 8 | + issue: infoIssue, |
| 9 | + method: 'info', |
| 10 | + expected: '\x1B[90mThis is a INFO issue at doc/api/test.md\x1B[39m', |
| 11 | + }, |
| 12 | + { |
| 13 | + issue: warnIssue, |
| 14 | + method: 'warn', |
| 15 | + expected: '\x1B[33mThis is a WARN issue at doc/api/test.md (1:1)\x1B[39m', |
| 16 | + }, |
| 17 | + { |
| 18 | + issue: errorIssue, |
| 19 | + method: 'error', |
| 20 | + expected: '\x1B[31mThis is a ERROR issue at doc/api/test.md (1:1)\x1B[39m', |
| 21 | + }, |
| 22 | +]; |
13 | 23 |
|
14 |
| - assert.strictEqual(process.stdout.write.mock.callCount(), 3); |
| 24 | +describe('console', () => { |
| 25 | + testCases.forEach(({ issue, method, expected }) => { |
| 26 | + it(`should use correct colors and output on ${method} issues`, t => { |
| 27 | + t.mock.method(console, method); |
| 28 | + const mock = console[method].mock; |
15 | 29 |
|
16 |
| - const callsArgs = process.stdout.write.mock.calls.map(call => |
17 |
| - call.arguments[0].trim() |
18 |
| - ); |
| 30 | + reporter(issue); |
19 | 31 |
|
20 |
| - assert.deepStrictEqual(callsArgs, [ |
21 |
| - '\x1B[90mThis is a INFO issue at doc/api/test.md\x1B[39m', |
22 |
| - '\x1B[33mThis is a WARN issue at doc/api/test.md (1:1)\x1B[39m', |
23 |
| - '\x1B[31mThis is a ERROR issue at doc/api/test.md (1:1)\x1B[39m', |
24 |
| - ]); |
| 32 | + assert.strictEqual(mock.callCount(), 1); |
| 33 | + assert.deepStrictEqual(mock.calls[0].arguments, [expected]); |
| 34 | + }); |
25 | 35 | });
|
26 | 36 | });
|
0 commit comments