Skip to content
Myr

code.js

This file

Path

test/exit/code.js

85 lines · 2.6 KiB · JavaScript

Last changed by

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–76why, one step back
1import process from 'node:process';
2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';56const isWindows = process.platform === 'win32';78setFixtureDir();910test('exitCode is 0 on success', async t => {11 const {exitCode} = await execa('noop.js', ['foo']);12 t.is(exitCode, 0);13});1415const testExitCode = async (t, expectedExitCode) => {16 const {exitCode, originalMessage, shortMessage, message} = await t.throwsAsync(17 execa('exit.js', [`${expectedExitCode}`]),18 );19 t.is(exitCode, expectedExitCode);20 t.is(originalMessage, '');21 t.is(shortMessage, `Command failed with exit code ${expectedExitCode}: exit.js ${expectedExitCode}`);22 t.is(message, shortMessage);23};2425test('exitCode is 2', testExitCode, 2);26test('exitCode is 3', testExitCode, 3);27test('exitCode is 4', testExitCode, 4);2829if (!isWindows) {30 test('error.signal is SIGINT', async t => {31 const subprocess = execa('forever.js');3233 process.kill(subprocess.pid, 'SIGINT');3435 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});36 t.is(signal, 'SIGINT');37 });3839 test('error.signalDescription is defined', async t => {40 const subprocess = execa('forever.js');4142 process.kill(subprocess.pid, 'SIGINT');4344 const {signalDescription} = await t.throwsAsync(subprocess, {message: /User interruption with CTRL-C/});45 t.is(signalDescription, 'User interruption with CTRL-C');46 });4748 test('error.signal is SIGTERM', async t => {49 const subprocess = execa('forever.js');5051 process.kill(subprocess.pid, 'SIGTERM');5253 const {signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGTERM/});54 t.is(signal, 'SIGTERM');55 });5657 test('error.signal uses killSignal', async t => {58 const {signal} = await t.throwsAsync(execa('forever.js', {killSignal: 'SIGINT', timeout: 1, message: /timed out after/}));59 t.is(signal, 'SIGINT');60 });6162 test('exitCode is undefined on signal termination', async t => {63 const subprocess = execa('forever.js');6465 process.kill(subprocess.pid);6667 const {exitCode} = await t.throwsAsync(subprocess);68 t.is(exitCode, undefined);69 });70}7172test('result.signal is undefined for successful execution', async t => {73 const {signal} = await execa('noop.js');74 t.is(signal, undefined);75});76

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 77why, one step back
77test('result.signal is undefined if subprocess failed, but was not killed', async t => {

Split files (#837)ehmickybefore adoption672c2d7

lines 78–85why, one step back
78 const {signal} = await t.throwsAsync(execa('fail.js'));
79 t.is(signal, undefined);80});8182test('result.signalDescription is undefined for successful execution', async t => {83 const {signalDescription} = await execa('noop.js');84 t.is(signalDescription, undefined);85});