diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index afde9b5d371cd3..4986103fe92245 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -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} + */ 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, }; diff --git a/test/common/index.js b/test/common/index.js index 92313f33d27c89..41c3579117926d 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -69,7 +69,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 []; @@ -82,7 +82,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 diff --git a/test/message/2100bytes.js b/test/fixtures/console/2100bytes.js similarity index 99% rename from test/message/2100bytes.js rename to test/fixtures/console/2100bytes.js index abd8c4b55246ae..5b2a28451160ec 100644 --- a/test/message/2100bytes.js +++ b/test/fixtures/console/2100bytes.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); console.log([ '_______________________________________________50', diff --git a/test/message/2100bytes.out b/test/fixtures/console/2100bytes.snapshot similarity index 100% rename from test/message/2100bytes.out rename to test/fixtures/console/2100bytes.snapshot diff --git a/test/message/console.js b/test/fixtures/console/console.js similarity index 60% rename from test/message/console.js rename to test/fixtures/console/console.js index e93e27b3d4f5d2..65916e019f38bd 100644 --- a/test/message/console.js +++ b/test/fixtures/console/console.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); console.trace('foo'); diff --git a/test/message/console.out b/test/fixtures/console/console.snapshot similarity index 59% rename from test/message/console.out rename to test/fixtures/console/console.snapshot index 57d56028663120..9aabbe5c5f275a 100644 --- a/test/message/console.out +++ b/test/fixtures/console/console.snapshot @@ -1,5 +1,5 @@ Trace: foo - at Object. (*console.js:*:*) + at * at * at * at * diff --git a/test/message/console_low_stack_space.js b/test/fixtures/console/console_low_stack_space.js similarity index 97% rename from test/message/console_low_stack_space.js rename to test/fixtures/console/console_low_stack_space.js index 8954b777d464f6..5093b0c307be0a 100644 --- a/test/message/console_low_stack_space.js +++ b/test/fixtures/console/console_low_stack_space.js @@ -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 diff --git a/test/message/console_low_stack_space.out b/test/fixtures/console/console_low_stack_space.snapshot similarity index 100% rename from test/message/console_low_stack_space.out rename to test/fixtures/console/console_low_stack_space.snapshot diff --git a/test/message/hello_world.js b/test/fixtures/console/hello_world.js similarity index 97% rename from test/message/hello_world.js rename to test/fixtures/console/hello_world.js index f3b1f8377f37f2..c32cb09f6009b2 100644 --- a/test/message/hello_world.js +++ b/test/fixtures/console/hello_world.js @@ -20,6 +20,6 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); console.log('hello world'); diff --git a/test/message/hello_world.out b/test/fixtures/console/hello_world.snapshot similarity index 100% rename from test/message/hello_world.out rename to test/fixtures/console/hello_world.snapshot diff --git a/test/message/stack_overflow.js b/test/fixtures/console/stack_overflow.js similarity index 98% rename from test/message/stack_overflow.js rename to test/fixtures/console/stack_overflow.js index 9541ee78409b5d..565692b6d6e4ba 100644 --- a/test/message/stack_overflow.js +++ b/test/fixtures/console/stack_overflow.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 0; diff --git a/test/message/stack_overflow.out b/test/fixtures/console/stack_overflow.snapshot similarity index 69% rename from test/message/stack_overflow.out rename to test/fixtures/console/stack_overflow.snapshot index fb378994672288..e723d53adc866e 100644 --- a/test/message/stack_overflow.out +++ b/test/fixtures/console/stack_overflow.snapshot @@ -1,5 +1,5 @@ before -*test*message*stack_overflow.js:* +*test*fixtures*console*stack_overflow.js:* JSON.stringify(array); ^ diff --git a/test/message/async_error_eval_cjs.js b/test/fixtures/errors/async_error_eval_cjs.js similarity index 88% rename from test/message/async_error_eval_cjs.js rename to test/fixtures/errors/async_error_eval_cjs.js index d76cabeab116d7..22fbe876582c17 100644 --- a/test/message/async_error_eval_cjs.js +++ b/test/fixtures/errors/async_error_eval_cjs.js @@ -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') diff --git a/test/message/async_error_eval_cjs.out b/test/fixtures/errors/async_error_eval_cjs.snapshot similarity index 79% rename from test/message/async_error_eval_cjs.out rename to test/fixtures/errors/async_error_eval_cjs.snapshot index a8d89eebcb6ada..ae9979251f6e0c 100644 --- a/test/message/async_error_eval_cjs.out +++ b/test/fixtures/errors/async_error_eval_cjs.snapshot @@ -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) \ No newline at end of file + at async main ([eval]:28:5) + diff --git a/test/message/async_error_eval_esm.js b/test/fixtures/errors/async_error_eval_esm.js similarity index 88% rename from test/message/async_error_eval_esm.js rename to test/fixtures/errors/async_error_eval_esm.js index efacef779b1712..d568902638b94d 100644 --- a/test/message/async_error_eval_esm.js +++ b/test/fixtures/errors/async_error_eval_esm.js @@ -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') diff --git a/test/message/async_error_eval_esm.out b/test/fixtures/errors/async_error_eval_esm.snapshot similarity index 99% rename from test/message/async_error_eval_esm.out rename to test/fixtures/errors/async_error_eval_esm.snapshot index 769fac7a0d408e..0c22264f94de61 100644 --- a/test/message/async_error_eval_esm.out +++ b/test/fixtures/errors/async_error_eval_esm.snapshot @@ -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) + diff --git a/test/message/async_error_microtask_main.js b/test/fixtures/errors/async_error_microtask_main.js similarity index 65% rename from test/message/async_error_microtask_main.js rename to test/fixtures/errors/async_error_microtask_main.js index 5520c650addeac..25822ba2f700c0 100644 --- a/test/message/async_error_microtask_main.js +++ b/test/fixtures/errors/async_error_microtask_main.js @@ -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 { diff --git a/test/message/async_error_sync_esm.out b/test/fixtures/errors/async_error_microtask_main.snapshot similarity index 77% rename from test/message/async_error_sync_esm.out rename to test/fixtures/errors/async_error_microtask_main.snapshot index 6054fc7cc22de0..9d84b96c35de68 100644 --- a/test/message/async_error_sync_esm.out +++ b/test/fixtures/errors/async_error_microtask_main.snapshot @@ -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) diff --git a/test/message/async_error_nexttick_main.js b/test/fixtures/errors/async_error_nexttick_main.js similarity index 65% rename from test/message/async_error_nexttick_main.js rename to test/fixtures/errors/async_error_nexttick_main.js index ecd0531852da8f..8ffa6ae0b9ba56 100644 --- a/test/message/async_error_nexttick_main.js +++ b/test/fixtures/errors/async_error_nexttick_main.js @@ -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 { diff --git a/test/message/async_error_nexttick_main.out b/test/fixtures/errors/async_error_nexttick_main.snapshot similarity index 58% rename from test/message/async_error_nexttick_main.out rename to test/fixtures/errors/async_error_nexttick_main.snapshot index 9669e9b5102ff9..eff2c0569cce82 100644 --- a/test/message/async_error_nexttick_main.out +++ b/test/fixtures/errors/async_error_nexttick_main.snapshot @@ -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) diff --git a/test/message/async_error_sync_esm.mjs b/test/fixtures/errors/async_error_sync_esm.mjs similarity index 57% rename from test/message/async_error_sync_esm.mjs rename to test/fixtures/errors/async_error_sync_esm.mjs index fdb6a260d1284b..d368ad53f9e172 100644 --- a/test/message/async_error_sync_esm.mjs +++ b/test/fixtures/errors/async_error_sync_esm.mjs @@ -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 { diff --git a/test/message/async_error_sync_main.out b/test/fixtures/errors/async_error_sync_esm.snapshot similarity index 77% rename from test/message/async_error_sync_main.out rename to test/fixtures/errors/async_error_sync_esm.snapshot index 565affbaf750d9..3d232a3243e0da 100644 --- a/test/message/async_error_sync_main.out +++ b/test/fixtures/errors/async_error_sync_esm.snapshot @@ -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) diff --git a/test/message/async_error_sync_main.js b/test/fixtures/errors/async_error_sync_main.js similarity index 62% rename from test/message/async_error_sync_main.js rename to test/fixtures/errors/async_error_sync_main.js index fa33c86d2cf911..4a7b402e2a815f 100644 --- a/test/message/async_error_sync_main.js +++ b/test/fixtures/errors/async_error_sync_main.js @@ -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 { diff --git a/test/message/async_error_microtask_main.out b/test/fixtures/errors/async_error_sync_main.snapshot similarity index 75% rename from test/message/async_error_microtask_main.out rename to test/fixtures/errors/async_error_sync_main.snapshot index 9512270730a976..34aaec5fed2d5f 100644 --- a/test/message/async_error_microtask_main.out +++ b/test/fixtures/errors/async_error_sync_main.snapshot @@ -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) diff --git a/test/message/error_aggregateTwoErrors.js b/test/fixtures/errors/error_aggregateTwoErrors.js similarity index 92% rename from test/message/error_aggregateTwoErrors.js rename to test/fixtures/errors/error_aggregateTwoErrors.js index 6cb6cce095b295..7a5b3b7b35538c 100644 --- a/test/message/error_aggregateTwoErrors.js +++ b/test/fixtures/errors/error_aggregateTwoErrors.js @@ -1,7 +1,7 @@ // Flags: --expose-internals 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 1; const { aggregateTwoErrors } = require('internal/errors'); diff --git a/test/message/error_aggregateTwoErrors.out b/test/fixtures/errors/error_aggregateTwoErrors.snapshot similarity index 60% rename from test/message/error_aggregateTwoErrors.out rename to test/fixtures/errors/error_aggregateTwoErrors.snapshot index a84ae7325000b9..a8d13c461b2cb0 100644 --- a/test/message/error_aggregateTwoErrors.out +++ b/test/fixtures/errors/error_aggregateTwoErrors.snapshot @@ -1,15 +1,16 @@ *error_aggregateTwoErrors.js:* throw aggregateTwoErrors(err, originalError); ^ + [AggregateError: original] { code: 'ERR0', [errors]: [ Error: original - at Object. (*test*message*error_aggregateTwoErrors.js:*:*) { + at Object. (*error_aggregateTwoErrors.js:*:*) { code: 'ERR0' }, Error: second error - at Object. (*test*message*error_aggregateTwoErrors.js:*:*) { + at Object. (*error_aggregateTwoErrors.js:*:*) { code: 'ERR1' } ] diff --git a/test/message/error_exit.js b/test/fixtures/errors/error_exit.js similarity index 98% rename from test/message/error_exit.js rename to test/fixtures/errors/error_exit.js index 51d303015fd8ac..dbe66b8ee0d568 100644 --- a/test/message/error_exit.js +++ b/test/fixtures/errors/error_exit.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 1; const assert = require('assert'); diff --git a/test/message/error_exit.out b/test/fixtures/errors/error_exit.snapshot similarity index 81% rename from test/message/error_exit.out rename to test/fixtures/errors/error_exit.snapshot index 4ee2f083b63569..778165dc25c4fc 100644 --- a/test/message/error_exit.out +++ b/test/fixtures/errors/error_exit.snapshot @@ -7,7 +7,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: 1 !== 2 - at Object. (*test*message*error_exit.js:*:*) { + at Object. (*error_exit.js:*:*) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 1, diff --git a/test/message/error_with_nul.js b/test/fixtures/errors/error_with_nul.js similarity index 88% rename from test/message/error_with_nul.js rename to test/fixtures/errors/error_with_nul.js index de49c383fd41a0..086672b9bbcb1e 100644 --- a/test/message/error_with_nul.js +++ b/test/fixtures/errors/error_with_nul.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 2; function test() { diff --git a/test/message/error_with_nul.out b/test/fixtures/errors/error_with_nul.snapshot similarity index 100% rename from test/message/error_with_nul.out rename to test/fixtures/errors/error_with_nul.snapshot diff --git a/test/message/events_unhandled_error_common_trace.js b/test/fixtures/errors/events_unhandled_error_common_trace.js similarity index 91% rename from test/message/events_unhandled_error_common_trace.js rename to test/fixtures/errors/events_unhandled_error_common_trace.js index 6ec4bed948d404..1e35a3a9832254 100644 --- a/test/message/events_unhandled_error_common_trace.js +++ b/test/fixtures/errors/events_unhandled_error_common_trace.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 2; const EventEmitter = require('events'); diff --git a/test/message/events_unhandled_error_common_trace.out b/test/fixtures/errors/events_unhandled_error_common_trace.snapshot similarity index 88% rename from test/message/events_unhandled_error_common_trace.out rename to test/fixtures/errors/events_unhandled_error_common_trace.snapshot index a3747cfdd32c31..a482c105b75e48 100644 --- a/test/message/events_unhandled_error_common_trace.out +++ b/test/fixtures/errors/events_unhandled_error_common_trace.snapshot @@ -1,5 +1,5 @@ node:events:* - throw er; // Unhandled 'error' event + throw er; * Unhandled 'error' event ^ Error: foo:bar diff --git a/test/message/events_unhandled_error_nexttick.js b/test/fixtures/errors/events_unhandled_error_nexttick.js similarity index 87% rename from test/message/events_unhandled_error_nexttick.js rename to test/fixtures/errors/events_unhandled_error_nexttick.js index bf508c9788757d..7072781586ddaf 100644 --- a/test/message/events_unhandled_error_nexttick.js +++ b/test/fixtures/errors/events_unhandled_error_nexttick.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 1; const EventEmitter = require('events'); diff --git a/test/message/events_unhandled_error_nexttick.out b/test/fixtures/errors/events_unhandled_error_nexttick.snapshot similarity index 80% rename from test/message/events_unhandled_error_nexttick.out rename to test/fixtures/errors/events_unhandled_error_nexttick.snapshot index 7b616c22e37302..450d4910a385b5 100644 --- a/test/message/events_unhandled_error_nexttick.out +++ b/test/fixtures/errors/events_unhandled_error_nexttick.snapshot @@ -1,5 +1,5 @@ node:events:* - throw er; // Unhandled 'error' event + throw er; * Unhandled 'error' event ^ Error diff --git a/test/message/events_unhandled_error_sameline.js b/test/fixtures/errors/events_unhandled_error_sameline.js similarity index 83% rename from test/message/events_unhandled_error_sameline.js rename to test/fixtures/errors/events_unhandled_error_sameline.js index 6dad22dd58e393..d9a01050feab12 100644 --- a/test/message/events_unhandled_error_sameline.js +++ b/test/fixtures/errors/events_unhandled_error_sameline.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 1; const EventEmitter = require('events'); diff --git a/test/message/events_unhandled_error_sameline.out b/test/fixtures/errors/events_unhandled_error_sameline.snapshot similarity index 82% rename from test/message/events_unhandled_error_sameline.out rename to test/fixtures/errors/events_unhandled_error_sameline.snapshot index dd12176259badf..520601e617083c 100644 --- a/test/message/events_unhandled_error_sameline.out +++ b/test/fixtures/errors/events_unhandled_error_sameline.snapshot @@ -1,5 +1,5 @@ node:events:* - throw er; // Unhandled 'error' event + throw er; * Unhandled 'error' event ^ Error diff --git a/test/message/events_unhandled_error_subclass.js b/test/fixtures/errors/events_unhandled_error_subclass.js similarity index 86% rename from test/message/events_unhandled_error_subclass.js rename to test/fixtures/errors/events_unhandled_error_subclass.js index 5fc3bc26fb4e93..2131771944faf5 100644 --- a/test/message/events_unhandled_error_subclass.js +++ b/test/fixtures/errors/events_unhandled_error_subclass.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 1; const EventEmitter = require('events'); diff --git a/test/message/events_unhandled_error_subclass.out b/test/fixtures/errors/events_unhandled_error_subclass.snapshot similarity index 83% rename from test/message/events_unhandled_error_subclass.out rename to test/fixtures/errors/events_unhandled_error_subclass.snapshot index 3d5d0307e6d792..6a9cfd4a1a0b21 100644 --- a/test/message/events_unhandled_error_subclass.out +++ b/test/fixtures/errors/events_unhandled_error_subclass.snapshot @@ -1,5 +1,5 @@ node:events:* - throw er; // Unhandled 'error' event + throw er; * Unhandled 'error' event ^ Error diff --git a/test/message/promise_always_throw_unhandled.js b/test/fixtures/errors/promise_always_throw_unhandled.js similarity index 94% rename from test/message/promise_always_throw_unhandled.js rename to test/fixtures/errors/promise_always_throw_unhandled.js index d9128f34a5c9f1..25d1642a65de41 100644 --- a/test/message/promise_always_throw_unhandled.js +++ b/test/fixtures/errors/promise_always_throw_unhandled.js @@ -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'`. diff --git a/test/message/promise_always_throw_unhandled.out b/test/fixtures/errors/promise_always_throw_unhandled.snapshot similarity index 61% rename from test/message/promise_always_throw_unhandled.out rename to test/fixtures/errors/promise_always_throw_unhandled.snapshot index bc2949391c16d7..c97540f5499f87 100644 --- a/test/message/promise_always_throw_unhandled.out +++ b/test/fixtures/errors/promise_always_throw_unhandled.snapshot @@ -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 () - at Object. (*promise_always_throw_unhandled.js:*:*) + at * at * at * at * diff --git a/test/message/throw_custom_error.js b/test/fixtures/errors/throw_custom_error.js similarity index 98% rename from test/message/throw_custom_error.js rename to test/fixtures/errors/throw_custom_error.js index 3e0e6a271c7415..1cf6108af716a1 100644 --- a/test/message/throw_custom_error.js +++ b/test/fixtures/errors/throw_custom_error.js @@ -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 diff --git a/test/message/throw_custom_error.out b/test/fixtures/errors/throw_custom_error.snapshot similarity index 79% rename from test/message/throw_custom_error.out rename to test/fixtures/errors/throw_custom_error.snapshot index 920cbf62310f39..ba80020c897a32 100644 --- a/test/message/throw_custom_error.out +++ b/test/fixtures/errors/throw_custom_error.snapshot @@ -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' } diff --git a/test/message/throw_in_line_with_tabs.js b/test/fixtures/errors/throw_in_line_with_tabs.js similarity index 98% rename from test/message/throw_in_line_with_tabs.js rename to test/fixtures/errors/throw_in_line_with_tabs.js index ab059916b2c8da..b62d422597904a 100644 --- a/test/message/throw_in_line_with_tabs.js +++ b/test/fixtures/errors/throw_in_line_with_tabs.js @@ -21,7 +21,7 @@ /* eslint-disable indent, no-tabs */ 'use strict'; -require('../common'); +require('../../common'); console.error('before'); diff --git a/test/message/throw_in_line_with_tabs.out b/test/fixtures/errors/throw_in_line_with_tabs.snapshot similarity index 58% rename from test/message/throw_in_line_with_tabs.out rename to test/fixtures/errors/throw_in_line_with_tabs.snapshot index 0d71e91b75c2e7..29c7e1ec3587d9 100644 --- a/test/message/throw_in_line_with_tabs.out +++ b/test/fixtures/errors/throw_in_line_with_tabs.snapshot @@ -1,5 +1,6 @@ before -*test*message*throw_in_line_with_tabs.js:* + +*throw_in_line_with_tabs.js:* throw ({ foo: 'bar' }); ^ { foo: 'bar' } diff --git a/test/message/throw_non_error.js b/test/fixtures/errors/throw_non_error.js similarity index 98% rename from test/message/throw_non_error.js rename to test/fixtures/errors/throw_non_error.js index fc1a568015aaf2..e1b239aa261d28 100644 --- a/test/message/throw_non_error.js +++ b/test/fixtures/errors/throw_non_error.js @@ -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 diff --git a/test/message/throw_non_error.out b/test/fixtures/errors/throw_non_error.snapshot similarity index 59% rename from test/message/throw_non_error.out rename to test/fixtures/errors/throw_non_error.snapshot index 665c9b4fd1d0c3..4ad80df4f6a9cb 100644 --- a/test/message/throw_non_error.out +++ b/test/fixtures/errors/throw_non_error.snapshot @@ -1,4 +1,5 @@ -*test*message*throw_non_error.js:* + +*throw_non_error.js:* throw ({ foo: 'bar' }); ^ { foo: 'bar' } diff --git a/test/message/source_map_disabled_by_api.js b/test/fixtures/source-map/output/source_map_disabled_by_api.js similarity index 55% rename from test/message/source_map_disabled_by_api.js rename to test/fixtures/source-map/output/source_map_disabled_by_api.js index 93c87f10c14931..b1a28d0eae1c2e 100644 --- a/test/message/source_map_disabled_by_api.js +++ b/test/fixtures/source-map/output/source_map_disabled_by_api.js @@ -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); } diff --git a/test/message/source_map_disabled_by_api.out b/test/fixtures/source-map/output/source_map_disabled_by_api.snapshot similarity index 100% rename from test/message/source_map_disabled_by_api.out rename to test/fixtures/source-map/output/source_map_disabled_by_api.snapshot diff --git a/test/message/source_map_enabled_by_api.js b/test/fixtures/source-map/output/source_map_enabled_by_api.js similarity index 51% rename from test/message/source_map_enabled_by_api.js rename to test/fixtures/source-map/output/source_map_enabled_by_api.js index f0308b19598988..4c70fa1cb2a240 100644 --- a/test/message/source_map_enabled_by_api.js +++ b/test/fixtures/source-map/output/source_map_enabled_by_api.js @@ -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); } diff --git a/test/message/source_map_enabled_by_api.out b/test/fixtures/source-map/output/source_map_enabled_by_api.snapshot similarity index 100% rename from test/message/source_map_enabled_by_api.out rename to test/fixtures/source-map/output/source_map_enabled_by_api.snapshot diff --git a/test/message/source_map_eval.js b/test/fixtures/source-map/output/source_map_eval.js similarity index 50% rename from test/message/source_map_eval.js rename to test/fixtures/source-map/output/source_map_eval.js index 404793f05412e4..5492c179248180 100644 --- a/test/message/source_map_eval.js +++ b/test/fixtures/source-map/output/source_map_eval.js @@ -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); diff --git a/test/message/source_map_eval.out b/test/fixtures/source-map/output/source_map_eval.snapshot similarity index 72% rename from test/message/source_map_eval.out rename to test/fixtures/source-map/output/source_map_eval.snapshot index 5d97e137f7f824..a4fcdb25282dfa 100644 --- a/test/message/source_map_eval.out +++ b/test/fixtures/source-map/output/source_map_eval.snapshot @@ -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. (*source_map_eval.js:*:*) + at Object. (*output*source_map_eval.js:10:1) Node.js * diff --git a/test/message/source_map_no_source_file.js b/test/fixtures/source-map/output/source_map_no_source_file.js similarity index 51% rename from test/message/source_map_no_source_file.js rename to test/fixtures/source-map/output/source_map_no_source_file.js index 53c53416248b77..eb7a107fa2f8ce 100644 --- a/test/message/source_map_no_source_file.js +++ b/test/fixtures/source-map/output/source_map_no_source_file.js @@ -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'); diff --git a/test/message/source_map_no_source_file.out b/test/fixtures/source-map/output/source_map_no_source_file.snapshot similarity index 100% rename from test/message/source_map_no_source_file.out rename to test/fixtures/source-map/output/source_map_no_source_file.snapshot diff --git a/test/message/source_map_throw_first_tick.js b/test/fixtures/source-map/output/source_map_throw_first_tick.js similarity index 50% rename from test/message/source_map_throw_first_tick.js rename to test/fixtures/source-map/output/source_map_throw_first_tick.js index 9bf1a353cf18be..62c2b41c693e9d 100644 --- a/test/message/source_map_throw_first_tick.js +++ b/test/fixtures/source-map/output/source_map_throw_first_tick.js @@ -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'); diff --git a/test/message/source_map_throw_first_tick.out b/test/fixtures/source-map/output/source_map_throw_first_tick.snapshot similarity index 51% rename from test/message/source_map_throw_first_tick.out rename to test/fixtures/source-map/output/source_map_throw_first_tick.snapshot index 792be67aae089f..fba8c95cc1103f 100644 --- a/test/message/source_map_throw_first_tick.out +++ b/test/fixtures/source-map/output/source_map_throw_first_tick.snapshot @@ -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. (*typescript-throw.ts:24:1) Node.js * diff --git a/test/message/vm_caught_custom_runtime_error.js b/test/fixtures/vm/vm_caught_custom_runtime_error.js similarity index 94% rename from test/message/vm_caught_custom_runtime_error.js rename to test/fixtures/vm/vm_caught_custom_runtime_error.js index 237e8e3a105436..81349fc9bf0ec5 100644 --- a/test/message/vm_caught_custom_runtime_error.js +++ b/test/fixtures/vm/vm_caught_custom_runtime_error.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +require('../../common'); const vm = require('vm'); console.error('beginning'); diff --git a/test/message/vm_caught_custom_runtime_error.out b/test/fixtures/vm/vm_caught_custom_runtime_error.snapshot similarity index 100% rename from test/message/vm_caught_custom_runtime_error.out rename to test/fixtures/vm/vm_caught_custom_runtime_error.snapshot diff --git a/test/message/vm_display_runtime_error.js b/test/fixtures/vm/vm_display_runtime_error.js similarity index 98% rename from test/message/vm_display_runtime_error.js rename to test/fixtures/vm/vm_display_runtime_error.js index 80505cb02f3f3b..390727d1f00988 100644 --- a/test/message/vm_display_runtime_error.js +++ b/test/fixtures/vm/vm_display_runtime_error.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 4; const vm = require('vm'); diff --git a/test/message/vm_display_runtime_error.out b/test/fixtures/vm/vm_display_runtime_error.snapshot similarity index 69% rename from test/message/vm_display_runtime_error.out rename to test/fixtures/vm/vm_display_runtime_error.snapshot index 6dc8a703b4b7cd..47c7d54bae4481 100644 --- a/test/message/vm_display_runtime_error.out +++ b/test/fixtures/vm/vm_display_runtime_error.snapshot @@ -7,7 +7,7 @@ Error: boo! at test.vm:1:7 at Script.runInThisContext (node:vm:*) at Object.runInThisContext (node:vm:*) - at Object. (*test*message*vm_display_runtime_error.js:*) + at Object. (*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. (*test*message*vm_display_runtime_error.js:*) + at Object. (*fixtures*vm*vm_display_runtime_error.js:36:4) Node.js * diff --git a/test/message/vm_display_syntax_error.js b/test/fixtures/vm/vm_display_syntax_error.js similarity index 98% rename from test/message/vm_display_syntax_error.js rename to test/fixtures/vm/vm_display_syntax_error.js index f47d8d477ececc..9d802eac624f76 100644 --- a/test/message/vm_display_syntax_error.js +++ b/test/fixtures/vm/vm_display_syntax_error.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 4; const vm = require('vm'); diff --git a/test/message/vm_display_syntax_error.out b/test/fixtures/vm/vm_display_syntax_error.snapshot similarity index 69% rename from test/message/vm_display_syntax_error.out rename to test/fixtures/vm/vm_display_syntax_error.snapshot index 371ebfccdc3e1d..84f52ce4dba0bc 100644 --- a/test/message/vm_display_syntax_error.out +++ b/test/fixtures/vm/vm_display_syntax_error.snapshot @@ -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. (*test*message*vm_display_syntax_error.js:*) + at Object. (*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. (*test*message*vm_display_syntax_error.js:*) + at Object. (*fixtures*vm*vm_display_syntax_error.js:36:4) Node.js * diff --git a/test/message/vm_dont_display_runtime_error.js b/test/fixtures/vm/vm_dont_display_runtime_error.js similarity index 98% rename from test/message/vm_dont_display_runtime_error.js rename to test/fixtures/vm/vm_dont_display_runtime_error.js index 2dff567fb9e4c6..128a312cc8979f 100644 --- a/test/message/vm_dont_display_runtime_error.js +++ b/test/fixtures/vm/vm_dont_display_runtime_error.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 4; const vm = require('vm'); diff --git a/test/message/vm_dont_display_runtime_error.out b/test/fixtures/vm/vm_dont_display_runtime_error.snapshot similarity index 69% rename from test/message/vm_dont_display_runtime_error.out rename to test/fixtures/vm/vm_dont_display_runtime_error.snapshot index 78b6a67c5aff2f..045183d4a37bde 100644 --- a/test/message/vm_dont_display_runtime_error.out +++ b/test/fixtures/vm/vm_dont_display_runtime_error.snapshot @@ -8,6 +8,6 @@ Error: boo! at test.vm:1:7 at Script.runInThisContext (node:vm:*) at Object.runInThisContext (node:vm:*) - at Object. (*test*message*vm_dont_display_runtime_error.js:*) + at Object. (*fixtures*vm*vm_dont_display_runtime_error.js:41:4) Node.js * diff --git a/test/message/vm_dont_display_syntax_error.js b/test/fixtures/vm/vm_dont_display_syntax_error.js similarity index 98% rename from test/message/vm_dont_display_syntax_error.js rename to test/fixtures/vm/vm_dont_display_syntax_error.js index 821933a6113bb9..6ce013b42364a8 100644 --- a/test/message/vm_dont_display_syntax_error.js +++ b/test/fixtures/vm/vm_dont_display_syntax_error.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +require('../../common'); Error.stackTraceLimit = 4; const vm = require('vm'); diff --git a/test/message/vm_dont_display_syntax_error.out b/test/fixtures/vm/vm_dont_display_syntax_error.snapshot similarity index 70% rename from test/message/vm_dont_display_syntax_error.out rename to test/fixtures/vm/vm_dont_display_syntax_error.snapshot index d7849361d5d230..27c4faf563617c 100644 --- a/test/message/vm_dont_display_syntax_error.out +++ b/test/fixtures/vm/vm_dont_display_syntax_error.snapshot @@ -8,6 +8,6 @@ SyntaxError: Unexpected number at new Script (node:vm:*) at createScript (node:vm:*) at Object.runInThisContext (node:vm:*) - at Object. (*test*message*vm_dont_display_syntax_error.js:*) + at Object. (*fixtures*vm*vm_dont_display_syntax_error.js:41:4) Node.js * diff --git a/test/parallel/test-node-output-console.mjs b/test/parallel/test-node-output-console.mjs new file mode 100644 index 00000000000000..6656028bae4795 --- /dev/null +++ b/test/parallel/test-node-output-console.mjs @@ -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); + }); + } +}); diff --git a/test/parallel/test-node-output-errors.mjs b/test/parallel/test-node-output-errors.mjs new file mode 100644 index 00000000000000..5668fca4dc89b8 --- /dev/null +++ b/test/parallel/test-node-output-errors.mjs @@ -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); + }); + } +}); diff --git a/test/parallel/test-node-output-sourcemaps.mjs b/test/parallel/test-node-output-sourcemaps.mjs new file mode 100644 index 00000000000000..a226cd9800d14e --- /dev/null +++ b/test/parallel/test-node-output-sourcemaps.mjs @@ -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); + }); + } +}); diff --git a/test/parallel/test-node-output-vm.mjs b/test/parallel/test-node-output-vm.mjs new file mode 100644 index 00000000000000..52dc9a0d57607c --- /dev/null +++ b/test/parallel/test-node-output-vm.mjs @@ -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); + }); + } +});