test.beforeEach(t => { let root = document.getElementById('root'); if (!root) { root = document.createElement('div'); root.id = 'root'; document.body.appendChild(root); } t.context.root = root; });
test('kill("SIGKILL") should terminate cleanly', async t => { const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']}); await pEvent(subprocess, 'message'); subprocess.kill('SIGKILL'); const {signal} = await t.throwsAsync(subprocess); t.is(signal, 'SIGKILL'); });
test('result.killed is false on process error, in sync mode', t => { const {killed} = t.throws(() => { execa.sync('wrong command'); }); t.false(killed); });
test('throw in finally bubbles up on error', async t => { const {message} = await t.throwsAsync(execa('exit', ['2']).finally(() => { throw new Error('called'); })); t.is(message, 'called'); });
test('error.isCanceled is true when cancel method is used', async t => { const subprocess = execa('noop'); subprocess.cancel(); const {isCanceled} = await t.throwsAsync(subprocess); t.true(isCanceled); });
test('`forceKillAfterTimeout` should not be negative', t => { t.throws(() => { execa('noop').kill('SIGTERM', {forceKillAfterTimeout: -1}); }, {instanceOf: TypeError, message: /non-negative integer/}); });
test('timeout must not be negative', async t => { await t.throws(() => { execa('noop', {timeout: -1}); }, INVALID_TIMEOUT_REGEXP); });
test.beforeEach(t => { let root = document.getElementById('root'); if (!root) { root = document.createElement('div'); root.id = 'root'; document.body.appendChild(root); } t.context.root = root; });
test('`forceKillAfterTimeout: number` should kill after a timeout', async t => { const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']}); await pEvent(subprocess, 'message'); subprocess.kill('SIGTERM', {forceKillAfterTimeout: 50}); const {signal} = await t.throwsAsync(subprocess); t.is(signal, 'SIGKILL'); });
test('`forceKillAfterTimeout: true` should kill after a timeout', async t => { const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']}); await pEvent(subprocess, 'message'); subprocess.kill('SIGTERM', {forceKillAfterTimeout: true}); const {signal} = await t.throwsAsync(subprocess); t.is(signal, 'SIGKILL'); });