Skip to content

Commit 662bf52

Browse 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

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎test/common/assertSnapshot.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function replaceWindowsPaths(str) {
2525
}
2626

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

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

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

Lines 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*assnapshotfrom'../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
constskipForceColors=
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+
constroot=fileURLToPath(newURL('../..',import.meta.url)).slice(0,-1);
20+
1721
constcolor='(\\[\\d+m)';
18-
conststackTraceBasePath=newRegExp(`${color}\\(${process.cwd().replaceAll(/[\\^$*+?.()|[\]{}]/g,'\\$&')}/?${color}(.*)${color}\\)`,'g');
22+
conststackTraceBasePath=newRegExp(`${color}\\(${root.replaceAll(/[\\^$*+?.()|[\]{}]/g,'\\$&')}/?${color}(.*)${color}\\)`,'g');
1923

2024
functionreplaceSpecDuration(str){
2125
returnstr
@@ -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 }oftests){
154161
it(name,fn);

0 commit comments

Comments
 (0)