GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: do not assume cwd in snapshot tests · nodejs/node@662bf52

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test
    • common
      • assertSnapshot.js
    • parallel
      • test-runner-output.mjs
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.