Skip to content

Commit 5a976cb

Browse files
joyeecheungRafaelGSS
authored andcommitted
test: split test-runner-run-watch.mjs
This test contains too many independent test cases and as a result, marking it as flaky on all major platforms means actual regressions could be covered up, and it's constantly making the CI orange and requires extra resuming on the flaked platforms which is still not great. Split it into individual files so that the actual flake can be identified out of the monolith. PR-URL: #60653 Refs: #54534 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8f611b9 commit 5a976cb

20 files changed

Lines changed: 400 additions & 436 deletions

‎test/common/watch.js‎

Lines changed: 102 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,58 @@ function refreshForTestRunnerWatch() {
4747
}
4848
}
4949

50+
asyncfunctionperformFileOperation(operation,useRunApi,timeout=1000){
51+
if(useRunApi){
52+
constinterval=setInterval(()=>{
53+
operation();
54+
clearInterval(interval);
55+
},common.platformTimeout(timeout));
56+
}else{
57+
operation();
58+
awaitsetTimeout(common.platformTimeout(timeout));
59+
}
60+
}
61+
62+
functionassertTestOutput(run,shouldCheckRecursion=false){
63+
if(shouldCheckRecursion){
64+
assert.doesNotMatch(run,/run\(\)isbeingcalledrecursively/);
65+
}
66+
assert.match(run,/tests1/);
67+
assert.match(run,/pass1/);
68+
assert.match(run,/fail0/);
69+
assert.match(run,/cancelled0/);
70+
}
71+
5072
asyncfunctiontestRunnerWatch({
5173
fileToUpdate,
5274
file,
5375
action ='update',
5476
fileToCreate,
5577
isolation,
78+
useRunApi =false,
79+
cwd =tmpdir.path,
80+
runnerCwd,
5681
}){
5782
constran1=Promise.withResolvers();
5883
constran2=Promise.withResolvers();
59-
constchild=spawn(process.execPath,
60-
['--watch','--test','--test-reporter=spec',
61-
isolation ? `--test-isolation=${isolation}` : '',
62-
file ? fixturePaths[file] : undefined].filter(Boolean),
63-
{encoding: 'utf8',stdio: 'pipe',cwd: tmpdir.path});
84+
85+
letargs;
86+
if(useRunApi){
87+
// Use the fixture that calls run() API
88+
construnner=fixtures.path('test-runner-watch.mjs');
89+
args=[runner];
90+
if(file)args.push('--file',file);
91+
if(runnerCwd)args.push('--cwd',runnerCwd);
92+
if(isolation)args.push('--isolation',isolation);
93+
}else{
94+
// Use CLI --watch --test flags
95+
args=['--watch','--test','--test-reporter=spec',
96+
isolation ? `--test-isolation=${isolation}` : '',
97+
file ? fixturePaths[file] : undefined].filter(Boolean);
98+
}
99+
100+
constchild=spawn(process.execPath,args,
101+
{encoding: 'utf8',stdio: 'pipe', cwd });
64102
letstdout='';
65103
letcurrentRun='';
66104
construns=[];
@@ -79,20 +117,28 @@ async function testRunnerWatch({
79117
currentRun='';
80118
constcontent=fixtureContent[fileToUpdate];
81119
constpath=fixturePaths[fileToUpdate];
82-
writeFileSync(path,content);
83-
awaitsetTimeout(common.platformTimeout(1000));
84-
awaitran2.promise;
120+
121+
if(useRunApi){
122+
constinterval=setInterval(
123+
()=>writeFileSync(path,content),
124+
common.platformTimeout(1000),
125+
);
126+
awaitran2.promise;
127+
clearInterval(interval);
128+
}else{
129+
writeFileSync(path,content);
130+
awaitsetTimeout(common.platformTimeout(1000));
131+
awaitran2.promise;
132+
}
133+
85134
runs.push(currentRun);
86135
child.kill();
87136
awaitonce(child,'exit');
88137

89138
assert.strictEqual(runs.length,2);
90139

91140
for(construnofruns){
92-
assert.match(run,/tests1/);
93-
assert.match(run,/pass1/);
94-
assert.match(run,/fail0/);
95-
assert.match(run,/cancelled0/);
141+
assertTestOutput(run,useRunApi);
96142
}
97143
};
98144

@@ -102,31 +148,53 @@ async function testRunnerWatch({
102148
currentRun='';
103149
constfileToRenamePath=tmpdir.resolve(fileToUpdate);
104150
constnewFileNamePath=tmpdir.resolve(`test-renamed-${fileToUpdate}`);
105-
renameSync(fileToRenamePath,newFileNamePath);
106-
awaitsetTimeout(common.platformTimeout(1000));
151+
152+
awaitperformFileOperation(
153+
()=>renameSync(fileToRenamePath,newFileNamePath),
154+
useRunApi,
155+
);
107156
awaitran2.promise;
157+
108158
runs.push(currentRun);
109159
child.kill();
110160
awaitonce(child,'exit');
111161

112162
assert.strictEqual(runs.length,2);
113163

114-
for(construnofruns){
115-
assert.match(run,/tests1/);
116-
assert.match(run,/pass1/);
117-
assert.match(run,/fail0/);
118-
assert.match(run,/cancelled0/);
164+
const[firstRun,secondRun]=runs;
165+
assertTestOutput(firstRun,useRunApi);
166+
167+
if(action==='rename2'){
168+
assert.match(secondRun,/MODULE_NOT_FOUND/);
169+
return;
119170
}
171+
172+
assertTestOutput(secondRun,useRunApi);
120173
};
121174

122175
consttestDelete=async()=>{
123176
awaitran1.promise;
124177
runs.push(currentRun);
125178
currentRun='';
126179
constfileToDeletePath=tmpdir.resolve(fileToUpdate);
127-
unlinkSync(fileToDeletePath);
128-
awaitsetTimeout(common.platformTimeout(2000));
129-
ran2.resolve();
180+
181+
if(useRunApi){
182+
const{ existsSync }=require('node:fs');
183+
constinterval=setInterval(()=>{
184+
if(existsSync(fileToDeletePath)){
185+
unlinkSync(fileToDeletePath);
186+
}else{
187+
ran2.resolve();
188+
clearInterval(interval);
189+
}
190+
},common.platformTimeout(1000));
191+
awaitran2.promise;
192+
}else{
193+
unlinkSync(fileToDeletePath);
194+
awaitsetTimeout(common.platformTimeout(2000));
195+
ran2.resolve();
196+
}
197+
130198
runs.push(currentRun);
131199
child.kill();
132200
awaitonce(child,'exit');
@@ -143,25 +211,29 @@ async function testRunnerWatch({
143211
runs.push(currentRun);
144212
currentRun='';
145213
constnewFilePath=tmpdir.resolve(fileToCreate);
146-
writeFileSync(newFilePath,'module.exports = {};');
147-
awaitsetTimeout(common.platformTimeout(1000));
214+
215+
awaitperformFileOperation(
216+
()=>writeFileSync(newFilePath,'module.exports = {};'),
217+
useRunApi,
218+
);
148219
awaitran2.promise;
220+
149221
runs.push(currentRun);
150222
child.kill();
151223
awaitonce(child,'exit');
152224

153225
for(construnofruns){
154-
assert.match(run,/tests1/);
155-
assert.match(run,/pass1/);
156-
assert.match(run,/fail0/);
157-
assert.match(run,/cancelled0/);
226+
assertTestOutput(run,false);
158227
}
159228
};
160229

161230
action==='update'&&awaittestUpdate();
162231
action==='rename'&&awaittestRename();
232+
action==='rename2'&&awaittestRename();
163233
action==='delete'&&awaittestDelete();
164234
action==='create'&&awaittestCreate();
235+
236+
returnruns;
165237
}
166238

167239

@@ -170,4 +242,6 @@ module.exports = {
170242
skipIfNoWatchModeSignals,
171243
testRunnerWatch,
172244
refreshForTestRunnerWatch,
245+
fixtureContent,
246+
fixturePaths,
173247
};

‎test/parallel/parallel.status‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ test-snapshot-incompatible: SKIP
2424
test-inspector-network-fetch: PASS, FLAKY
2525
# https://github.com/nodejs/node/issues/54808
2626
test-async-context-frame: PASS, FLAKY
27-
# https://github.com/nodejs/node/issues/54534
28-
test-runner-run-watch: PASS, FLAKY
2927
# https://github.com/nodejs/node/issues/59636
3028
test-fs-cp-sync-error-on-exist: SKIP
3129
test-fs-cp-sync-symlink-points-to-dest-error: SKIP
@@ -43,8 +41,6 @@ test-without-async-context-frame: PASS, FLAKY
4341
test-performance-function: PASS, FLAKY
4442
# https://github.com/nodejs/node/issues/54346
4543
test-esm-loader-hooks-inspect-wait: PASS, FLAKY
46-
# https://github.com/nodejs/node/issues/54534
47-
test-runner-run-watch: PASS, FLAKY
4844

4945
[$system==linux && $arch==s390x]
5046
# https://github.com/nodejs/node/issues/58353
@@ -54,8 +50,6 @@ test-http2-debug: PASS, FLAKY
5450
# https://github.com/nodejs/node/issues/42741
5551
test-http-server-headers-timeout-keepalive: PASS,FLAKY
5652
test-http-server-request-timeout-keepalive: PASS,FLAKY
57-
# https://github.com/nodejs/node/issues/54534
58-
test-runner-run-watch: PASS, FLAKY
5953
# https://github.com/nodejs/node/issues/60050
6054
test-cluster-dgram-1: SKIP
6155

@@ -85,8 +79,6 @@ test-esm-loader-hooks-inspect-wait: PASS, FLAKY
8579
test-fs-promises-watch-iterator: SKIP
8680
# https://github.com/nodejs/node/issues/50050
8781
test-tick-processor-arguments: SKIP
88-
# https://github.com/nodejs/node/issues/54534
89-
test-runner-run-watch: PASS, FLAKY
9082

9183
[$system==freebsd]
9284
# https://github.com/nodejs/node/issues/54346

0 commit comments

Comments
 (0)