Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky test-runner-watch-mode #48144

Merged
merged 2 commits into from
May 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions test/parallel/test-runner-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@
import '../common/index.mjs';
import { describe, it } from 'node:test';
import { spawn } from 'node:child_process';
import { writeFileSync, readFileSync } from 'node:fs';
import { writeFileSync } from 'node:fs';
import util from 'internal/util';
import * as fixtures from '../common/fixtures.mjs';

// This test updates these files repeatedly,
// Reading them from disk is unreliable due to race conditions.
const fixtureContent = {
[fixtures.path('test-runner/dependent.js')]:
`const test = require('node:test');
require('./dependency.js');
import('./dependency.mjs');
import('data:text/javascript,');
test('test has ran');
`,
[fixtures.path('test-runner/dependency.js')]:
`module.exports = {};
`,
[fixtures.path('test-runner/dependency.mjs')]:
`export const a = 1;
`,
};

async function testWatch({ files, fileToUpdate }) {
const ran1 = util.createDeferredPromise();
const ran2 = util.createDeferredPromise();
Expand All @@ -20,7 +38,7 @@ async function testWatch({ files, fileToUpdate }) {
});

await ran1.promise;
const content = readFileSync(fileToUpdate, 'utf8');
const content = fixtureContent[fileToUpdate];
const interval = setInterval(() => writeFileSync(fileToUpdate, content), 10);
await ran2.promise;
clearInterval(interval);
Expand Down