Skip to content
Myr

exit.js

This file

Path

test/resolve/exit.js

85 lines · 2.8 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 2why, one step back
2import process from 'node:process';

TweaksSindre Sorhusbefore adoption698a1b8

lines 3–4why, one step back
3import test from 'node:test';
4import {assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 5–11why, one step back
5import {execa} from '../../index.js';
6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';78const isWindows = process.platform === 'win32';910setFixtureDirectory();11

TweaksSindre Sorhusbefore adoption698a1b8

line 12why, one step back
12test('exitCode is 0 on success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 13why, one step back
13 const {exitCode} = await execa('noop.js', ['foo']);

TweaksSindre Sorhusbefore adoption698a1b8

line 14why, one step back
14 assert.equal(exitCode, 0);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 15–16why, one step back
15});
16

TweaksSindre Sorhusbefore adoption698a1b8

lines 17–22why, one step back
17const testExitCode = async expectedExitCode => {
18 const {exitCode, originalMessage, shortMessage, message} = await assertRejects(execa('exit.js', [`${expectedExitCode}`]));19 assert.equal(exitCode, expectedExitCode);20 assert.equal(originalMessage, undefined);21 assert.equal(shortMessage, `Command failed with exit code ${expectedExitCode}: exit.js ${expectedExitCode}`);22 assert.equal(message, shortMessage);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 23–24why, one step back
23};
24

TweaksSindre Sorhusbefore adoption698a1b8

lines 25–27why, one step back
25test('exitCode is 2', () => testExitCode(2));
26test('exitCode is 3', () => testExitCode(3));27test('exitCode is 4', () => testExitCode(4));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 28–29why, one step back
28
29if (!isWindows) {

TweaksSindre Sorhusbefore adoption698a1b8

line 30why, one step back
30 test('error.signal is SIGINT', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 31–34why, one step back
31 const subprocess = execa('forever.js');
3233 process.kill(subprocess.pid, 'SIGINT');34

TweaksSindre Sorhusbefore adoption698a1b8

lines 35–36why, one step back
35 const {signal} = await assertRejects(subprocess, {message: /was killed with SIGINT/});
36 assert.equal(signal, 'SIGINT');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 37–38why, one step back
37 });
38

TweaksSindre Sorhusbefore adoption698a1b8

line 39why, one step back
39 test('error.signalDescription is defined', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 40–43why, one step back
40 const subprocess = execa('forever.js');
4142 process.kill(subprocess.pid, 'SIGINT');43

TweaksSindre Sorhusbefore adoption698a1b8

lines 44–45why, one step back
44 const {signalDescription} = await assertRejects(subprocess, {message: /User interruption with CTRL-C/});
45 assert.equal(signalDescription, 'User interruption with CTRL-C');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 46–47why, one step back
46 });
47

TweaksSindre Sorhusbefore adoption698a1b8

line 48why, one step back
48 test('error.signal is SIGTERM', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 49–52why, one step back
49 const subprocess = execa('forever.js');
5051 process.kill(subprocess.pid, 'SIGTERM');52

TweaksSindre Sorhusbefore adoption698a1b8

lines 53–54why, one step back
53 const {signal} = await assertRejects(subprocess, {message: /was killed with SIGTERM/});
54 assert.equal(signal, 'SIGTERM');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 55–56why, one step back
55 });
56

TweaksSindre Sorhusbefore adoption698a1b8

lines 57–59why, one step back
57 test('error.signal uses killSignal', async () => {
58 const {signal} = await assertRejects(execa('forever.js', {killSignal: 'SIGINT', timeout: 1, message: /timed out after/}));59 assert.equal(signal, 'SIGINT');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 60–61why, one step back
60 });
61

TweaksSindre Sorhusbefore adoption698a1b8

line 62why, one step back
62 test('exitCode is undefined on signal termination', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 63–66why, one step back
63 const subprocess = execa('forever.js');
6465 process.kill(subprocess.pid);66

TweaksSindre Sorhusbefore adoption698a1b8

lines 67–68why, one step back
67 const {exitCode} = await assertRejects(subprocess);
68 assert.equal(exitCode, undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 69–71why, one step back
69 });
70}71

TweaksSindre Sorhusbefore adoption698a1b8

line 72why, one step back
72test('result.signal is undefined for successful execution', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 73why, one step back
73 const {signal} = await execa('noop.js');

TweaksSindre Sorhusbefore adoption698a1b8

line 74why, one step back
74 assert.equal(signal, undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 75–76why, one step back
75});
76

TweaksSindre Sorhusbefore adoption698a1b8

lines 77–79why, one step back
77test('result.signal is undefined if subprocess failed, but was not killed', async () => {
78 const {signal} = await assertRejects(execa('fail.js'));79 assert.equal(signal, undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 80–81why, one step back
80});
81

TweaksSindre Sorhusbefore adoption698a1b8

line 82why, one step back
82test('result.signalDescription is undefined for successful execution', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 83why, one step back
83 const {signalDescription} = await execa('noop.js');

TweaksSindre Sorhusbefore adoption698a1b8

line 84why, one step back
84 assert.equal(signalDescription, undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 85why, one step back
85});