Skip to content
Myr

result.js

This file

Path

test/return/result.js

152 lines · 4.7 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 {assertThrows, assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 5–7why, one step back
5import {execa, execaSync} from '../../index.js';
6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {fullStdio} from '../helpers/stdio.js';

TweaksSindre Sorhusbefore adoption698a1b8

line 8why, one step back
8/* eslint-disable node-test/no-conditional-assertion -- shared helper functions are called from conditional paths on purpose */

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 9–13why, one step back
9
10const isWindows = process.platform === 'win32';1112setFixtureDirectory();13

TweaksSindre Sorhusbefore adoption698a1b8

line 14why, one step back
14const testSuccessShape = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 15why, one step back
15 const result = await execaMethod('empty.js', {...fullStdio, all: true});

TweaksSindre Sorhusbefore adoption698a1b8

line 16why, one step back
16 assert.deepEqual(Reflect.ownKeys(result), [

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 17–23why, one step back
17 'command',
18 'escapedCommand',19 'cwd',20 'durationMs',21 'failed',22 'timedOut',23 'isCanceled',

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 24why, one step back
24 'isGracefullyCanceled',

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 25–26why, one step back
25 'isTerminated',
26 'isMaxBuffer',

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

line 27why, one step back
27 'isForcefullyTerminated',

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 28–32why, one step back
28 'exitCode',
29 'stdout',30 'stderr',31 'all',32 'stdio',

Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360

line 33why, one step back
33 'ipcOutput',

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 34–37why, one step back
34 'pipedFrom',
35 ]);36};37

TweaksSindre Sorhusbefore adoption698a1b8

lines 38–39why, one step back
38test('Return value properties are not missing and are ordered', () => testSuccessShape(execa));
39test('Return value properties are not missing and are ordered, sync', () => testSuccessShape(execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 40why, one step back
40

TweaksSindre Sorhusbefore adoption698a1b8

line 41why, one step back
41const testErrorShape = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 42why, one step back
42 const error = await execaMethod('fail.js', {...fullStdio, all: true, reject: false});

TweaksSindre Sorhusbefore adoption698a1b8

lines 43–44why, one step back
43 assert.equal(error.exitCode, 2);
44 assert.deepEqual(Reflect.ownKeys(error), [

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 45–54why, one step back
45 'stack',
46 'message',47 'shortMessage',48 'command',49 'escapedCommand',50 'cwd',51 'durationMs',52 'failed',53 'timedOut',54 'isCanceled',

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 55why, one step back
55 'isGracefullyCanceled',

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 56–57why, one step back
56 'isTerminated',
57 'isMaxBuffer',

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

line 58why, one step back
58 'isForcefullyTerminated',

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 59–63why, one step back
59 'exitCode',
60 'stdout',61 'stderr',62 'all',63 'stdio',

Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360

line 64why, one step back
64 'ipcOutput',

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 65–68why, one step back
65 'pipedFrom',
66 ]);67};68

TweaksSindre Sorhusbefore adoption698a1b8

lines 69–70why, one step back
69test('Error properties are not missing and are ordered', () => testErrorShape(execa));
70test('Error properties are not missing and are ordered, sync', () => testErrorShape(execaSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 71why, one step back
71

TweaksSindre Sorhusbefore adoption698a1b8

line 72why, one step back
72test('failed is false on success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 74why, one step back
74 assert.equal(failed, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 77–79why, one step back
77test('failed is true on failure', async () => {
78 const {failed} = await assertRejects(execa('fail.js'));79 assert.equal(failed, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 82why, one step back
82test('error.isTerminated is true if subprocess was killed directly', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 83–86why, one step back
83 const subprocess = execa('forever.js', {killSignal: 'SIGINT'});
8485 subprocess.kill();86

TweaksSindre Sorhusbefore adoption698a1b8

lines 87–92why, one step back
87 const {isTerminated, signal, originalMessage, message, shortMessage} = await assertRejects(subprocess, {message: /was killed with SIGINT/});
88 assert.equal(isTerminated, true);89 assert.equal(signal, 'SIGINT');90 assert.equal(originalMessage, undefined);91 assert.equal(shortMessage, 'Command was killed with SIGINT (User interruption with CTRL-C): forever.js');92 assert.equal(message, shortMessage);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 93–94why, one step back
93});
94

TweaksSindre Sorhusbefore adoption698a1b8

line 95why, one step back
95test('error.isTerminated is true if subprocess was killed indirectly', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 96–101why, one step back
96 const subprocess = execa('forever.js', {killSignal: 'SIGHUP'});
9798 process.kill(subprocess.pid, 'SIGINT');99100 // `subprocess.kill()` is emulated by Node.js on Windows101 if (isWindows) {

TweaksSindre Sorhusbefore adoption698a1b8

lines 102–104why, one step back
102 const {isTerminated, signal} = await assertRejects(subprocess, {message: /failed with exit code 1/});
103 assert.equal(isTerminated, false);104 assert.equal(signal, undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 105why, one step back
105 } else {

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 109–111why, one step back
109 }
110});111

TweaksSindre Sorhusbefore adoption698a1b8

line 112why, one step back
112test('result.isTerminated is false if not killed', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 114why, one step back
114 assert.equal(isTerminated, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 115–116why, one step back
115});
116

TweaksSindre Sorhusbefore adoption698a1b8

line 117why, one step back
117test('result.isTerminated is false if not killed and subprocess.kill() was called', async () => {

Fix CI tests related to `.kill(0)` (#1212)ehmickybefore adoption23ec6f0

lines 118–119why, one step back
118 const subprocess = execa('noop.js');
119 subprocess.kill(0);

TweaksSindre Sorhusbefore adoption698a1b8

line 120why, one step back
120 assert.equal(subprocess.nodeChildProcess.killed, true);

Fix CI tests related to `.kill(0)` (#1212)ehmickybefore adoption23ec6f0

line 121why, one step back
121 const {isTerminated} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 122why, one step back
122 assert.equal(isTerminated, false);

Fix CI tests related to `.kill(0)` (#1212)ehmickybefore adoption23ec6f0

line 123why, one step back
123});

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 124why, one step back
124

TweaksSindre Sorhusbefore adoption698a1b8

line 125why, one step back
125test('result.isTerminated is false if not killed, in sync mode', () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 126why, one step back
126 const {isTerminated} = execaSync('noop.js');

TweaksSindre Sorhusbefore adoption698a1b8

line 127why, one step back
127 assert.equal(isTerminated, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 128–129why, one step back
128});
129

TweaksSindre Sorhusbefore adoption698a1b8

lines 130–132why, one step back
130test('result.isTerminated is false on subprocess error', async () => {
131 const {isTerminated} = await assertRejects(execa('wrong command'));132 assert.equal(isTerminated, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 133–134why, one step back
133});
134

TweaksSindre Sorhusbefore adoption698a1b8

lines 135–136why, one step back
135test('result.isTerminated is false on subprocess error, in sync mode', () => {
136 const {isTerminated} = assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 137–138why, one step back
137 execaSync('wrong command');
138 });

TweaksSindre Sorhusbefore adoption698a1b8

line 139why, one step back
139 assert.equal(isTerminated, false);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 140–141why, one step back
140});
141

TweaksSindre Sorhusbefore adoption698a1b8

line 142why, one step back
142test('error.code is undefined on success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 144why, one step back
144 assert.equal(code, undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 145–146why, one step back
145});
146

TweaksSindre Sorhusbefore adoption698a1b8

lines 147–149why, one step back
147test('error.code is defined on failure if applicable', async () => {
148 const {code} = await assertRejects(execa('noop.js', {uid: true}));149 assert.equal(code, 'ERR_INVALID_ARG_TYPE');

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 150why, one step back
150});

TweaksSindre Sorhusbefore adoption698a1b8

lines 151–152why, one step back
151
152/* eslint-enable node-test/no-conditional-assertion */