Skip to content

Commit

Permalink
test: handle console colorization
Browse files Browse the repository at this point in the history
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 <kevin@kevinlocke.name>
  • Loading branch information
kevinoid committed Nov 2, 2024
1 parent 8d1f9f8 commit b0f47a0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,17 @@ describe('noderegression command', () => {
assert(brOptions.console instanceof console.Console);
brOptions.console.info('info test');
brOptions.console.error('error test');

// Note: Output of console.Console is colorized on Node.js >=20.15 <22.10
// due to nodejs/node#51629 and nodejs/node#54677
const testStream = new stream.PassThrough({ encoding: 'utf8' });
// eslint-disable-next-line no-console
const testConsole = new console.Console(testStream);
testConsole.info('info test');
testConsole.error('error test');

assert.strictEqual(options.stdout.read(), null);
assert.strictEqual(options.stderr.read(), 'info test\nerror test\n');
assert.strictEqual(options.stderr.read(), testStream.read());
});

it('passes through options.env', async () => {
Expand Down Expand Up @@ -475,9 +484,19 @@ describe('noderegression command', () => {
for (const level of ['debug', 'info', 'warn', 'error']) {
brConsole[level](level);
}

// Note: Output of console.Console is colorized on Node.js >=20.15 <22.10
// due to nodejs/node#51629 and nodejs/node#54677
const testStream = new stream.PassThrough({ encoding: 'utf8' });
// eslint-disable-next-line no-console
const testConsole = new console.Console(testStream);
for (const level of expectLevels) {
testConsole[level](level);
}

assert.strictEqual(
options.stderr.read(),
`${expectLevels.join('\n')}\n`,
testStream.read(),
);
});
}
Expand Down

0 comments on commit b0f47a0

Please sign in to comment.