A live process to stand in for a daemon; signals reach it, never the test.
()
| 147 | |
| 148 | /** A live process to stand in for a daemon; signals reach it, never the test. */ |
| 149 | function startDetachedProcess(): number { |
| 150 | const source = [ |
| 151 | "const { spawn } = require('child_process');", |
| 152 | "const child = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { detached: true, stdio: 'ignore' });", |
| 153 | 'child.unref();', |
| 154 | 'console.log(child.pid);', |
| 155 | ].join(' '); |
| 156 | const pid = Number(execFileSync(process.execPath, ['-e', source], { encoding: 'utf8' }).trim()); |
| 157 | if (!Number.isInteger(pid) || pid <= 0) throw new Error('could not start daemon fixture'); |
| 158 | return pid; |
| 159 | } |
| 160 | |
| 161 | async function deadPid(): Promise<number> { |
| 162 | const child = spawn(process.execPath, ['-e', 'process.exit(0)']); |
no test coverage detected