Skip to content

Commit

Permalink
test: refactor test-node-output-errors
Browse files Browse the repository at this point in the history
The main reason is to not have the test fail if the CWD contains some
special URL chars.

PR-URL: nodejs/node#48992
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent 69a0225 commit 695b9e6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions graal-nodejs/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 { pathToFileURL } from 'node:url';

const skipForceColors =
process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' ||
Expand All @@ -20,7 +21,13 @@ function replaceStackTrace(str) {

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:*/');
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:*/');
}

function normalizeNoNumbers(str) {
Expand Down Expand Up @@ -50,11 +57,11 @@ describe('errors output', { concurrency: true }, () => {
{ 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 },
!skipForceColors ? { name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } } : null,
].filter(Boolean);
for (const { name, transform, env } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { env });
{ skip: skipForceColors, name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } },
];
for (const { name, transform = defaultTransform, env, skip = false } of tests) {
it(name, { skip }, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform, { env });
});
}
});

0 comments on commit 695b9e6

Please sign in to comment.