Skip to content

Commit c1ec099

Browse files
authored
test: make sure current run result is pushed and reset
PR-URL: #54332 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 9f08320 commit c1ec099

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

test/parallel/test-runner-run-watch.mjs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { join } from 'node:path';
1212
if (common.isIBMi)
1313
common.skip('IBMi does not support `fs.watch()`');
1414

15+
if (common.isAIX)
16+
common.skip('folder watch capability is limited in AIX.');
17+
1518
// This test updates these files repeatedly,
1619
// Reading them from disk is unreliable due to race conditions.
1720
const fixtureContent = {
@@ -60,6 +63,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
6063

6164
const testUpdate = async () => {
6265
await ran1.promise;
66+
runs.push(currentRun);
67+
currentRun = '';
6368
const content = fixtureContent[fileToUpdate];
6469
const path = fixturePaths[fileToUpdate];
6570
const interval = setInterval(() => writeFileSync(path, content), common.platformTimeout(1000));
@@ -68,6 +73,9 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
6873
clearInterval(interval);
6974
child.kill();
7075
await once(child, 'exit');
76+
77+
assert.strictEqual(runs.length, 2);
78+
7179
for (const run of runs) {
7280
assert.doesNotMatch(run, /run\(\) is being called recursively/);
7381
assert.match(run, /# tests 1/);
@@ -79,6 +87,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
7987

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

91-
for (const run of runs) {
92-
assert.doesNotMatch(run, /run\(\) is being called recursively/);
93-
if (action === 'rename2') {
94-
assert.match(run, /MODULE_NOT_FOUND/);
95-
} else {
96-
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
97-
}
98-
assert.match(run, /# tests 1/);
99-
assert.match(run, /# pass 1/);
100-
assert.match(run, /# fail 0/);
101-
assert.match(run, /# cancelled 0/);
101+
assert.strictEqual(runs.length, 2);
102+
103+
const [firstRun, secondRun] = runs;
104+
assert.match(firstRun, /# tests 1/);
105+
assert.match(firstRun, /# pass 1/);
106+
assert.match(firstRun, /# fail 0/);
107+
assert.match(firstRun, /# cancelled 0/);
108+
assert.doesNotMatch(firstRun, /run\(\) is being called recursively/);
109+
110+
if (action === 'rename2') {
111+
assert.match(secondRun, /MODULE_NOT_FOUND/);
112+
return;
102113
}
114+
115+
assert.match(secondRun, /# tests 1/);
116+
assert.match(secondRun, /# pass 1/);
117+
assert.match(secondRun, /# fail 0/);
118+
assert.match(secondRun, /# cancelled 0/);
119+
assert.doesNotMatch(secondRun, /run\(\) is being called recursively/);
103120
};
104121

105122
const testDelete = async () => {
106123
await ran1.promise;
124+
runs.push(currentRun);
125+
currentRun = '';
107126
const fileToDeletePath = tmpdir.resolve(fileToUpdate);
108127
const interval = setInterval(() => {
109128
if (existsSync(fileToDeletePath)) {
@@ -118,6 +137,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
118137
child.kill();
119138
await once(child, 'exit');
120139

140+
assert.strictEqual(runs.length, 2);
141+
121142
for (const run of runs) {
122143
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
123144
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import tmpdir from '../common/tmpdir.js';
1111
if (common.isIBMi)
1212
common.skip('IBMi does not support `fs.watch()`');
1313

14+
if (common.isAIX)
15+
common.skip('folder watch capability is limited in AIX.');
16+
1417
let fixturePaths;
1518

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

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

71+
assert.strictEqual(runs.length, 2);
72+
6673
for (const run of runs) {
6774
assert.match(run, /# tests 1/);
6875
assert.match(run, /# pass 1/);
@@ -73,6 +80,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
7380

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

94+
assert.strictEqual(runs.length, 2);
95+
8596
for (const run of runs) {
8697
assert.match(run, /# tests 1/);
8798
assert.match(run, /# pass 1/);
@@ -92,6 +103,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
92103

93104
const testDelete = async () => {
94105
await ran1.promise;
106+
runs.push(currentRun);
107+
currentRun = '';
95108
const fileToDeletePath = tmpdir.resolve(fileToUpdate);
96109
const interval = setInterval(() => {
97110
if (existsSync(fileToDeletePath)) {
@@ -106,6 +119,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
106119
child.kill();
107120
await once(child, 'exit');
108121

122+
assert.strictEqual(runs.length, 2);
123+
109124
for (const run of runs) {
110125
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
111126
}

0 commit comments

Comments
 (0)