test: migrate message tests to use assertSnapshot

PR-URL: https://github.com/nodejs/node/pull/47498
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Moshe Atlow
2023-04-27 09:41:58 +03:00
committed by GitHub
parent 8b66dc6ea9
commit b6738c1af0
70 changed files with 274 additions and 84 deletions

View File

@@ -8,14 +8,18 @@ const assert = require('node:assert/strict');
const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\n|$)/g;
const windowNewlineRegexp = /\r/g;
function replaceStackTrace(str) {
return str.replace(stackFramesRegexp, '$1*$7\n');
function replaceStackTrace(str, replacement = '$1*$7\n') {
return str.replace(stackFramesRegexp, replacement);
}
function replaceWindowsLineEndings(str) {
return str.replace(windowNewlineRegexp, '');
}
function replaceWindowsPaths(str) {
return str.replaceAll(path.win32.sep, path.posix.sep);
}
function transform(...args) {
return (str) => args.reduce((acc, fn) => fn(acc), str);
}
@@ -35,12 +39,24 @@ async function assertSnapshot(actual, filename = process.argv[1]) {
}
}
/**
* Spawn a process and assert its output against a snapshot.
* if you want to automatically update the snapshot, run tests with NODE_REGENERATE_SNAPSHOTS=1
* transform is a function that takes the output and returns a string that will be compared against the snapshot
* this is useful for normalizing output such as stack traces
* there are some predefined transforms in this file such as replaceStackTrace and replaceWindowsLineEndings
* both of which can be used as an example for writing your own
* compose multiple transforms by passing them as arguments to the transform function:
* assertSnapshot.transform(assertSnapshot.replaceStackTrace, assertSnapshot.replaceWindowsLineEndings)
*
* @param {string} filename
* @param {function(string): string} [transform]
* @returns {Promise<void>}
*/
async function spawnAndAssert(filename, transform = (x) => x) {
// TODO: Add an option to this function to alternatively or additionally compare stderr.
// For now, tests that want to check stderr or both stdout and stderr can use spawnPromisified.
const flags = common.parseTestFlags(filename);
const { stdout } = await common.spawnPromisified(process.execPath, [...flags, filename]);
await assertSnapshot(transform(stdout), filename);
const { stdout, stderr } = await common.spawnPromisified(process.execPath, [...flags, filename]);
await assertSnapshot(transform(`${stdout}${stderr}`), filename);
}
module.exports = {
@@ -48,6 +64,7 @@ module.exports = {
getSnapshotPath,
replaceStackTrace,
replaceWindowsLineEndings,
replaceWindowsPaths,
spawnAndAssert,
transform,
};

View File

@@ -70,7 +70,7 @@ function parseTestFlags(filename = process.argv[1]) {
fs.closeSync(fd);
const source = buffer.toString('utf8', 0, bytesRead);
const flagStart = source.indexOf('// Flags: --') + 10;
const flagStart = source.search(/\/\/ Flags:\s+--/) + 10;
if (flagStart === 9) {
return [];
@@ -83,7 +83,8 @@ function parseTestFlags(filename = process.argv[1]) {
return source
.substring(flagStart, flagEnd)
.replace(/_/g, '-')
.split(' ');
.split(/\s+/)
.filter(Boolean);
}
// Check for flags. Skip this for workers (both, the `cluster` module and

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
console.log([
'_______________________________________________50',

View File

@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
console.trace('foo');

View File

@@ -1,5 +1,5 @@
Trace: foo
at Object.<anonymous> (*console.js:*:*)
at *
at *
at *
at *

View File

@@ -7,7 +7,7 @@ Object.defineProperty(global, 'console', {
value: {},
});
require('../common');
require('../../common');
// This test checks that, if Node cannot put together the `console` object
// because it is low on stack space while doing so, it can succeed later

View File

@@ -20,6 +20,6 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
console.log('hello world');

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 0;

View File

@@ -1,5 +1,5 @@
before
*test*message*stack_overflow.js:*
*test*fixtures*console*stack_overflow.js:*
JSON.stringify(array);
^

View File

@@ -1,9 +1,9 @@
'use strict';
require('../common');
require('../../common');
const { spawnSync } = require('child_process');
const four = require('../common/fixtures')
const four = require('../../common/fixtures')
.readSync('async-error.js')
.toString()
.split('\n')

View File

@@ -3,4 +3,5 @@ Error: test
at two ([eval]:15:9)
at async three ([eval]:18:3)
at async four ([eval]:22:3)
at async main ([eval]:28:5)
at async main ([eval]:28:5)

View File

@@ -1,9 +1,9 @@
'use strict';
require('../common');
require('../../common');
const { spawnSync } = require('child_process');
const four = require('../common/fixtures')
const four = require('../../common/fixtures')
.readSync('async-error.js')
.toString()
.split('\n')

View File

@@ -4,3 +4,4 @@ Error: test
at async three (file:*/[eval1]:18:3)
at async four (file:*/[eval1]:22:3)
at async main (file:*/[eval1]:28:5)

View File

@@ -1,6 +1,6 @@
'use strict';
require('../common');
const four = require('../fixtures/async-error');
require('../../common');
const four = require('../async-error');
async function main() {
try {

View File

@@ -3,4 +3,4 @@ Error: test
at two (*fixtures*async-error.js:17:9)
at async three (*fixtures*async-error.js:20:3)
at async four (*fixtures*async-error.js:24:3)
at async main (*message*async_error_sync_esm.mjs:6:5)
at async main (*async_error_microtask_main.js:7:5)

View File

@@ -1,6 +1,6 @@
'use strict';
require('../common');
const four = require('../fixtures/async-error');
require('../../common');
const four = require('../async-error');
async function main() {
try {

View File

@@ -1,7 +1,7 @@
Error: test
at one (*fixtures*async-error.js:4:9)
at two (*fixtures*async-error.js:17:9)
at process.processTicksAndRejections (node:internal/process/task_queues:*:*)
at process.processTicksAndRejections (node:internal*process*task_queues:95:5)
at async three (*fixtures*async-error.js:20:3)
at async four (*fixtures*async-error.js:24:3)
at async main (*message*async_error_nexttick_main.js:7:5)
at async main (*async_error_nexttick_main.js:7:5)

View File

@@ -1,5 +1,5 @@
import '../common/index.mjs';
import four from '../fixtures/async-error.js';
import '../../common/index.mjs';
import four from '../async-error.js';
async function main() {
try {

View File

@@ -3,4 +3,4 @@ Error: test
at two (*fixtures*async-error.js:17:9)
at async three (*fixtures*async-error.js:20:3)
at async four (*fixtures*async-error.js:24:3)
at async main (*message*async_error_sync_main.js:7:5)
at async main (file:*/async_error_sync_esm.mjs:6:5)

View File

@@ -1,6 +1,6 @@
'use strict';
require('../common');
const four = require('../fixtures/async-error');
require('../../common');
const four = require('../async-error');
async function main() {
try {

View File

@@ -3,4 +3,4 @@ Error: test
at two (*fixtures*async-error.js:17:9)
at async three (*fixtures*async-error.js:20:3)
at async four (*fixtures*async-error.js:24:3)
at async main (*message*async_error_microtask_main.js:7:5)
at async main (*async_error_sync_main.js:7:5)

View File

@@ -1,7 +1,7 @@
// Flags: --expose-internals
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 1;
const { aggregateTwoErrors } = require('internal/errors');

View File

@@ -1,15 +1,16 @@
*error_aggregateTwoErrors.js:*
throw aggregateTwoErrors(err, originalError);
^
[AggregateError: original] {
code: 'ERR0',
[errors]: [
Error: original
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*) {
at Object.<anonymous> (*error_aggregateTwoErrors.js:*:*) {
code: 'ERR0'
},
Error: second error
at Object.<anonymous> (*test*message*error_aggregateTwoErrors.js:*:*) {
at Object.<anonymous> (*error_aggregateTwoErrors.js:*:*) {
code: 'ERR1'
}
]

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 1;
const assert = require('assert');

View File

@@ -7,7 +7,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1 !== 2
at Object.<anonymous> (*test*message*error_exit.js:*:*) {
at Object.<anonymous> (*error_exit.js:*:*) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 1,

View File

@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 2;
function test() {

View File

@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 2;
const EventEmitter = require('events');

View File

@@ -1,5 +1,5 @@
node:events:*
throw er; // Unhandled 'error' event
throw er; * Unhandled 'error' event
^
Error: foo:bar

View File

@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 1;
const EventEmitter = require('events');

View File

@@ -1,5 +1,5 @@
node:events:*
throw er; // Unhandled 'error' event
throw er; * Unhandled 'error' event
^
Error

View File

@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 1;
const EventEmitter = require('events');

View File

@@ -1,5 +1,5 @@
node:events:*
throw er; // Unhandled 'error' event
throw er; * Unhandled 'error' event
^
Error

View File

@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 1;
const EventEmitter = require('events');

View File

@@ -1,5 +1,5 @@
node:events:*
throw er; // Unhandled 'error' event
throw er; * Unhandled 'error' event
^
Error

View File

@@ -1,7 +1,7 @@
// Flags: --unhandled-rejections=strict
'use strict';
require('../common');
require('../../common');
// Check that the process will exit on the first unhandled rejection in case the
// unhandled rejections mode is set to `'strict'`.

View File

@@ -1,10 +1,11 @@
*promise_always_throw_unhandled.js:*
throw new Error('One');
^
Error: One
at *promise_always_throw_unhandled.js:*:*
at *
at new Promise (<anonymous>)
at Object.<anonymous> (*promise_always_throw_unhandled.js:*:*)
at *
at *
at *
at *

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
// Custom error throwing
// eslint-disable-next-line no-throw-literal

View File

@@ -1,4 +1,5 @@
*test*message*throw_custom_error.js:*
*throw_custom_error.js:*
throw ({ name: 'MyCustomError', message: 'This is a custom message' });
^
{ name: 'MyCustomError', message: 'This is a custom message' }

View File

@@ -21,7 +21,7 @@
/* eslint-disable indent, no-tabs */
'use strict';
require('../common');
require('../../common');
console.error('before');

View File

@@ -1,5 +1,6 @@
before
*test*message*throw_in_line_with_tabs.js:*
*throw_in_line_with_tabs.js:*
throw ({ foo: 'bar' });
^
{ foo: 'bar' }

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
// Custom error throwing
// eslint-disable-next-line no-throw-literal

View File

@@ -1,4 +1,5 @@
*test*message*throw_non_error.js:*
*throw_non_error.js:*
throw ({ foo: 'bar' });
^
{ foo: 'bar' }

View File

@@ -1,25 +1,25 @@
// Flags: --enable-source-maps
'use strict';
require('../common');
require('../../../common');
Error.stackTraceLimit = 5;
process.setSourceMapsEnabled(false);
try {
require('../fixtures/source-map/enclosing-call-site-min.js');
require('../enclosing-call-site-min.js');
} catch (e) {
console.log(e);
}
delete require.cache[require
.resolve('../fixtures/source-map/enclosing-call-site-min.js')];
.resolve('../enclosing-call-site-min.js')];
// Re-enable.
process.setSourceMapsEnabled(true);
try {
require('../fixtures/source-map/enclosing-call-site-min.js');
require('../enclosing-call-site-min.js');
} catch (e) {
console.log(e);
}

View File

@@ -1,22 +1,22 @@
'use strict';
require('../common');
require('../../../common');
Error.stackTraceLimit = 5;
process.setSourceMapsEnabled(true);
try {
require('../fixtures/source-map/enclosing-call-site-min.js');
require('../enclosing-call-site-min.js');
} catch (e) {
console.log(e);
}
delete require.cache[require
.resolve('../fixtures/source-map/enclosing-call-site-min.js')];
.resolve('../enclosing-call-site-min.js')];
process.setSourceMapsEnabled(false);
try {
require('../fixtures/source-map/enclosing-call-site-min.js');
require('../enclosing-call-site-min.js');
} catch (e) {
console.log(e);
}

View File

@@ -1,10 +1,10 @@
// Flags: --enable-source-maps
'use strict';
require('../common');
require('../../../common');
Error.stackTraceLimit = 3;
const fs = require('fs');
const content = fs.readFileSync(require.resolve('../fixtures/source-map/tabs.js'), 'utf8');
const content = fs.readFileSync(require.resolve('../tabs.js'), 'utf8');
eval(content);

View File

@@ -2,9 +2,10 @@
alert "I knew it!"
^
ReferenceError: alert is not defined
at Object.eval (*tabs.coffee:26:2)
at eval (*tabs.coffee:1:14)
at Object.<anonymous> (*source_map_eval.js:*:*)
at Object.<anonymous> (*output*source_map_eval.js:10:1)
Node.js *

View File

@@ -1,7 +1,7 @@
// Flags: --enable-source-maps
'use strict';
require('../common');
require('../../../common');
Error.stackTraceLimit = 2;
require('../fixtures/source-map/no-source.js');
require('../no-source.js');

View File

@@ -1,7 +1,7 @@
// Flags: --enable-source-maps
'use strict';
require('../common');
require('../../../common');
Error.stackTraceLimit = 2;
require('../fixtures/source-map/typescript-throw');
require('../typescript-throw');

View File

@@ -2,8 +2,10 @@ reachable
*typescript-throw.ts:18
throw Error('an exception');
^
Error: an exception
at *typescript-throw.ts:18:11*
at *typescript-throw.ts:24:1*
at branch (*typescript-throw.ts:18:11)
at Object.<anonymous> (*typescript-throw.ts:24:1)
Node.js *

View File

@@ -1,5 +1,5 @@
'use strict';
require('../common');
require('../../common');
const vm = require('vm');
console.error('beginning');

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 4;
const vm = require('vm');

View File

@@ -7,7 +7,7 @@ Error: boo!
at test.vm:1:7
at Script.runInThisContext (node:vm:*)
at Object.runInThisContext (node:vm:*)
at Object.<anonymous> (*test*message*vm_display_runtime_error.js:*)
at Object.<anonymous> (*fixtures*vm*vm_display_runtime_error.js:31:6)
test.vm:1
throw new Error("spooky!")
^
@@ -16,6 +16,6 @@ Error: spooky!
at test.vm:1:7
at Script.runInThisContext (node:vm:*)
at Object.runInThisContext (node:vm:*)
at Object.<anonymous> (*test*message*vm_display_runtime_error.js:*)
at Object.<anonymous> (*fixtures*vm*vm_display_runtime_error.js:36:4)
Node.js *

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 4;
const vm = require('vm');

View File

@@ -2,18 +2,20 @@ beginning
foo.vm:1
var 4;
^
SyntaxError: Unexpected number
at new Script (node:vm:*)
at createScript (node:vm:*)
at Object.runInThisContext (node:vm:*)
at Object.<anonymous> (*test*message*vm_display_syntax_error.js:*)
at Object.<anonymous> (*fixtures*vm*vm_display_syntax_error.js:31:6)
test.vm:1
var 5;
^
SyntaxError: Unexpected number
at new Script (node:vm:*)
at createScript (node:vm:*)
at Object.runInThisContext (node:vm:*)
at Object.<anonymous> (*test*message*vm_display_syntax_error.js:*)
at Object.<anonymous> (*fixtures*vm*vm_display_syntax_error.js:36:4)
Node.js *

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 4;
const vm = require('vm');

View File

@@ -8,6 +8,6 @@ Error: boo!
at test.vm:1:7
at Script.runInThisContext (node:vm:*)
at Object.runInThisContext (node:vm:*)
at Object.<anonymous> (*test*message*vm_dont_display_runtime_error.js:*)
at Object.<anonymous> (*fixtures*vm*vm_dont_display_runtime_error.js:41:4)
Node.js *

View File

@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
require('../../common');
Error.stackTraceLimit = 4;
const vm = require('vm');

View File

@@ -8,6 +8,6 @@ SyntaxError: Unexpected number
at new Script (node:vm:*)
at createScript (node:vm:*)
at Object.runInThisContext (node:vm:*)
at Object.<anonymous> (*test*message*vm_dont_display_syntax_error.js:*)
at Object.<anonymous> (*fixtures*vm*vm_dont_display_syntax_error.js:41:4)
Node.js *

View File

@@ -0,0 +1,36 @@
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, '*');
}
function replaceStackTrace(str) {
return snapshot.replaceStackTrace(str, '$1at *$7\n');
}
describe('console output', { concurrency: true }, () => {
function stackTrace(str) {
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('/', '*').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.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion, stackTrace)
},
];
const defaultTransform = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceStackTrace);
for (const { name, transform } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
});
}
});

View File

@@ -0,0 +1,52 @@
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, '*');
}
function replaceStackTrace(str) {
return snapshot.replaceStackTrace(str, '$1at *$7\n');
}
describe('errors output', { concurrency: true }, () => {
function normalize(str) {
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*errors*', '*').replaceAll('file:**', 'file:*/');
}
function normalizeNoNumbers(str) {
return normalize(str).replaceAll(/\d+:\d+/g, '*:*').replaceAll(/:\d+/g, ':*').replaceAll('*fixtures*message*', '*');
}
const common = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion);
const defaultTransform = snapshot.transform(common, normalize);
const errTransform = snapshot.transform(common, normalizeNoNumbers);
const promiseTransform = snapshot.transform(common, replaceStackTrace, normalizeNoNumbers);
const tests = [
{ name: 'errors/async_error_eval_cjs.js' },
{ name: 'errors/async_error_eval_esm.js' },
{ name: 'errors/async_error_microtask_main.js' },
{ name: 'errors/async_error_nexttick_main.js' },
{ name: 'errors/async_error_sync_main.js' },
{ name: 'errors/async_error_sync_esm.mjs' },
{ name: 'errors/error_aggregateTwoErrors.js', transform: errTransform },
{ name: 'errors/error_exit.js', transform: errTransform },
{ name: 'errors/error_with_nul.js', transform: errTransform },
{ name: 'errors/events_unhandled_error_common_trace.js', transform: errTransform },
{ name: 'errors/events_unhandled_error_nexttick.js', transform: errTransform },
{ name: 'errors/events_unhandled_error_sameline.js', transform: errTransform },
{ name: 'errors/events_unhandled_error_subclass.js', transform: errTransform },
{ name: 'errors/throw_custom_error.js', transform: errTransform },
{ name: 'errors/throw_in_line_with_tabs.js', transform: errTransform },
{ name: 'errors/throw_non_error.js', transform: errTransform },
{ name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform },
];
for (const { name, transform } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
});
}
});

View File

@@ -0,0 +1,42 @@
import * as common from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import * as path from 'node:path';
import { describe, it } from 'node:test';
function replaceNodeVersion(str) {
return str.replaceAll(process.version, '*');
}
describe('sourcemaps output', { concurrency: true }, () => {
function normalize(str) {
const result = str
.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
.replaceAll('//', '*')
.replaceAll('/Users/bencoe/oss/coffee-script-test', '')
.replaceAll(/\/(\w)/g, '*$1')
.replaceAll('*test*', '*')
.replaceAll('*fixtures*source-map*', '*');
if (common.isWindows) {
const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi');
return result.replaceAll(regex, '');
}
return result;
}
const defaultTransform = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceNodeVersion, normalize);
const tests = [
{ name: 'source-map/output/source_map_disabled_by_api.js' },
{ name: 'source-map/output/source_map_enabled_by_api.js' },
{ name: 'source-map/output/source_map_eval.js' },
{ name: 'source-map/output/source_map_no_source_file.js' },
{ name: 'source-map/output/source_map_throw_first_tick.js' },
];
for (const { name, transform } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
});
}
});

View File

@@ -0,0 +1,30 @@
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, replaceNodeVersion, normalize);
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);
});
}
});