@@ -3,7 +3,8 @@ import * as common from '../common/index.mjs';
3
3
import { describe , it } from 'node:test' ;
4
4
import assert from 'node:assert' ;
5
5
import { spawn } from 'node:child_process' ;
6
- import { writeFileSync , unlinkSync } from 'node:fs' ;
6
+ import { writeFile , unlink } from 'node:fs/promises' ;
7
+ import { setTimeout } from 'node:timers/promises' ;
7
8
import util from 'internal/util' ;
8
9
import tmpdir from '../common/tmpdir.js' ;
9
10
@@ -46,8 +47,12 @@ test('test to delete has ran');`,
46
47
const fixturePaths = Object . fromEntries ( Object . keys ( fixtureContent )
47
48
. map ( ( file ) => [ file , tmpdir . resolve ( file ) ] ) ) ;
48
49
49
- Object . entries ( fixtureContent )
50
- . forEach ( ( [ file , content ] ) => writeFileSync ( fixturePaths [ file ] , content ) ) ;
50
+ async function setupFixtures ( ) {
51
+ return Promise . all ( Object . entries ( fixtureContent )
52
+ . map ( ( [ file , content ] ) => writeFile ( fixturePaths [ file ] , content , { flush : true } ) ) ) ;
53
+ }
54
+
55
+ await setupFixtures ( ) ;
51
56
52
57
describe ( 'test runner watch mode with more complex setup' , ( ) => {
53
58
it ( 'should run tests when a dependency changed after a watched test file being deleted' , async ( ) => {
@@ -76,15 +81,16 @@ describe('test runner watch mode with more complex setup', () => {
76
81
runs . push ( currentRun ) ;
77
82
currentRun = '' ;
78
83
const fileToDeletePathLocal = tmpdir . resolve ( 'test-to-delete.mjs' ) ;
79
- unlinkSync ( fileToDeletePathLocal ) ;
84
+ await unlink ( fileToDeletePathLocal ) ;
85
+ await setTimeout ( common . platformTimeout ( 1000 ) ) ;
80
86
81
87
const content = fixtureContent [ 'dependency.mjs' ] ;
82
88
const path = fixturePaths [ 'dependency.mjs' ] ;
83
- const interval = setInterval ( ( ) => writeFileSync ( path , content ) , common . platformTimeout ( 1000 ) ) ;
89
+ await writeFile ( path , content , { flush : true } ) ;
90
+ await setTimeout ( common . platformTimeout ( 1000 ) ) ;
84
91
await ran2 . promise ;
85
92
runs . push ( currentRun ) ;
86
93
currentRun = '' ;
87
- clearInterval ( interval ) ;
88
94
child . kill ( ) ;
89
95
90
96
assert . strictEqual ( runs . length , 2 ) ;
0 commit comments