Skip to content

Commit 3ad523c

Browse files
committed
test: split test-runner-watch-mode-kill-signal
This test has been timing out in the CI with no information about why. Splitting it into multiple files to at least show which test case is timing out. Drive-by: name the test as test-watch-mode-kill-signal-* as the tests aren't testing the test runner and are just testing --watch-kill-signal.
1 parent 8096aea commit 3ad523c

File tree

7 files changed

+148
-131
lines changed

7 files changed

+148
-131
lines changed

test/common/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,20 @@ function expectRequiredTLAError(err) {
913913
}
914914
}
915915

916+
function skipIfNoWatchModeSignals() {
917+
if (exports.isWindows) {
918+
skip('no signals on Windows');
919+
}
920+
921+
if (exports.isIBMi) {
922+
skip('IBMi does not support `fs.watch()`');
923+
}
924+
925+
if (exports.isAIX) {
926+
skip('folder watch capability is limited in AIX.');
927+
}
928+
}
929+
916930
const common = {
917931
allowGlobals,
918932
buildType,
@@ -960,6 +974,7 @@ const common = {
960974
skipIf32Bits,
961975
skipIfEslintMissing,
962976
skipIfInspectorDisabled,
977+
skipIfNoWatchModeSignals,
963978
skipIfSQLiteMissing,
964979
spawnPromisified,
965980

test/common/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const {
4646
skipIf32Bits,
4747
skipIfEslintMissing,
4848
skipIfInspectorDisabled,
49+
skipIfNoWatchModeSignals,
4950
skipIfSQLiteMissing,
5051
spawnPromisified,
5152
} = common;
@@ -97,6 +98,7 @@ export {
9798
skipIf32Bits,
9899
skipIfEslintMissing,
99100
skipIfInspectorDisabled,
101+
skipIfNoWatchModeSignals,
100102
skipIfSQLiteMissing,
101103
spawnPromisified,
102104
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
process.on('SIGTERM', () => { console.log('__SIGTERM received__'); process.exit(); });
2+
process.on('SIGINT', () => { console.log('__SIGINT received__'); process.exit(); });
3+
process.send('script ready');
4+
setTimeout(() => {}, 100_000);

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

Lines changed: 0 additions & 131 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Test that the kill signal sent by --watch defaults to SIGTERM.
2+
3+
import { skipIfNoWatchModeSignals } from '../common/index.mjs';
4+
import assert from 'node:assert';
5+
import { writeFileSync } from 'node:fs';
6+
import { spawn } from 'node:child_process';
7+
import { once } from 'node:events';
8+
import tmpdir from '../common/tmpdir.js';
9+
import fixtures from '../common/fixtures.js';
10+
11+
skipIfNoWatchModeSignals();
12+
13+
tmpdir.refresh();
14+
const indexPath = tmpdir.resolve('kill-signal-for-watch.js');
15+
const indexContents = fixtures.readSync('kill-signal-for-watch.js', 'utf8');
16+
writeFileSync(indexPath, indexContents);
17+
18+
const child = spawn(
19+
process.execPath,
20+
['--watch', indexPath],
21+
{
22+
cwd: tmpdir.path,
23+
stdio: ['inherit', 'pipe', 'inherit', 'ipc'],
24+
}
25+
);
26+
27+
let stdout = '';
28+
child.stdout.on('data', (data) => {
29+
stdout += `${data}`;
30+
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
31+
child.kill();
32+
}
33+
});
34+
35+
child.on('message', (msg) => {
36+
if (msg === 'script ready') {
37+
writeFileSync(indexPath, indexContents);
38+
}
39+
});
40+
41+
await once(child, 'exit');
42+
43+
assert.match(stdout, /__SIGTERM received__/);
44+
assert.doesNotMatch(stdout, /__SIGINT received__/);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Test that --watch-kill-signal errors when an invalid kill signal is provided.
2+
3+
import { skipIfNoWatchModeSignals } from '../common/index.mjs';
4+
import assert from 'node:assert';
5+
import { writeFileSync } from 'node:fs';
6+
import { spawn } from 'node:child_process';
7+
import tmpdir from '../common/tmpdir.js';
8+
import fixtures from '../common/fixtures.js';
9+
10+
skipIfNoWatchModeSignals();
11+
12+
tmpdir.refresh();
13+
const indexPath = tmpdir.resolve('kill-signal-for-watch.js');
14+
const indexContents = fixtures.readSync('kill-signal-for-watch.js', 'utf8');
15+
writeFileSync(indexPath, indexContents);
16+
17+
const currentRun = Promise.withResolvers();
18+
const child = spawn(
19+
process.execPath,
20+
['--watch', '--watch-kill-signal', 'invalid_signal', indexPath],
21+
{
22+
cwd: tmpdir.path,
23+
stdio: ['inherit', 'inherit', 'pipe'],
24+
}
25+
);
26+
let stderr = '';
27+
28+
child.stderr.on('data', (data) => {
29+
stderr += data.toString();
30+
currentRun.resolve();
31+
});
32+
33+
await currentRun.promise;
34+
35+
assert.match(
36+
stderr,
37+
/TypeError \[ERR_UNKNOWN_SIGNAL\]: Unknown signal: invalid_signal/
38+
);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Test that the kill signal sent by --watch can be overridden to SIGINT
2+
// by using --watch-kill-signal.
3+
4+
import { skipIfNoWatchModeSignals } from '../common/index.mjs';
5+
import assert from 'node:assert';
6+
import { writeFileSync } from 'node:fs';
7+
import { spawn } from 'node:child_process';
8+
import { once } from 'node:events';
9+
import tmpdir from '../common/tmpdir.js';
10+
import fixtures from '../common/fixtures.js';
11+
12+
skipIfNoWatchModeSignals();
13+
14+
tmpdir.refresh();
15+
const indexPath = tmpdir.resolve('kill-signal-for-watch.js');
16+
const indexContents = fixtures.readSync('kill-signal-for-watch.js', 'utf8');
17+
writeFileSync(indexPath, indexContents);
18+
19+
const child = spawn(
20+
process.execPath,
21+
['--watch', '--watch-kill-signal', 'SIGINT', indexPath],
22+
{
23+
cwd: tmpdir.path,
24+
stdio: ['inherit', 'pipe', 'inherit', 'ipc'],
25+
}
26+
);
27+
28+
let stdout = '';
29+
child.stdout.on('data', (data) => {
30+
stdout += `${data}`;
31+
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
32+
child.kill();
33+
}
34+
});
35+
36+
child.on('message', (msg) => {
37+
if (msg === 'script ready') {
38+
writeFileSync(indexPath, indexContents);
39+
}
40+
});
41+
42+
await once(child, 'exit');
43+
44+
assert.match(stdout, /__SIGINT received__/);
45+
assert.doesNotMatch(stdout, /__SIGTERM received__/);

0 commit comments

Comments
 (0)