Skip to content

Commit 140ae8d

Browse files
committed
feat: use node:fs/promises
1 parent 9daffe6 commit 140ae8d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

test/parallel/test-runner-watch-mode-complex.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as common from '../common/index.mjs';
33
import { describe, it } from 'node:test';
44
import assert from 'node:assert';
55
import { spawn } from 'node:child_process';
6-
import { writeFileSync, unlinkSync } from 'node:fs';
6+
import { writeFile, unlink } from 'node:fs/promises';
77
import util from 'internal/util';
88
import tmpdir from '../common/tmpdir.js';
99

@@ -46,8 +46,12 @@ test('test to delete has ran');`,
4646
const fixturePaths = Object.fromEntries(Object.keys(fixtureContent)
4747
.map((file) => [file, tmpdir.resolve(file)]));
4848

49-
Object.entries(fixtureContent)
50-
.forEach(([file, content]) => writeFileSync(fixturePaths[file], content));
49+
async function setupFixtures() {
50+
await Promise.all(Object.entries(fixtureContent)
51+
.map(([file, content]) => writeFile(fixturePaths[file], content)));
52+
}
53+
54+
await setupFixtures();
5155

5256
describe('test runner watch mode with more complex setup', () => {
5357
it('should run tests when a dependency changed after a watched test file being deleted', async () => {
@@ -76,14 +80,14 @@ describe('test runner watch mode with more complex setup', () => {
7680
runs.push(currentRun);
7781
currentRun = '';
7882
const fileToDeletePathLocal = tmpdir.resolve('test-to-delete.mjs');
79-
await new Promise((resolve) => setTimeout(() => {
80-
unlinkSync(fileToDeletePathLocal);
83+
await new Promise((resolve) => setTimeout(async () => {
84+
await unlink(fileToDeletePathLocal);
8185
resolve();
8286
}, common.platformTimeout(1000)));
8387

8488
const content = fixtureContent['dependency.mjs'];
8589
const path = fixturePaths['dependency.mjs'];
86-
setTimeout(() => writeFileSync(path, content), common.platformTimeout(1000));
90+
setTimeout(async () => await writeFile(path, content), common.platformTimeout(1000));
8791
await ran2.promise;
8892
runs.push(currentRun);
8993
currentRun = '';
@@ -103,4 +107,4 @@ describe('test runner watch mode with more complex setup', () => {
103107
assert.match(secondRun, /fail 0/);
104108
assert.match(secondRun, /cancelled 0/);
105109
});
106-
});
110+
});

0 commit comments

Comments
 (0)