Skip to content

Commit 6e05e8d

Browse files
committed
test: fix regex to account to path containing white spaces
1 parent 8526791 commit 6e05e8d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

test/common/assertSnapshot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const test = require('node:test');
55
const fs = require('node:fs/promises');
66
const assert = require('node:assert/strict');
77

8-
const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g;
8+
const stackFramesRegexp = /(?<=\n)(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g;
99
const windowNewlineRegexp = /\r/g;
1010

1111
function replaceStackTrace(str, replacement = '$1*$7$8\n') {

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ function replaceStackTrace(str) {
2121

2222
describe('errors output', { concurrency: true }, () => {
2323
function normalize(str) {
24-
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:*/');
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:*/');
2531
}
2632

2733
function normalizeNoNumbers(str) {
@@ -51,11 +57,11 @@ describe('errors output', { concurrency: true }, () => {
5157
{ name: 'errors/throw_in_line_with_tabs.js', transform: errTransform },
5258
{ name: 'errors/throw_non_error.js', transform: errTransform },
5359
{ name: 'errors/promise_always_throw_unhandled.js', transform: promiseTransform },
54-
!skipForceColors ? { name: 'errors/force_colors.js', env: { FORCE_COLOR: 1 } } : null,
55-
].filter(Boolean);
56-
for (const { name, transform, env } of tests) {
57-
it(name, async () => {
58-
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 });
5965
});
6066
}
6167
});

0 commit comments

Comments
 (0)