Skip to content

Commit 6f3587c

Browse files
trivikraduh95
authored andcommitted
test: deflake watch mode worker test
Trigger watch restarts by appending whitespace instead of rewriting watched modules. This avoids transient empty or partial ESM dependency contents while the restarted worker is loading. Use a separate temporary directory for each subtest so concurrent subtests do not share worker and dependency file names. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: #63384 Refs: https://github.com/nodejs/reliability/blob/main/reports/2026-05-17.md#jstest-failure Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent ad98b46 commit 6f3587c

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎test/sequential/test-watch-mode-worker.mjs‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import path from 'node:path';
55
import{execPath}from'node:process';
66
import{describe,it}from'node:test';
77
import{spawn}from'node:child_process';
8-
import{writeFileSync,readFileSync}from'node:fs';
8+
import{appendFileSync,mkdirSync,writeFileSync}from'node:fs';
99
import{inspect}from'node:util';
1010
import{pathToFileURL}from'node:url';
1111
import{createInterface}from'node:readline';
1212

1313
if(common.isIBMi)
1414
common.skip('IBMi does not support `fs.watch()`');
1515

16-
functionrestart(file,content=readFileSync(file)){
17-
writeFileSync(file,content);
18-
consttimer=setInterval(()=>writeFileSync(file,content),common.platformTimeout(250));
16+
functionrestart(file){
17+
appendFileSync(file,'\n');
18+
consttimer=setInterval(()=>appendFileSync(file,'\n'),common.platformTimeout(250));
1919
return()=>clearInterval(timer);
2020
}
2121

@@ -26,6 +26,12 @@ function createTmpFile(content = 'console.log(\'running\');', ext = '.js', basen
2626
returnfile;
2727
}
2828

29+
functioncreateTmpDir(){
30+
constdir=path.join(tmpdir.path,`${tmpFiles++}`);
31+
mkdirSync(dir);
32+
returndir;
33+
}
34+
2935
asyncfunctionrunWriteSucceed({
3036
file,
3137
watchedFile,
@@ -78,10 +84,10 @@ async function runWriteSucceed({
7884
}
7985

8086
tmpdir.refresh();
81-
constdir=tmpdir.path;
8287

8388
describe('watch mode',{concurrency: !process.env.TEST_PARALLEL,timeout: 60_000},()=>{
8489
it('should watch changes to worker - cjs',async()=>{
90+
constdir=createTmpDir();
8591
constworker=path.join(dir,'worker.js');
8692

8793
writeFileSync(worker,`
@@ -109,6 +115,7 @@ const w = new Worker(${JSON.stringify(worker)});
109115
});
110116

111117
it('should watch changes to worker dependencies - cjs',async()=>{
118+
constdir=createTmpDir();
112119
constdep=path.join(dir,'dep.js');
113120
constworker=path.join(dir,'worker.js');
114121

@@ -142,6 +149,7 @@ const w = new Worker(${JSON.stringify(worker)});
142149
});
143150

144151
it('should watch changes to nested worker dependencies - cjs',async()=>{
152+
constdir=createTmpDir();
145153
constsubDep=path.join(dir,'sub-dep.js');
146154
constdep=path.join(dir,'dep.js');
147155
constworker=path.join(dir,'worker.js');
@@ -181,6 +189,7 @@ const w = new Worker(${JSON.stringify(worker)});
181189
});
182190

183191
it('should watch changes to worker - esm',async()=>{
192+
constdir=createTmpDir();
184193
constworker=path.join(dir,'worker.mjs');
185194

186195
writeFileSync(worker,`
@@ -208,6 +217,7 @@ new Worker(new URL(${JSON.stringify(pathToFileURL(worker))}));
208217
});
209218

210219
it('should watch changes to worker dependencies - esm',async()=>{
220+
constdir=createTmpDir();
211221
constdep=path.join(dir,'dep.mjs');
212222
constworker=path.join(dir,'worker.mjs');
213223

@@ -241,6 +251,7 @@ new Worker(new URL(${JSON.stringify(pathToFileURL(worker))}));
241251
});
242252

243253
it('should watch changes to nested worker dependencies - esm',async()=>{
254+
constdir=createTmpDir();
244255
constsubDep=path.join(dir,'sub-dep.mjs');
245256
constdep=path.join(dir,'dep.mjs');
246257
constworker=path.join(dir,'worker.mjs');

0 commit comments

Comments
 (0)