diff --git a/test/message/assert_throws_stack.js b/test/fixtures/assert/assert_throws_stack.js similarity index 82% rename from test/message/assert_throws_stack.js rename to test/fixtures/assert/assert_throws_stack.js index 36bc5734cae37f..a1fca696c5ac10 100644 --- a/test/message/assert_throws_stack.js +++ b/test/fixtures/assert/assert_throws_stack.js @@ -1,6 +1,6 @@ 'use strict'; -require('../common'); +require('../../common'); const assert = require('assert').strict; assert.throws(() => { throw new Error('foo'); }, { bar: true }); diff --git a/test/message/assert_throws_stack.out b/test/fixtures/assert/assert_throws_stack.snapshot similarity index 60% rename from test/message/assert_throws_stack.out rename to test/fixtures/assert/assert_throws_stack.snapshot index 06eaa906442440..ebd3517dd74a48 100644 --- a/test/message/assert_throws_stack.out +++ b/test/fixtures/assert/assert_throws_stack.snapshot @@ -1,4 +1,4 @@ -node:assert:* +node:assert* throw err; ^ @@ -9,7 +9,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: - Comparison { - bar: true - } - at Object. (*assert_throws_stack.js:*:*) + at * at * at * at * @@ -19,16 +19,16 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: generatedMessage: true, code: 'ERR_ASSERTION', actual: Error: foo - at assert.throws.bar (*assert_throws_stack.js:*) - at getActual (node:assert:*) - at Function.throws (node:assert:*) - at Object. (*assert_throws_stack.js:*:*) at * at * at * at * at * - at *, + at * + at * + at * + at * + at node:internal*main*run_main_module**, expected: { bar: true }, operator: 'throws' } diff --git a/test/message/internal_assert.js b/test/fixtures/assert/internal_assert.js similarity index 80% rename from test/message/internal_assert.js rename to test/fixtures/assert/internal_assert.js index fdb459b67ca0fa..871504f0925a6f 100644 --- a/test/message/internal_assert.js +++ b/test/fixtures/assert/internal_assert.js @@ -1,7 +1,7 @@ 'use strict'; // Flags: --expose-internals -require('../common'); +require('../../common'); const assert = require('internal/assert'); assert(false); diff --git a/test/message/internal_assert.out b/test/fixtures/assert/internal_assert.snapshot similarity index 52% rename from test/message/internal_assert.out rename to test/fixtures/assert/internal_assert.snapshot index bd25c879478083..3b60a41ffc4f0c 100644 --- a/test/message/internal_assert.out +++ b/test/fixtures/assert/internal_assert.snapshot @@ -1,13 +1,13 @@ -node:internal/assert:* +node:internal*assert* throw new ERR_INTERNAL_ASSERTION(message); ^ Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals. -Please open an issue with this stack trace at https://github.com/nodejs/node/issues +Please open an issue with this stack trace at https:**github.com*nodejs*node*issues - at new NodeError (node:internal/errors:*:*) - at assert (node:internal/assert:*:*) - at * (*test*message*internal_assert.js:7:1) + at * + at * + at * at * at * at * diff --git a/test/message/internal_assert_fail.js b/test/fixtures/assert/internal_assert_fail.js similarity index 82% rename from test/message/internal_assert_fail.js rename to test/fixtures/assert/internal_assert_fail.js index 1b2cf13552869b..503a1dcbc7264a 100644 --- a/test/message/internal_assert_fail.js +++ b/test/fixtures/assert/internal_assert_fail.js @@ -1,7 +1,7 @@ 'use strict'; // Flags: --expose-internals -require('../common'); +require('../../common'); const assert = require('internal/assert'); assert.fail('Unreachable!'); diff --git a/test/message/internal_assert_fail.out b/test/fixtures/assert/internal_assert_fail.snapshot similarity index 52% rename from test/message/internal_assert_fail.out rename to test/fixtures/assert/internal_assert_fail.snapshot index 408d6d3364470d..6821e0007dac80 100644 --- a/test/message/internal_assert_fail.out +++ b/test/fixtures/assert/internal_assert_fail.snapshot @@ -1,14 +1,14 @@ -node:internal/assert:* +node:internal*assert* throw new ERR_INTERNAL_ASSERTION(message); ^ Error [ERR_INTERNAL_ASSERTION]: Unreachable! This is caused by either a bug in Node.js or incorrect usage of Node.js internals. -Please open an issue with this stack trace at https://github.com/nodejs/node/issues +Please open an issue with this stack trace at https:**github.com*nodejs*node*issues - at new NodeError (node:internal/errors:*:*) - at Function.fail (node:internal/assert:*:*) - at * (*test*message*internal_assert_fail.js:7:8) + at * + at * + at * at * at * at * diff --git a/test/parallel/test-output-assert.mjs b/test/parallel/test-output-assert.mjs new file mode 100644 index 00000000000000..07454d5f1eb2b6 --- /dev/null +++ b/test/parallel/test-output-assert.mjs @@ -0,0 +1,33 @@ +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 replaceStackTrace(str) { + return snapshot.replaceStackTrace(str, '$1at *$7\n'); +} +function normalize(str) { + return str + .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '') + .replaceAll('/', '*') + .replaceAll(process.version, '*') + .replaceAll(/:\d+/g, '*'); +} +const common = snapshot + .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths); + +const defaultTransform = snapshot.transform(common, replaceStackTrace, normalize); + +const tests = [ + { name: 'assert/assert_throws_stack.js' }, + { name: 'assert/internal_assert_fail.js' }, + { name: 'assert/internal_assert.js' }, +]; + +describe('assertion output', { concurrency: true }, () => { + for (const { name, transform } of tests) { + it(name, async () => { + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); + }); + } +});