Skip to content

Commit 27796e6

Browse files
committed
test: split test-runner-run-watch.mjs
This test contains too many independent test cases and as a result, marking it as flaky on all major platforms means actual regressions could be covered up, and it's constantly making the CI orange and requires extra resuming on the flaked platforms which is still not great. Split it into individual files so that the actual flake can be identified out of the monolith.
1 parent 8e5c80d commit 27796e6

20 files changed

+400
-436
lines changed

test/common/watch.js

Lines changed: 102 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,58 @@ function refreshForTestRunnerWatch() {
4747
}
4848
}
4949

50+
async function performFileOperation(operation, useRunApi, timeout = 1000) {
51+
if (useRunApi) {
52+
const interval = setInterval(() => {
53+
operation();
54+
clearInterval(interval);
55+
}, common.platformTimeout(timeout));
56+
} else {
57+
operation();
58+
await setTimeout(common.platformTimeout(timeout));
59+
}
60+
}
61+
62+
function assertTestOutput(run, shouldCheckRecursion = false) {
63+
if (shouldCheckRecursion) {
64+
assert.doesNotMatch(run, /run\(\) is being called recursively/);
65+
}
66+
assert.match(run, /tests 1/);
67+
assert.match(run, /pass 1/);
68+
assert.match(run, /fail 0/);
69+
assert.match(run, /cancelled 0/);
70+
}
71+
5072
async function testRunnerWatch({
5173
fileToUpdate,
5274
file,
5375
action = 'update',
5476
fileToCreate,
5577
isolation,
78+
useRunApi = false,
79+
cwd = tmpdir.path,
80+
runnerCwd,
5681
}) {
5782
const ran1 = Promise.withResolvers();
5883
const ran2 = Promise.withResolvers();
59-
const child = spawn(process.execPath,
60-
['--watch', '--test', '--test-reporter=spec',
61-
isolation ? `--test-isolation=${isolation}` : '',
62-
file ? fixturePaths[file] : undefined].filter(Boolean),
63-
{ encoding: 'utf8', stdio: 'pipe', cwd: tmpdir.path });
84+
85+
let args;
86+
if (useRunApi) {
87+
// Use the fixture that calls run() API
88+
const runner = fixtures.path('test-runner-watch.mjs');
89+
args = [runner];
90+
if (file) args.push('--file', file);
91+
if (runnerCwd) args.push('--cwd', runnerCwd);
92+
if (isolation) args.push('--isolation', isolation);
93+
} else {
94+
// Use CLI --watch --test flags
95+
args = ['--watch', '--test', '--test-reporter=spec',
96+
isolation ? `--test-isolation=${isolation}` : '',
97+
file ? fixturePaths[file] : undefined].filter(Boolean);
98+
}
99+
100+
const child = spawn(process.execPath, args,
101+
{ encoding: 'utf8', stdio: 'pipe', cwd });
64102
let stdout = '';
65103
let currentRun = '';
66104
const runs = [];
@@ -79,20 +117,28 @@ async function testRunnerWatch({
79117
currentRun = '';
80118
const content = fixtureContent[fileToUpdate];
81119
const path = fixturePaths[fileToUpdate];
82-
writeFileSync(path, content);
83-
await setTimeout(common.platformTimeout(1000));
84-
await ran2.promise;
120+
121+
if (useRunApi) {
122+
const interval = setInterval(
123+
() => writeFileSync(path, content),
124+
common.platformTimeout(1000),
125+
);
126+
await ran2.promise;
127+
clearInterval(interval);
128+
} else {
129+
writeFileSync(path, content);
130+
await setTimeout(common.platformTimeout(1000));
131+
await ran2.promise;
132+
}
133+
85134
runs.push(currentRun);
86135
child.kill();
87136
await once(child, 'exit');
88137

89138
assert.strictEqual(runs.length, 2);
90139

91140
for (const run of runs) {
92-
assert.match(run, /tests 1/);
93-
assert.match(run, /pass 1/);
94-
assert.match(run, /fail 0/);
95-
assert.match(run, /cancelled 0/);
141+
assertTestOutput(run, useRunApi);
96142
}
97143
};
98144

@@ -102,31 +148,53 @@ async function testRunnerWatch({
102148
currentRun = '';
103149
const fileToRenamePath = tmpdir.resolve(fileToUpdate);
104150
const newFileNamePath = tmpdir.resolve(`test-renamed-${fileToUpdate}`);
105-
renameSync(fileToRenamePath, newFileNamePath);
106-
await setTimeout(common.platformTimeout(1000));
151+
152+
await performFileOperation(
153+
() => renameSync(fileToRenamePath, newFileNamePath),
154+
useRunApi,
155+
);
107156
await ran2.promise;
157+
108158
runs.push(currentRun);
109159
child.kill();
110160
await once(child, 'exit');
111161

112162
assert.strictEqual(runs.length, 2);
113163

114-
for (const run of runs) {
115-
assert.match(run, /tests 1/);
116-
assert.match(run, /pass 1/);
117-
assert.match(run, /fail 0/);
118-
assert.match(run, /cancelled 0/);
164+
const [firstRun, secondRun] = runs;
165+
assertTestOutput(firstRun, useRunApi);
166+
167+
if (action === 'rename2') {
168+
assert.match(secondRun, /MODULE_NOT_FOUND/);
169+
return;
119170
}
171+
172+
assertTestOutput(secondRun, useRunApi);
120173
};
121174

122175
const testDelete = async () => {
123176
await ran1.promise;
124177
runs.push(currentRun);
125178
currentRun = '';
126179
const fileToDeletePath = tmpdir.resolve(fileToUpdate);
127-
unlinkSync(fileToDeletePath);
128-
await setTimeout(common.platformTimeout(2000));
129-
ran2.resolve();
180+
181+
if (useRunApi) {
182+
const { existsSync } = require('node:fs');
183+
const interval = setInterval(() => {
184+
if (existsSync(fileToDeletePath)) {
185+
unlinkSync(fileToDeletePath);
186+
} else {
187+
ran2.resolve();
188+
clearInterval(interval);
189+
}
190+
}, common.platformTimeout(1000));
191+
await ran2.promise;
192+
} else {
193+
unlinkSync(fileToDeletePath);
194+
await setTimeout(common.platformTimeout(2000));
195+
ran2.resolve();
196+
}
197+
130198
runs.push(currentRun);
131199
child.kill();
132200
await once(child, 'exit');
@@ -143,25 +211,29 @@ async function testRunnerWatch({
143211
runs.push(currentRun);
144212
currentRun = '';
145213
const newFilePath = tmpdir.resolve(fileToCreate);
146-
writeFileSync(newFilePath, 'module.exports = {};');
147-
await setTimeout(common.platformTimeout(1000));
214+
215+
await performFileOperation(
216+
() => writeFileSync(newFilePath, 'module.exports = {};'),
217+
useRunApi,
218+
);
148219
await ran2.promise;
220+
149221
runs.push(currentRun);
150222
child.kill();
151223
await once(child, 'exit');
152224

153225
for (const run of runs) {
154-
assert.match(run, /tests 1/);
155-
assert.match(run, /pass 1/);
156-
assert.match(run, /fail 0/);
157-
assert.match(run, /cancelled 0/);
226+
assertTestOutput(run, false);
158227
}
159228
};
160229

161230
action === 'update' && await testUpdate();
162231
action === 'rename' && await testRename();
232+
action === 'rename2' && await testRename();
163233
action === 'delete' && await testDelete();
164234
action === 'create' && await testCreate();
235+
236+
return runs;
165237
}
166238

167239

@@ -170,4 +242,6 @@ module.exports = {
170242
skipIfNoWatchModeSignals,
171243
testRunnerWatch,
172244
refreshForTestRunnerWatch,
245+
fixtureContent,
246+
fixturePaths,
173247
};

test/parallel/parallel.status

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ test-snapshot-incompatible: SKIP
2424
test-inspector-network-fetch: PASS, FLAKY
2525
# https://github.com/nodejs/node/issues/54808
2626
test-async-context-frame: PASS, FLAKY
27-
# https://github.com/nodejs/node/issues/54534
28-
test-runner-run-watch: PASS, FLAKY
2927
# https://github.com/nodejs/node/issues/59636
3028
test-fs-cp-sync-error-on-exist: SKIP
3129
test-fs-cp-sync-symlink-points-to-dest-error: SKIP
@@ -43,8 +41,6 @@ test-without-async-context-frame: PASS, FLAKY
4341
test-performance-function: PASS, FLAKY
4442
# https://github.com/nodejs/node/issues/54346
4543
test-esm-loader-hooks-inspect-wait: PASS, FLAKY
46-
# https://github.com/nodejs/node/issues/54534
47-
test-runner-run-watch: PASS, FLAKY
4844

4945
[$system==linux && $arch==s390x]
5046
# https://github.com/nodejs/node/issues/58353
@@ -54,8 +50,6 @@ test-http2-debug: PASS, FLAKY
5450
# https://github.com/nodejs/node/issues/42741
5551
test-http-server-headers-timeout-keepalive: PASS,FLAKY
5652
test-http-server-request-timeout-keepalive: PASS,FLAKY
57-
# https://github.com/nodejs/node/issues/54534
58-
test-runner-run-watch: PASS, FLAKY
5953
# https://github.com/nodejs/node/issues/60050
6054
test-cluster-dgram-1: SKIP
6155

@@ -85,8 +79,6 @@ test-esm-loader-hooks-inspect-wait: PASS, FLAKY
8579
test-fs-promises-watch-iterator: SKIP
8680
# https://github.com/nodejs/node/issues/50050
8781
test-tick-processor-arguments: SKIP
88-
# https://github.com/nodejs/node/issues/54534
89-
test-runner-run-watch: PASS, FLAKY
9082

9183
[$system==freebsd]
9284
# https://github.com/nodejs/node/issues/54346

0 commit comments

Comments
 (0)