Skip to content

Commit 48930c6

Browse files
committed
feat: use node:fs/promises
1 parent 9daffe6 commit 48930c6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 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

@@ -15,6 +15,10 @@ if (common.isAIX)
1515

1616
tmpdir.refresh();
1717

18+
function wait(ms) {
19+
return new Promise((resolve) => setTimeout(resolve, ms));
20+
}
21+
1822
// This test updates these files repeatedly,
1923
// Reading them from disk is unreliable due to race conditions.
2024
const fixtureContent = {
@@ -46,8 +50,12 @@ test('test to delete has ran');`,
4650
const fixturePaths = Object.fromEntries(Object.keys(fixtureContent)
4751
.map((file) => [file, tmpdir.resolve(file)]));
4852

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();
5159

5260
describe('test runner watch mode with more complex setup', () => {
5361
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', () => {
7684
runs.push(currentRun);
7785
currentRun = '';
7886
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));
8389

8490
const content = fixtureContent['dependency.mjs'];
8591
const path = fixturePaths['dependency.mjs'];
86-
setTimeout(() => writeFileSync(path, content), common.platformTimeout(1000));
92+
await writeFile(path, content);
93+
await wait(common.platformTimeout(1000));
8794
await ran2.promise;
8895
runs.push(currentRun);
8996
currentRun = '';

0 commit comments

Comments
 (0)