Skip to content

Commit 02e8972

Browse files
authored
test: remove interval and give more time to unsync
PR-URL: #55006 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
1 parent a6ece28 commit 02e8972

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ 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';
7+
import { setTimeout } from 'node:timers/promises';
78
import util from 'internal/util';
89
import tmpdir from '../common/tmpdir.js';
910

@@ -46,8 +47,12 @@ test('test to delete has ran');`,
4647
const 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

5257
describe('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

Comments
 (0)