Skip to content

Commit 9431f78

Browse files
committed
fix tests
1 parent 3aed77f commit 9431f78

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
import { describe, it } from 'node:test';
2-
import console from '../../reporters/console.mjs';
32
import assert from 'node:assert';
3+
import reporter from '../../reporters/console.mjs';
44
import { errorIssue, infoIssue, warnIssue } from '../fixtures/issues.mjs';
55

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+
];
1323

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;
1529

16-
const callsArgs = process.stdout.write.mock.calls.map(call =>
17-
call.arguments[0].trim()
18-
);
30+
reporter(issue);
1931

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+
});
2535
});
2636
});

0 commit comments

Comments
 (0)