node/test/parallel/test-node-output-vm.mjs
Moshe Atlow 03db04924f
test: fix output tests when path includes node version
PR-URL: https://github.com/nodejs/node/pull/47843
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-05-05 17:10:31 +00:00

31 lines
1.1 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';
function replaceNodeVersion(str) {
return str.replaceAll(process.version, '*');
}
describe('vm output', { concurrency: true }, () => {
function normalize(str) {
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll(/node:vm:\d+:\d+/g, 'node:vm:*');
}
const defaultTransform = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize, replaceNodeVersion);
const tests = [
{ name: 'vm/vm_caught_custom_runtime_error.js' },
{ name: 'vm/vm_display_runtime_error.js' },
{ name: 'vm/vm_display_syntax_error.js' },
{ name: 'vm/vm_dont_display_runtime_error.js' },
{ name: 'vm/vm_dont_display_syntax_error.js' },
];
for (const { name, transform } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
});
}
});