Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make snapshot comparison more flexible #54375

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
at *
at *
at *
(Use `node --trace-warnings ...` to show where the warning was created)
(Use `* --trace-warnings ...` to show where the warning was created)
(node:*) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https:*nodejs.org*api*cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
throw { * eslint-disable-line no-throw-literal
^
[object Object]
(Use `node --trace-uncaught ...` to show where the exception was thrown)
(Use `* --trace-uncaught ...` to show where the exception was thrown)

Node.js *
2 changes: 1 addition & 1 deletion test/fixtures/errors/throw_null.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
throw null;
^
null
(Use `node --trace-uncaught ...` to show where the exception was thrown)
(Use `* --trace-uncaught ...` to show where the exception was thrown)

Node.js *
2 changes: 1 addition & 1 deletion test/fixtures/errors/throw_undefined.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
throw undefined;
^
undefined
(Use `node --trace-uncaught ...` to show where the exception was thrown)
(Use `* --trace-uncaught ...` to show where the exception was thrown)

Node.js *
5 changes: 4 additions & 1 deletion test/parallel/test-node-output-errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import * as os from 'node:os';
import { describe, it } from 'node:test';
import { basename } from 'node:path';
import { pathToFileURL } from 'node:url';

const skipForceColors =
Expand All @@ -20,13 +21,15 @@ function replaceForceColorsStackTrace(str) {

describe('errors output', { concurrency: !process.env.TEST_PARALLEL }, () => {
function normalize(str) {
const baseName = basename(process.argv0 || 'node', '.exe');
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
.replaceAll(pathToFileURL(process.cwd()).pathname, '')
.replaceAll('//', '*')
.replaceAll(/\/(\w)/g, '*$1')
.replaceAll('*test*', '*')
.replaceAll('*fixtures*errors*', '*')
.replaceAll('file:**', 'file:*/');
.replaceAll('file:**', 'file:*/')
.replaceAll(`${baseName} --`, '* --');
}

function normalizeNoNumbers(str) {
Expand Down
Loading