@@ -3,7 +3,8 @@ import * as common from '../common/index.mjs';
33import { describe , it } from 'node:test' ;
44import assert from 'node:assert' ;
55import { 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' ;
78import util from 'internal/util' ;
89import tmpdir from '../common/tmpdir.js' ;
910
@@ -46,8 +47,12 @@ test('test to delete has ran');`,
4647const fixturePaths = Object . fromEntries ( Object . keys ( fixtureContent )
4748 . map ( ( file ) => [ file , tmpdir . resolve ( file ) ] ) ) ;
4849
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 ( ) ;
5156
5257describe ( 'test runner watch mode with more complex setup' , ( ) => {
5358 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', () => {
7681 runs . push ( currentRun ) ;
7782 currentRun = '' ;
7883 const fileToDeletePathLocal = tmpdir . resolve ( 'test-to-delete.mjs' ) ;
79- unlinkSync ( fileToDeletePathLocal ) ;
84+ await unlink ( fileToDeletePathLocal ) ;
85+ await setTimeout ( common . platformTimeout ( 1000 ) ) ;
8086
8187 const content = fixtureContent [ 'dependency.mjs' ] ;
8288 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 ) ) ;
8491 await ran2 . promise ;
8592 runs . push ( currentRun ) ;
8693 currentRun = '' ;
87- clearInterval ( interval ) ;
8894 child . kill ( ) ;
8995
9096 assert . strictEqual ( runs . length , 2 ) ;
0 commit comments