Skip to content

Commit

Permalink
test: fix regex to account to path containing white spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jul 29, 2023
1 parent 8526791 commit 6e05e8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const test = require('node:test');
const fs = require('node:fs/promises');
const assert = require('node:assert/strict');

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

function replaceStackTrace(str, replacement = '$1*$7$8\n') {
Expand Down
18 changes: 12 additions & 6 deletions test/parallel/test-node-output-errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ function replaceStackTrace(str) {

describe('errors output', { concurrency: true }, () => {
function normalize(str) {
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:*/');
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 @@ -51,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 6e05e8d

Please sign in to comment.