| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 77189c1 commit f372303
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('./index.js'); | ||
| 3 | + | ||
| 4 | + exports.skipIfNoWatchModeSignals = function() { | ||
| 5 | + if (common.isWindows) { | ||
| 6 | + common.skip('no signals on Windows'); | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + if (common.isIBMi) { | ||
| 10 | + common.skip('IBMi does not support `fs.watch()`'); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + if (common.isAIX) { | ||
| 14 | + common.skip('folder watch capability is limited in AIX.'); | ||
| 15 | + } | ||
| 16 | + }; | ||
| Original file line number | Diff line number | Diff 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); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,45 @@ | |||
| 1 | + // Test that the kill signal sent by --watch defaults to SIGTERM. | ||
| 2 | + | ||
| 3 | + import '../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 | + import { skipIfNoWatchModeSignals } from '../common/watch.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', 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, /__SIGTERM received__/); | ||
| 45 | + assert.doesNotMatch(stdout, /__SIGINT received__/); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,39 @@ | |||
| 1 | + // Test that --watch-kill-signal errors when an invalid kill signal is provided. | ||
| 2 | + | ||
| 3 | + import '../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 | + import { skipIfNoWatchModeSignals } from '../common/watch.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 currentRun = Promise.withResolvers(); | ||
| 19 | + const child = spawn( | ||
| 20 | + process.execPath, | ||
| 21 | + ['--watch', '--watch-kill-signal', 'invalid_signal', indexPath], | ||
| 22 | + { | ||
| 23 | + cwd: tmpdir.path, | ||
| 24 | + stdio: ['inherit', 'inherit', 'pipe'], | ||
| 25 | + } | ||
| 26 | + ); | ||
| 27 | + let stderr = ''; | ||
| 28 | + | ||
| 29 | + child.stderr.on('data', (data) => { | ||
| 30 | + stderr += data.toString(); | ||
| 31 | + currentRun.resolve(); | ||
| 32 | + }); | ||
| 33 | + | ||
| 34 | + await currentRun.promise; | ||
| 35 | + | ||
| 36 | + assert.match( | ||
| 37 | + stderr, | ||
| 38 | + /TypeError \[ERR_UNKNOWN_SIGNAL\]: Unknown signal: invalid_signal/ | ||
| 39 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,46 @@ | |||
| 1 | + // Test that the kill signal sent by --watch can be overridden to SIGINT | ||
| 2 | + // by using --watch-kill-signal. | ||
| 3 | + | ||
| 4 | + import '../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 | + import { skipIfNoWatchModeSignals } from '../common/watch.js'; | ||
| 12 | + | ||
| 13 | + skipIfNoWatchModeSignals(); | ||
| 14 | + | ||
| 15 | + tmpdir.refresh(); | ||
| 16 | + const indexPath = tmpdir.resolve('kill-signal-for-watch.js'); | ||
| 17 | + const indexContents = fixtures.readSync('kill-signal-for-watch.js', 'utf8'); | ||
| 18 | + writeFileSync(indexPath, indexContents); | ||
| 19 | + | ||
| 20 | + const child = spawn( | ||
| 21 | + process.execPath, | ||
| 22 | + ['--watch', '--watch-kill-signal', 'SIGINT', indexPath], | ||
| 23 | + { | ||
| 24 | + cwd: tmpdir.path, | ||
| 25 | + stdio: ['inherit', 'pipe', 'inherit', 'ipc'], | ||
| 26 | + } | ||
| 27 | + ); | ||
| 28 | + | ||
| 29 | + let stdout = ''; | ||
| 30 | + child.stdout.on('data', (data) => { | ||
| 31 | + stdout += `${data}`; | ||
| 32 | + if (/__(SIGINT|SIGTERM) received__/.test(stdout)) { | ||
| 33 | + child.kill(); | ||
| 34 | + } | ||
| 35 | + }); | ||
| 36 | + | ||
| 37 | + child.on('message', (msg) => { | ||
| 38 | + if (msg === 'script ready') { | ||
| 39 | + writeFileSync(indexPath, indexContents); | ||
| 40 | + } | ||
| 41 | + }); | ||
| 42 | + | ||
| 43 | + await once(child, 'exit'); | ||
| 44 | + | ||
| 45 | + assert.match(stdout, /__SIGINT received__/); | ||
| 46 | + assert.doesNotMatch(stdout, /__SIGTERM received__/); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments