@@ -3,7 +3,7 @@ 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
7
import util from 'internal/util' ;
8
8
import tmpdir from '../common/tmpdir.js' ;
9
9
@@ -15,6 +15,10 @@ if (common.isAIX)
15
15
16
16
tmpdir . refresh ( ) ;
17
17
18
+ function wait ( ms ) {
19
+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
20
+ }
21
+
18
22
// This test updates these files repeatedly,
19
23
// Reading them from disk is unreliable due to race conditions.
20
24
const fixtureContent = {
@@ -46,8 +50,12 @@ test('test to delete has ran');`,
46
50
const fixturePaths = Object . fromEntries ( Object . keys ( fixtureContent )
47
51
. map ( ( file ) => [ file , tmpdir . resolve ( file ) ] ) ) ;
48
52
49
- Object . entries ( fixtureContent )
50
- . forEach ( ( [ file , content ] ) => writeFileSync ( fixturePaths [ file ] , content ) ) ;
53
+ async function setupFixtures ( ) {
54
+ await Promise . all ( Object . entries ( fixtureContent )
55
+ . map ( ( [ file , content ] ) => writeFile ( fixturePaths [ file ] , content ) ) ) ;
56
+ }
57
+
58
+ await setupFixtures ( ) ;
51
59
52
60
describe ( 'test runner watch mode with more complex setup' , ( ) => {
53
61
it ( 'should run tests when a dependency changed after a watched test file being deleted' , async ( ) => {
@@ -76,14 +84,13 @@ describe('test runner watch mode with more complex setup', () => {
76
84
runs . push ( currentRun ) ;
77
85
currentRun = '' ;
78
86
const fileToDeletePathLocal = tmpdir . resolve ( 'test-to-delete.mjs' ) ;
79
- await new Promise ( ( resolve ) => setTimeout ( ( ) => {
80
- unlinkSync ( fileToDeletePathLocal ) ;
81
- resolve ( ) ;
82
- } , common . platformTimeout ( 1000 ) ) ) ;
87
+ await unlink ( fileToDeletePathLocal ) ;
88
+ await wait ( common . platformTimeout ( 1000 ) ) ;
83
89
84
90
const content = fixtureContent [ 'dependency.mjs' ] ;
85
91
const path = fixturePaths [ 'dependency.mjs' ] ;
86
- setTimeout ( ( ) => writeFileSync ( path , content ) , common . platformTimeout ( 1000 ) ) ;
92
+ await writeFile ( path , content ) ;
93
+ await wait ( common . platformTimeout ( 1000 ) ) ;
87
94
await ran2 . promise ;
88
95
runs . push ( currentRun ) ;
89
96
currentRun = '' ;
0 commit comments