()
| 76 | } |
| 77 | |
| 78 | function createChildBackedChannel(): { channel: unknown } { |
| 79 | const child = spawn(process.execPath, [ |
| 80 | '-e', |
| 81 | [ |
| 82 | "process.on('SIGTERM', () => {", |
| 83 | " console.log('cleanup done');", |
| 84 | ' process.exit(42);', |
| 85 | '});', |
| 86 | "console.log('ready');", |
| 87 | 'setInterval(() => {}, 1000);', |
| 88 | ].join('\n'), |
| 89 | ]); |
| 90 | |
| 91 | const stdout = new PassThrough(); |
| 92 | child.stdout.pipe(stdout); |
| 93 | |
| 94 | const channel = Object.assign(stdout, { |
| 95 | stderr: child.stderr, |
| 96 | signal(name: string): void { |
| 97 | child.kill(`SIG${name}` as NodeJS.Signals); |
| 98 | }, |
| 99 | close(): void { |
| 100 | child.kill('SIGTERM'); |
| 101 | }, |
| 102 | on(event: string, listener: (...args: unknown[]) => void): unknown { |
| 103 | if (event === 'exit' || event === 'close') { |
| 104 | child.on(event, listener as (...args: [number | null]) => void); |
| 105 | return channel; |
| 106 | } |
| 107 | return PassThrough.prototype.on.call(stdout, event, listener); |
| 108 | }, |
| 109 | }); |
| 110 | |
| 111 | return { channel }; |
| 112 | } |
| 113 | |
| 114 | describe('SSHProcess.kill()', () => { |
| 115 | test('kill("SIGTERM") sends "TERM" to channel.signal (strips SIG prefix)', async () => { |
no test coverage detected