GeezerVison is showing github.com — test: do not assume cwd in snapshot tests · nodejs/node@662bf52
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/common/assertSnapshot.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,7 +25,7 @@ function replaceWindowsPaths(str) { | 25 | 25 | } | 26 | 26 |
| 27 | 27 | function replaceFullPaths(str) { | 28 | | - return str.replaceAll(process.cwd(), ''); | | 28 | + return str.replaceAll(path.resolve(__dirname, '../..'), ''); | 29 | 29 | } | 30 | 30 |
| 31 | 31 | function transform(...args) { | @@ -78,7 +78,7 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ... | 78 | 78 | return; | 79 | 79 | } | 80 | 80 | 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; | 82 | 82 | const args = tty ? [process.execPath, ...flags, filename] : [...flags, filename]; | 83 | 83 | const { stdout, stderr } = await common.spawnPromisified(executable, args, options); | 84 | 84 | await assertSnapshot(transform(`${stdout}${stderr}`), filename); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-output.mjs +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,8 @@ import * as fixtures from '../common/fixtures.mjs'; | 3 | 3 | import * as snapshot from '../common/assertSnapshot.js'; | 4 | 4 | import { describe, it } from 'node:test'; | 5 | 5 | import { hostname } from 'node:os'; | | 6 | +import { chdir, cwd } from 'node:process'; | | 7 | +import { fileURLToPath } from 'node:url'; | 6 | 8 |
| 7 | 9 | const skipForceColors = | 8 | 10 | process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' || | @@ -14,8 +16,10 @@ function replaceTestDuration(str) { | 14 | 16 | .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *'); | 15 | 17 | } | 16 | 18 |
| | 19 | +const root = fileURLToPath(new URL('../..', import.meta.url)).slice(0, -1); | | 20 | + | 17 | 21 | 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'); | 19 | 23 |
| 20 | 24 | function replaceSpecDuration(str) { | 21 | 25 | return str | @@ -149,6 +153,9 @@ const tests = [ | 149 | 153 | }), | 150 | 154 | })); | 151 | 155 |
| | 156 | +if (cwd() !== root) { | | 157 | + chdir(root); | | 158 | +} | 152 | 159 | describe('test runner output', { concurrency: true }, () => { | 153 | 160 | for (const { name, fn } of tests) { | 154 | 161 | it(name, fn); | |
|