Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions 16 test/common/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const common = require('./index.js');

exports.skipIfNoWatchModeSignals = function() {
if (common.isWindows) {
common.skip('no signals on Windows');
}

if (common.isIBMi) {
common.skip('IBMi does not support `fs.watch()`');
}

if (common.isAIX) {
common.skip('folder watch capability is limited in AIX.');
}
};
4 changes: 4 additions & 0 deletions 4 test/fixtures/kill-signal-for-watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
process.on('SIGTERM', () => { console.log('__SIGTERM received__'); process.exit(); });
process.on('SIGINT', () => { console.log('__SIGINT received__'); process.exit(); });
process.send('script ready');
setTimeout(() => {}, 100_000);
131 changes: 0 additions & 131 deletions 131 test/parallel/test-runner-watch-mode-kill-signal.mjs

This file was deleted.

45 changes: 45 additions & 0 deletions 45 test/parallel/test-watch-mode-kill-signal-default.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Test that the kill signal sent by --watch defaults to SIGTERM.

import '../common/index.mjs';
import assert from 'node:assert';
import { writeFileSync } from 'node:fs';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
import tmpdir from '../common/tmpdir.js';
import fixtures from '../common/fixtures.js';
import { skipIfNoWatchModeSignals } from '../common/watch.js';

skipIfNoWatchModeSignals();

tmpdir.refresh();
const indexPath = tmpdir.resolve('kill-signal-for-watch.js');
const indexContents = fixtures.readSync('kill-signal-for-watch.js', 'utf8');
writeFileSync(indexPath, indexContents);

const child = spawn(
process.execPath,
['--watch', indexPath],
{
cwd: tmpdir.path,
stdio: ['inherit', 'pipe', 'inherit', 'ipc'],
}
);

let stdout = '';
child.stdout.on('data', (data) => {
stdout += `${data}`;
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
child.kill();
}
});

child.on('message', (msg) => {
if (msg === 'script ready') {
writeFileSync(indexPath, indexContents);
}
});

await once(child, 'exit');

assert.match(stdout, /__SIGTERM received__/);
assert.doesNotMatch(stdout, /__SIGINT received__/);
39 changes: 39 additions & 0 deletions 39 test/parallel/test-watch-mode-kill-signal-invalid.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Test that --watch-kill-signal errors when an invalid kill signal is provided.

import '../common/index.mjs';
import assert from 'node:assert';
import { writeFileSync } from 'node:fs';
import { spawn } from 'node:child_process';
import tmpdir from '../common/tmpdir.js';
import fixtures from '../common/fixtures.js';
import { skipIfNoWatchModeSignals } from '../common/watch.js';

skipIfNoWatchModeSignals();

tmpdir.refresh();
const indexPath = tmpdir.resolve('kill-signal-for-watch.js');
const indexContents = fixtures.readSync('kill-signal-for-watch.js', 'utf8');
writeFileSync(indexPath, indexContents);

const currentRun = Promise.withResolvers();
const child = spawn(
process.execPath,
['--watch', '--watch-kill-signal', 'invalid_signal', indexPath],
{
cwd: tmpdir.path,
stdio: ['inherit', 'inherit', 'pipe'],
}
);
let stderr = '';

child.stderr.on('data', (data) => {
stderr += data.toString();
currentRun.resolve();
});

await currentRun.promise;

assert.match(
stderr,
/TypeError \[ERR_UNKNOWN_SIGNAL\]: Unknown signal: invalid_signal/
);
46 changes: 46 additions & 0 deletions 46 test/parallel/test-watch-mode-kill-signal-override.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Test that the kill signal sent by --watch can be overridden to SIGINT
// by using --watch-kill-signal.

import '../common/index.mjs';
import assert from 'node:assert';
import { writeFileSync } from 'node:fs';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
import tmpdir from '../common/tmpdir.js';
import fixtures from '../common/fixtures.js';
import { skipIfNoWatchModeSignals } from '../common/watch.js';

skipIfNoWatchModeSignals();

tmpdir.refresh();
const indexPath = tmpdir.resolve('kill-signal-for-watch.js');
const indexContents = fixtures.readSync('kill-signal-for-watch.js', 'utf8');
writeFileSync(indexPath, indexContents);

const child = spawn(
process.execPath,
['--watch', '--watch-kill-signal', 'SIGINT', indexPath],
{
cwd: tmpdir.path,
stdio: ['inherit', 'pipe', 'inherit', 'ipc'],
}
);

let stdout = '';
child.stdout.on('data', (data) => {
stdout += `${data}`;
if (/__(SIGINT|SIGTERM) received__/.test(stdout)) {
child.kill();
}
});

child.on('message', (msg) => {
if (msg === 'script ready') {
writeFileSync(indexPath, indexContents);
}
});

await once(child, 'exit');

assert.match(stdout, /__SIGINT received__/);
assert.doesNotMatch(stdout, /__SIGTERM received__/);
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.