Files
node/test/parallel/test-node-output-console.mjs
T
Chengzhong Wu b064ddc221 test: unify assertSnapshot common patterns
Unifes assertSnapshot common patterns like platform specific path
separators, line ending, line trailing spaces, Node.js version strings,
and pids in warning messages.

PR-URL: https://github.com/nodejs/node/pull/61590
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-02-08 10:08:58 +01:00

46 lines
1.4 KiB
JavaScript

import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import { describe, it } from 'node:test';
const skipForceColors =
process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' ||
process.config.variables.node_shared_openssl;
function replaceStackTrace(str) {
return snapshot.replaceStackTrace(str, '$1at *$7\n');
}
describe('console output', { concurrency: !process.env.TEST_PARALLEL }, () => {
function normalize(str) {
return str.replaceAll(/\d+/g, '*');
}
const tests = [
{ name: 'console/2100bytes.js' },
{ name: 'console/console_low_stack_space.js' },
{ name: 'console/console.js' },
{ name: 'console/hello_world.js' },
{
name: 'console/stack_overflow.js',
transform: snapshot
.transform(
snapshot.basicTransform,
snapshot.transformProjectRoot(),
normalize
)
},
!skipForceColors ? { name: 'console/force_colors.js', env: { FORCE_COLOR: 1 } } : null,
].filter(Boolean);
const defaultTransform = snapshot
.transform(snapshot.basicTransform, replaceStackTrace);
for (const { name, transform, env } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(
fixtures.path(name),
transform ?? defaultTransform,
{ env: { ...env, ...process.env } },
);
});
}
});