Skip to content

Commit 3af7cfe

Browse files
authored
test: refactor test-node-output-errors
The main reason is to not have the test fail if the CWD contains some special URL chars. PR-URL: #48992 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent a061781 commit 3af7cfe

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

test/parallel/test-node-output-errors.mjs

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fixtures from '../common/fixtures.mjs';
33
import * as snapshot from '../common/assertSnapshot.js';
44
import * as os from 'node:os';
55
import { describe, it } from 'node:test';
6+
import { pathToFileURL } from 'node:url';
67

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

2122
describe('errors output', { concurrency: true }, () => {
2223
function normalize(str) {
23-
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '').replaceAll('//', '*').replaceAll(/\/(\w)/g, '*$1').replaceAll('*test*', '*').replaceAll('*fixtures*errors*', '*').replaceAll('file:**', 'file:*/');
24+
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
25+
.replaceAll(pathToFileURL(process.cwd()).pathname, '')
26+
.replaceAll('//', '*')
27+
.replaceAll(/\/(\w)/g, '*$1')
28+
.replaceAll('*test*', '*')
29+
.replaceAll('*fixtures*errors*', '*')
30+
.replaceAll('file:**', 'file:*/');
2431
}
2532

2633
function normalizeNoNumbers(str) {
@@ -50,11 +57,11 @@ describe('errors output', { concurrency: true }, () => {
5057
{ name: 'errors/throw_in_line_with_tabs.js', transform: errTransform },
5158
{ name: 'errors/throw_non_error.js', transform: errTransform },
5259
{ name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform },
53-
!skipForceColors ? { name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } } : null,
54-
].filter(Boolean);
55-
for (const { name, transform, env } of tests) {
56-
it(name, async () => {
57-
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { env });
60+
{ skip: skipForceColors, name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } },
61+
];
62+
for (const { name, transform = defaultTransform, env, skip = false } of tests) {
63+
it(name, { skip }, async () => {
64+
await snapshot.spawnAndAssert(fixtures.path(name), transform, { env });
5865
});
5966
}
6067
});

0 commit comments

Comments
 (0)