Skip to content

Commit b0f47a0

Browse files
committed
test: handle console colorization
The output of console.Console is colorized in Node.js >=20.15 <22.10 due to nodejs/node#51629 and nodejs/node#54677. Handle this in our test cases by comparing the output to the output of console.Console on a PassThrough stream. Signed-off-by: Kevin Locke <[email protected]>
1 parent 8d1f9f8 commit b0f47a0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

test/cli.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,17 @@ describe('noderegression command', () => {
227227
assert(brOptions.console instanceof console.Console);
228228
brOptions.console.info('info test');
229229
brOptions.console.error('error test');
230+
231+
// Note: Output of console.Console is colorized on Node.js >=20.15 <22.10
232+
// due to nodejs/node#51629 and nodejs/node#54677
233+
const testStream = new stream.PassThrough({ encoding: 'utf8' });
234+
// eslint-disable-next-line no-console
235+
const testConsole = new console.Console(testStream);
236+
testConsole.info('info test');
237+
testConsole.error('error test');
238+
230239
assert.strictEqual(options.stdout.read(), null);
231-
assert.strictEqual(options.stderr.read(), 'info test\nerror test\n');
240+
assert.strictEqual(options.stderr.read(), testStream.read());
232241
});
233242

234243
it('passes through options.env', async () => {
@@ -475,9 +484,19 @@ describe('noderegression command', () => {
475484
for (const level of ['debug', 'info', 'warn', 'error']) {
476485
brConsole[level](level);
477486
}
487+
488+
// Note: Output of console.Console is colorized on Node.js >=20.15 <22.10
489+
// due to nodejs/node#51629 and nodejs/node#54677
490+
const testStream = new stream.PassThrough({ encoding: 'utf8' });
491+
// eslint-disable-next-line no-console
492+
const testConsole = new console.Console(testStream);
493+
for (const level of expectLevels) {
494+
testConsole[level](level);
495+
}
496+
478497
assert.strictEqual(
479498
options.stderr.read(),
480-
`${expectLevels.join('\n')}\n`,
499+
testStream.read(),
481500
);
482501
});
483502
}

0 commit comments

Comments
 (0)