Skip to content

Commit 7647250

Browse files
StefanStojanovictargos
authored andcommitted
test: fix test-watch-mode
Refs: #44898 PR-URL: #45585 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Erick Wendel <erick.workspace@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent cd36250 commit 7647250

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ if (common.isIBMi)
1515
common.skip('IBMi does not support `fs.watch()`');
1616

1717
constsupportsRecursive=common.isOSX||common.isWindows;
18+
letdisableRestart=false;
1819

1920
functionrestart(file){
2021
// To avoid flakiness, we save the file repeatedly until test is done
2122
writeFileSync(file,readFileSync(file));
22-
consttimer=setInterval(()=>writeFileSync(file,readFileSync(file)),1000);
23+
consttimer=setInterval(()=>{
24+
if(!disableRestart){
25+
writeFileSync(file,readFileSync(file));
26+
}
27+
},common.platformTimeout(1000));
2328
return()=>clearInterval(timer);
2429
}
2530

@@ -38,11 +43,15 @@ async function spawnWithRestarts({
3843
letstdout='';
3944
letcancelRestarts;
4045

46+
disableRestart=true;
4147
constchild=spawn(execPath,['--watch','--no-warnings', ...args],{encoding: 'utf8'});
4248
child.stderr.on('data',(data)=>{
4349
stderr+=data;
4450
});
4551
child.stdout.on('data',async(data)=>{
52+
if(data.toString().includes('Restarting')){
53+
disableRestart=true;
54+
}
4655
stdout+=data;
4756
constrestartsCount=stdout.match(newRegExp(`Restarting ${printedArgs.replace(/\\/g,'\\\\')}`,'g'))?.length??0;
4857
if(restarts===0||!isReady(data.toString())){
@@ -54,6 +63,9 @@ async function spawnWithRestarts({
5463
return;
5564
}
5665
cancelRestarts??=restart(watchedFile);
66+
if(isReady(data.toString())){
67+
disableRestart=false;
68+
}
5769
});
5870

5971
awaitonce(child,'exit');
@@ -97,9 +109,9 @@ async function failWriteSucceed({ file, watchedFile }) {
97109

98110
tmpdir.refresh();
99111

100-
// Warning: this suite can run safely with concurrency: true
101-
// only if tests do not watch/depend on the same files
102-
describe('watch mode',{concurrency: true,timeout: 60_000},()=>{
112+
// Warning: this suite cannot run safely with concurrency: true
113+
// because of the disableRestart flag used for controlling restarts
114+
describe('watch mode',{concurrency: false,timeout: 60_000},()=>{
103115
it('should watch changes to a file - event loop ended',async()=>{
104116
constfile=createTmpFile();
105117
const{ stderr, stdout }=awaitspawnWithRestarts({ file });

0 commit comments

Comments
 (0)