nodejs/test/parallel/test-node-output-eval.mjs
Shelley Vohr ee8939c82f
test: make eval snapshot comparison more flexible
PR-URL: https://github.com/nodejs/node/pull/57020
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-02-23 19:40:51 +00:00

49 lines
1.3 KiB
JavaScript

import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import { basename } from 'node:path';
import { describe, it } from 'node:test';
describe('eval output', { concurrency: true }, () => {
function normalize(str) {
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
.replaceAll(/\d+:\d+/g, '*:*');
}
const defaultTransform = snapshot.transform(
normalize,
snapshot.replaceWindowsLineEndings,
snapshot.replaceWindowsPaths,
snapshot.replaceNodeVersion,
removeStackTraces,
filterEmptyLines,
generalizeProcessName,
);
function removeStackTraces(output) {
return output.replaceAll(/^ *at .+$/gm, '');
}
function filterEmptyLines(output) {
return output.replaceAll(/^\s*$/gm, '');
}
function generalizeProcessName(output) {
const baseName = basename(process.argv0 || 'node', '.exe');
return output.replaceAll(`${baseName} --`, '* --');
}
const tests = [
{ name: 'eval/eval_messages.js' },
{ name: 'eval/stdin_messages.js' },
{ name: 'eval/stdin_typescript.js' },
{ name: 'eval/eval_typescript.js' },
];
for (const { name } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), defaultTransform);
});
}
});