|  | 
|  | 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