timeout.js
This file
Path
test/terminate/timeout.js
97 lines · 4.2 KiB · JavaScript
Last changed by
Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–3why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';3import {assertThrows, assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–8why, one step back4import {execa, execaSync} from '../../index.js';5import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';67setFixtureDirectory();8TweaksSindre Sorhusbefore adoption698a1b8
lines 9–16why, one step back9test('timeout kills the subprocess if it times out', async () => {10 const {isTerminated, signal, timedOut, originalMessage, shortMessage, message} = await assertRejects(execa('forever.js', {timeout: 1}));11 assert.equal(isTerminated, true);12 assert.equal(signal, 'SIGTERM');13 assert.equal(timedOut, true);14 assert.equal(originalMessage, undefined);15 assert.equal(shortMessage, 'Command timed out after 1 milliseconds: forever.js');16 assert.equal(message, shortMessage);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 17–18why, one step back17});18TweaksSindre Sorhusbefore adoption698a1b8
lines 19–20why, one step back19test('timeout kills the subprocess if it times out, in sync mode', async () => {20 const {isTerminated, signal, timedOut, originalMessage, shortMessage, message} = await assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 21–22why, one step back21 execaSync('node', ['forever.js'], {timeout: 1, cwd: FIXTURES_DIRECTORY});22 });TweaksSindre Sorhusbefore adoption698a1b8
lines 23–25why, one step back23 assert.equal(isTerminated, true);24 assert.equal(signal, 'SIGTERM');25 assert.equal(timedOut, true);Fix `preferLocal` argument escaping edge-case on Windows (#1259)Sindre Sorhusbefore adoptione771733
line 26why, one step back26 // On Windows, the command is spawned using the absolute path resolved via `PATHEXT`, so it appears in Node.js' own error messageTweaksSindre Sorhusbefore adoption698a1b8
lines 27–29why, one step back27 assert.match(originalMessage, /^spawnSync .*node(?:\.[A-Za-z]+)? ETIMEDOUT$/);28 assert.equal(shortMessage, `Command timed out after 1 milliseconds: node forever.js\n${originalMessage}`);29 assert.equal(message, shortMessage);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 30–31why, one step back30});31TweaksSindre Sorhusbefore adoption698a1b8
line 32why, one step back32test('timeout does not kill the subprocess if it does not time out', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 33why, one step back33 const {timedOut} = await execa('delay.js', ['500'], {timeout: 1e8});TweaksSindre Sorhusbefore adoption698a1b8
line 34why, one step back34 assert.equal(timedOut, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 35–36why, one step back35});36TweaksSindre Sorhusbefore adoption698a1b8
lines 37–41why, one step back37test('timeout uses killSignal', async () => {38 const {isTerminated, signal, timedOut} = await assertRejects(execa('forever.js', {timeout: 1, killSignal: 'SIGINT'}));39 assert.equal(isTerminated, true);40 assert.equal(signal, 'SIGINT');41 assert.equal(timedOut, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 42–45why, one step back42});4344const INVALID_TIMEOUT_REGEXP = /`timeout` option to be a non-negative integer/;45TweaksSindre Sorhusbefore adoption698a1b8
lines 46–47why, one step back46const testTimeoutValidation = (timeout, execaMethod) => {47 assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 48–51why, one step back48 execaMethod('empty.js', {timeout});49 }, {message: INVALID_TIMEOUT_REGEXP});50};51Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
lines 52–53why, one step back52test('timeout must be an integer', () => testTimeoutValidation(100.5, execa));53test('timeout must be an integer - sync', () => testTimeoutValidation(100.5, execaSync));TweaksSindre Sorhusbefore adoption698a1b8
line 54why, one step back54test('timeout must not be negative', () => testTimeoutValidation(-1, execa));Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
line 55why, one step back55test('timeout must be a number', () => testTimeoutValidation(false, execa));TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56test('timeout must not be negative - sync', () => testTimeoutValidation(-1, execaSync));Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
lines 57–60why, one step back57test('timeout must be a number - sync', () => testTimeoutValidation(false, execaSync));58// Larger delays make timers fire right away59test('timeout must not be larger than the maximum timer delay', () => testTimeoutValidation(2 ** 31, execa));60test('timeout must not be larger than the maximum timer delay - sync', () => testTimeoutValidation(2 ** 31, execaSync));Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
lines 61–65why, one step back61test('timeout must not be null', () => {62 assertThrows(() => {63 execa('empty.js', {timeout: null});64 }, {message: /got `null` \(null\)/});65});Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
lines 66–73why, one step back6667const testMaxTimeout = async execaMethod => {68 const {timedOut} = await execaMethod('noop.js', {timeout: (2 ** 31) - 1});69 assert.equal(timedOut, false);70};7172test('timeout can be the maximum timer delay', () => testMaxTimeout(execa));73test('timeout can be the maximum timer delay - sync', () => testMaxTimeout(execaSync));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 74why, one step back74TweaksSindre Sorhusbefore adoption698a1b8
line 75why, one step back75test('timedOut is false if timeout is undefined', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 76why, one step back76 const {timedOut} = await execa('noop.js');TweaksSindre Sorhusbefore adoption698a1b8
line 77why, one step back77 assert.equal(timedOut, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 78–79why, one step back78});79TweaksSindre Sorhusbefore adoption698a1b8
line 80why, one step back80test('timedOut is false if timeout is 0', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 81why, one step back81 const {timedOut} = await execa('noop.js', {timeout: 0});TweaksSindre Sorhusbefore adoption698a1b8
line 82why, one step back82 assert.equal(timedOut, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 83–84why, one step back83});84TweaksSindre Sorhusbefore adoption698a1b8
line 85why, one step back85test('timedOut is false if timeout is undefined and exit code is 0 in sync mode', () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 86why, one step back86 const {timedOut} = execaSync('noop.js');TweaksSindre Sorhusbefore adoption698a1b8
line 87why, one step back87 assert.equal(timedOut, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 88–89why, one step back88});89TweaksSindre Sorhusbefore adoption698a1b8
line 90why, one step back90test('timedOut is false if the timeout happened after a different error occurred', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 91–92why, one step back91 const subprocess = execa('forever.js', {timeout: 1e3});92 const cause = new Error('test');Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 93why, one step back93 subprocess.nodeChildProcess.emit('error', cause);TweaksSindre Sorhusbefore adoption698a1b8
lines 94–96why, one step back94 const error = await assertRejects(subprocess);95 assert.equal(error.cause, cause);96 assert.equal(error.timedOut, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 97why, one step back97});