Skip to content
Myr

exit.js

This file

Path

test/resolve/exit.js

85 lines · 2.6 KiB · JavaScript

Last changed by

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

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

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

Upgrade xo (#980)ehmickybefore adoptionccfa412

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

Rename files (#977)ehmickybefore adoption4b2e316

lines 5–7why, one step back
5
6const isWindows = process.platform === 'win32';7

Upgrade xo (#980)ehmickybefore adoptionccfa412

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

Rename files (#977)ehmickybefore adoption4b2e316

lines 9–19why, one step back
9
10test('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);

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

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

Rename files (#977)ehmickybefore adoption4b2e316

lines 21–85why, one step back
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});7677test('result.signal is undefined if subprocess failed, but was not killed', async t => {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});