Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 662bf52

Browse filesBrowse files
aduh95marco-ippolito
authored andcommitted
test: do not assume cwd in snapshot tests
PR-URL: #53146 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0312065 commit 662bf52
Copy full SHA for 662bf52

2 files changed

+10-3Lines changed: 10 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/common/assertSnapshot.js‎

Copy file name to clipboardExpand all lines: test/common/assertSnapshot.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function replaceWindowsPaths(str) {
2525
}
2626

2727
function replaceFullPaths(str) {
28-
return str.replaceAll(process.cwd(), '');
28+
return str.replaceAll(path.resolve(__dirname, '../..'), '');
2929
}
3030

3131
function transform(...args) {
@@ -78,7 +78,7 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ...
7878
return;
7979
}
8080
const flags = common.parseTestFlags(filename);
81-
const executable = tty ? 'tools/pseudo-tty.py' : process.execPath;
81+
const executable = tty ? path.join(__dirname, '../..', 'tools/pseudo-tty.py') : process.execPath;
8282
const args = tty ? [process.execPath, ...flags, filename] : [...flags, filename];
8383
const { stdout, stderr } = await common.spawnPromisified(executable, args, options);
8484
await assertSnapshot(transform(`${stdout}${stderr}`), filename);
Collapse file

‎test/parallel/test-runner-output.mjs‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-output.mjs
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as fixtures from '../common/fixtures.mjs';
33
import * as snapshot from '../common/assertSnapshot.js';
44
import { describe, it } from 'node:test';
55
import { hostname } from 'node:os';
6+
import { chdir, cwd } from 'node:process';
7+
import { fileURLToPath } from 'node:url';
68

79
const skipForceColors =
810
process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' ||
@@ -14,8 +16,10 @@ function replaceTestDuration(str) {
1416
.replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *');
1517
}
1618

19+
const root = fileURLToPath(new URL('../..', import.meta.url)).slice(0, -1);
20+
1721
const color = '(\\[\\d+m)';
18-
const stackTraceBasePath = new RegExp(`${color}\\(${process.cwd().replaceAll(/[\\^$*+?.()|[\]{}]/g, '\\$&')}/?${color}(.*)${color}\\)`, 'g');
22+
const stackTraceBasePath = new RegExp(`${color}\\(${root.replaceAll(/[\\^$*+?.()|[\]{}]/g, '\\$&')}/?${color}(.*)${color}\\)`, 'g');
1923

2024
function replaceSpecDuration(str) {
2125
return str
@@ -149,6 +153,9 @@ const tests = [
149153
}),
150154
}));
151155

156+
if (cwd() !== root) {
157+
chdir(root);
158+
}
152159
describe('test runner output', { concurrency: true }, () => {
153160
for (const { name, fn } of tests) {
154161
it(name, fn);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.