Skip to content

Commit

Permalink
feat: use node:fs/promises
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarchini committed Sep 20, 2024
1 parent 9daffe6 commit 48930c6
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test/parallel/test-runner-watch-mode-complex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as common from '../common/index.mjs';
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { spawn } from 'node:child_process';
import { writeFileSync, unlinkSync } from 'node:fs';
import { writeFile, unlink } from 'node:fs/promises';
import util from 'internal/util';
import tmpdir from '../common/tmpdir.js';

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

tmpdir.refresh();

function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

// This test updates these files repeatedly,
// Reading them from disk is unreliable due to race conditions.
const fixtureContent = {
Expand Down Expand Up @@ -46,8 +50,12 @@ test('test to delete has ran');`,
const fixturePaths = Object.fromEntries(Object.keys(fixtureContent)
.map((file) => [file, tmpdir.resolve(file)]));

Object.entries(fixtureContent)
.forEach(([file, content]) => writeFileSync(fixturePaths[file], content));
async function setupFixtures() {
await Promise.all(Object.entries(fixtureContent)
.map(([file, content]) => writeFile(fixturePaths[file], content)));
}

await setupFixtures();

describe('test runner watch mode with more complex setup', () => {
it('should run tests when a dependency changed after a watched test file being deleted', async () => {
Expand Down Expand Up @@ -76,14 +84,13 @@ describe('test runner watch mode with more complex setup', () => {
runs.push(currentRun);
currentRun = '';
const fileToDeletePathLocal = tmpdir.resolve('test-to-delete.mjs');
await new Promise((resolve) => setTimeout(() => {
unlinkSync(fileToDeletePathLocal);
resolve();
}, common.platformTimeout(1000)));
await unlink(fileToDeletePathLocal);
await wait(common.platformTimeout(1000));

const content = fixtureContent['dependency.mjs'];
const path = fixturePaths['dependency.mjs'];
setTimeout(() => writeFileSync(path, content), common.platformTimeout(1000));
await writeFile(path, content);
await wait(common.platformTimeout(1000));
await ran2.promise;
runs.push(currentRun);
currentRun = '';
Expand Down

0 comments on commit 48930c6

Please sign in to comment.