@@ -15,11 +15,16 @@ if (common.isIBMi)
15
15
common . skip ( 'IBMi does not support `fs.watch()`' ) ;
16
16
17
17
const supportsRecursive = common . isOSX || common . isWindows ;
18
+ let disableRestart = false ;
18
19
19
20
function restart ( file ) {
20
21
// To avoid flakiness, we save the file repeatedly until test is done
21
22
writeFileSync ( file , readFileSync ( file ) ) ;
22
- const timer = setInterval ( ( ) => writeFileSync ( file , readFileSync ( file ) ) , 1000 ) ;
23
+ const timer = setInterval ( ( ) => {
24
+ if ( ! disableRestart ) {
25
+ writeFileSync ( file , readFileSync ( file ) ) ;
26
+ }
27
+ } , common . platformTimeout ( 1000 ) ) ;
23
28
return ( ) => clearInterval ( timer ) ;
24
29
}
25
30
@@ -38,11 +43,15 @@ async function spawnWithRestarts({
38
43
let stdout = '' ;
39
44
let cancelRestarts ;
40
45
46
+ disableRestart = true ;
41
47
const child = spawn ( execPath , [ '--watch' , '--no-warnings' , ...args ] , { encoding : 'utf8' } ) ;
42
48
child . stderr . on ( 'data' , ( data ) => {
43
49
stderr += data ;
44
50
} ) ;
45
51
child . stdout . on ( 'data' , async ( data ) => {
52
+ if ( data . toString ( ) . includes ( 'Restarting' ) ) {
53
+ disableRestart = true ;
54
+ }
46
55
stdout += data ;
47
56
const restartsCount = stdout . match ( new RegExp ( `Restarting ${ printedArgs . replace ( / \\ / g, '\\\\' ) } ` , 'g' ) ) ?. length ?? 0 ;
48
57
if ( restarts === 0 || ! isReady ( data . toString ( ) ) ) {
@@ -54,6 +63,9 @@ async function spawnWithRestarts({
54
63
return ;
55
64
}
56
65
cancelRestarts ??= restart ( watchedFile ) ;
66
+ if ( isReady ( data . toString ( ) ) ) {
67
+ disableRestart = false ;
68
+ }
57
69
} ) ;
58
70
59
71
await once ( child , 'exit' ) ;
@@ -97,9 +109,9 @@ async function failWriteSucceed({ file, watchedFile }) {
97
109
98
110
tmpdir . refresh ( ) ;
99
111
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 } , ( ) => {
103
115
it ( 'should watch changes to a file - event loop ended' , async ( ) => {
104
116
const file = createTmpFile ( ) ;
105
117
const { stderr, stdout } = await spawnWithRestarts ( { file } ) ;
0 commit comments