timeout.js
This file
Path
test/exit/timeout.js
76 lines · 2.7 KiB · JavaScript
Last changed by
Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–6why, one step back1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';45setFixtureDir();6Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 7why, one step back7test('timeout kills the subprocess if it times out', async t => {Split files (#837)ehmickybefore adoption672c2d7
lines 8–16why, one step back8 const {isTerminated, signal, timedOut, originalMessage, shortMessage, message} = await t.throwsAsync(execa('forever.js', {timeout: 1}));9 t.true(isTerminated);10 t.is(signal, 'SIGTERM');11 t.true(timedOut);12 t.is(originalMessage, '');13 t.is(shortMessage, 'Command timed out after 1 milliseconds: forever.js');14 t.is(message, shortMessage);15});16Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 17why, one step back17test('timeout kills the subprocess if it times out, in sync mode', async t => {Split files (#837)ehmickybefore adoption672c2d7
lines 18–28why, one step back18 const {isTerminated, signal, timedOut, originalMessage, shortMessage, message} = await t.throws(() => {19 execaSync('node', ['forever.js'], {timeout: 1, cwd: FIXTURES_DIR});20 });21 t.true(isTerminated);22 t.is(signal, 'SIGTERM');23 t.true(timedOut);24 t.is(originalMessage, 'spawnSync node ETIMEDOUT');25 t.is(shortMessage, `Command timed out after 1 milliseconds: node forever.js\n${originalMessage}`);26 t.is(message, shortMessage);27});28Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 29why, one step back29test('timeout does not kill the subprocess if it does not time out', async t => {Split files (#837)ehmickybefore adoption672c2d7
lines 30–69why, one step back30 const {timedOut} = await execa('delay.js', ['500'], {timeout: 1e8});31 t.false(timedOut);32});3334test('timeout uses killSignal', async t => {35 const {isTerminated, signal, timedOut} = await t.throwsAsync(execa('forever.js', {timeout: 1, killSignal: 'SIGINT'}));36 t.true(isTerminated);37 t.is(signal, 'SIGINT');38 t.true(timedOut);39});4041const INVALID_TIMEOUT_REGEXP = /`timeout` option to be a non-negative integer/;4243const testTimeoutValidation = (t, timeout, execaMethod) => {44 t.throws(() => {45 execaMethod('empty.js', {timeout});46 }, {message: INVALID_TIMEOUT_REGEXP});47};4849test('timeout must not be negative', testTimeoutValidation, -1, execa);50test('timeout must be an integer', testTimeoutValidation, false, execa);51test('timeout must not be negative - sync', testTimeoutValidation, -1, execaSync);52test('timeout must be an integer - sync', testTimeoutValidation, false, execaSync);5354test('timedOut is false if timeout is undefined', async t => {55 const {timedOut} = await execa('noop.js');56 t.false(timedOut);57});5859test('timedOut is false if timeout is 0', async t => {60 const {timedOut} = await execa('noop.js', {timeout: 0});61 t.false(timedOut);62});6364test('timedOut is false if timeout is undefined and exit code is 0 in sync mode', t => {65 const {timedOut} = execaSync('noop.js');66 t.false(timedOut);67});6869test('timedOut is true if the timeout happened after a different error occurred', async t => {Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 70why, one step back70 const subprocess = execa('forever.js', {timeout: 1e3});Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 71–74why, one step back71 const cause = new Error('test');72 subprocess.emit('error', cause);73 const error = await t.throwsAsync(subprocess);74 t.is(error.cause, cause);Split files (#837)ehmickybefore adoption672c2d7
lines 75–76why, one step back75 t.true(error.timedOut);76});