Skip to content
Myr

timeout.js

This file

Path

test/terminate/timeout.js

76 lines · 2.8 KiB · JavaScript

Last changed by

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

lines 1–2why, one step back
1import test from 'ava';
2import {execa, execaSync} from '../../index.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 3why, one step back
3import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';

Rename files (#977)ehmickybefore adoption4b2e316

line 4why, one step back
4

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 5why, one step back
5setFixtureDirectory();

Rename files (#977)ehmickybefore adoption4b2e316

lines 6–11why, one step back
6
7test('timeout kills the subprocess if it times out', async t => {8 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);

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

line 12why, one step back
12 t.is(originalMessage, undefined);

Rename files (#977)ehmickybefore adoption4b2e316

lines 13–18why, one step back
13 t.is(shortMessage, 'Command timed out after 1 milliseconds: forever.js');
14 t.is(message, shortMessage);15});1617test('timeout kills the subprocess if it times out, in sync mode', async t => {18 const {isTerminated, signal, timedOut, originalMessage, shortMessage, message} = await t.throws(() => {

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 19why, one step back
19 execaSync('node', ['forever.js'], {timeout: 1, cwd: FIXTURES_DIRECTORY});

Rename files (#977)ehmickybefore adoption4b2e316

lines 20–76why, one step back
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});2829test('timeout does not kill the subprocess if it does not time out', async t => {30 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 => {70 const subprocess = execa('forever.js', {timeout: 1e3});71 const cause = new Error('test');72 subprocess.emit('error', cause);73 const error = await t.throwsAsync(subprocess);74 t.is(error.cause, cause);75 t.true(error.timedOut);76});