import { spawn } from 'child_process' import t from '../../lib/eltro.mjs' import assert from '../../lib/assert.mjs' import kill from '../../lib/kill.mjs' t.describe('kill', function() { let worker t.afterEach(function() { if (worker?.pid && !worker.killed) { worker.kill() } }) t.test('should kill process correctly', function(done) { worker = spawn('node', ['./test/kill/runner.mjs']) assert.ok(worker.pid) worker.on('exit', done.finish(function(code, signal) { assert.ok(code || signal) })) kill(worker.pid) }) t.test('should succeed in killing tree', async function() { worker = spawn('node', ['./test/kill/runner.mjs']) assert.ok(worker.pid) // Give it some time to start await new Promise(res => { worker.stdout.on('data', function(data) { if (data.toString().indexOf('secondary') >= 0) res() }) }) return kill(worker.pid).then(function(pids) { assert.strictEqual(pids.size, 2) }) }) })