Skip to content

Commit

Permalink
test: make sure current run result is pushed and reset
Browse files Browse the repository at this point in the history
PR-URL: #54332
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
jakecastelli authored and RafaelGSS committed Aug 19, 2024
1 parent 1278555 commit 3df7938
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
43 changes: 32 additions & 11 deletions test/parallel/test-runner-run-watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { join } from 'node:path';
if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');

if (common.isAIX)
common.skip('folder watch capability is limited in AIX.');

// This test updates these files repeatedly,
// Reading them from disk is unreliable due to race conditions.
const fixtureContent = {
Expand Down Expand Up @@ -60,6 +63,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p

const testUpdate = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const content = fixtureContent[fileToUpdate];
const path = fixturePaths[fileToUpdate];
const interval = setInterval(() => writeFileSync(path, content), common.platformTimeout(1000));
Expand All @@ -68,6 +73,9 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
clearInterval(interval);
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.doesNotMatch(run, /run\(\) is being called recursively/);
assert.match(run, /# tests 1/);
Expand All @@ -79,6 +87,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p

const testRename = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToRenamePath = tmpdir.resolve(fileToUpdate);
const newFileNamePath = tmpdir.resolve(`test-renamed-${fileToUpdate}`);
const interval = setInterval(() => renameSync(fileToRenamePath, newFileNamePath), common.platformTimeout(1000));
Expand All @@ -88,22 +98,31 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
child.kill();
await once(child, 'exit');

for (const run of runs) {
assert.doesNotMatch(run, /run\(\) is being called recursively/);
if (action === 'rename2') {
assert.match(run, /MODULE_NOT_FOUND/);
} else {
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
}
assert.match(run, /# tests 1/);
assert.match(run, /# pass 1/);
assert.match(run, /# fail 0/);
assert.match(run, /# cancelled 0/);
assert.strictEqual(runs.length, 2);

const [firstRun, secondRun] = runs;
assert.match(firstRun, /# tests 1/);
assert.match(firstRun, /# pass 1/);
assert.match(firstRun, /# fail 0/);
assert.match(firstRun, /# cancelled 0/);
assert.doesNotMatch(firstRun, /run\(\) is being called recursively/);

if (action === 'rename2') {
assert.match(secondRun, /MODULE_NOT_FOUND/);
return;
}

assert.match(secondRun, /# tests 1/);
assert.match(secondRun, /# pass 1/);
assert.match(secondRun, /# fail 0/);
assert.match(secondRun, /# cancelled 0/);
assert.doesNotMatch(secondRun, /run\(\) is being called recursively/);
};

const testDelete = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToDeletePath = tmpdir.resolve(fileToUpdate);
const interval = setInterval(() => {
if (existsSync(fileToDeletePath)) {
Expand All @@ -118,6 +137,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
}
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-runner-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import tmpdir from '../common/tmpdir.js';
if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');

if (common.isAIX)
common.skip('folder watch capability is limited in AIX.');

let fixturePaths;

// This test updates these files repeatedly,
Expand Down Expand Up @@ -54,6 +57,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {

const testUpdate = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const content = fixtureContent[fileToUpdate];
const path = fixturePaths[fileToUpdate];
const interval = setInterval(() => writeFileSync(path, content), common.platformTimeout(1000));
Expand All @@ -63,6 +68,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.match(run, /# tests 1/);
assert.match(run, /# pass 1/);
Expand All @@ -73,6 +80,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {

const testRename = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToRenamePath = tmpdir.resolve(fileToUpdate);
const newFileNamePath = tmpdir.resolve(`test-renamed-${fileToUpdate}`);
const interval = setInterval(() => renameSync(fileToRenamePath, newFileNamePath), common.platformTimeout(1000));
Expand All @@ -82,6 +91,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.match(run, /# tests 1/);
assert.match(run, /# pass 1/);
Expand All @@ -92,6 +103,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {

const testDelete = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToDeletePath = tmpdir.resolve(fileToUpdate);
const interval = setInterval(() => {
if (existsSync(fileToDeletePath)) {
Expand All @@ -106,6 +119,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
}
Expand Down

0 comments on commit 3df7938

Please sign in to comment.