result.js
This file
Path
test/return/result.js
152 lines · 4.7 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import process from 'node:process';TweaksSindre Sorhusbefore adoption698a1b8
lines 3–4why, one step back3import test from 'node:test';4import {assertThrows, assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 5–7why, one step back5import {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 back8/* 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 back910const isWindows = process.platform === 'win32';1112setFixtureDirectory();13TweaksSindre Sorhusbefore adoption698a1b8
line 14why, one step back14const testSuccessShape = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 15why, one step back15 const result = await execaMethod('empty.js', {...fullStdio, all: true});TweaksSindre Sorhusbefore adoption698a1b8
line 16why, one step back16 assert.deepEqual(Reflect.ownKeys(result), [100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 17–23why, one step back17 'command',18 'escapedCommand',19 'cwd',20 'durationMs',21 'failed',22 'timedOut',23 'isCanceled',Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 24why, one step back24 'isGracefullyCanceled',100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 25–26why, one step back25 'isTerminated',26 'isMaxBuffer',Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 27why, one step back27 'isForcefullyTerminated',100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 28–32why, one step back28 'exitCode',29 'stdout',30 'stderr',31 'all',32 'stdio',Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 33why, one step back33 'ipcOutput',100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 34–37why, one step back34 'pipedFrom',35 ]);36};37TweaksSindre Sorhusbefore adoption698a1b8
lines 38–39why, one step back38test('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 back40TweaksSindre Sorhusbefore adoption698a1b8
line 41why, one step back41const testErrorShape = async execaMethod => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 42why, one step back42 const error = await execaMethod('fail.js', {...fullStdio, all: true, reject: false});TweaksSindre Sorhusbefore adoption698a1b8
lines 43–44why, one step back43 assert.equal(error.exitCode, 2);44 assert.deepEqual(Reflect.ownKeys(error), [100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 45–54why, one step back45 '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 back55 'isGracefullyCanceled',100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 56–57why, one step back56 'isTerminated',57 'isMaxBuffer',Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 58why, one step back58 'isForcefullyTerminated',100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 59–63why, one step back59 'exitCode',60 'stdout',61 'stderr',62 'all',63 'stdio',Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 64why, one step back64 'ipcOutput',100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 65–68why, one step back65 'pipedFrom',66 ]);67};68TweaksSindre Sorhusbefore adoption698a1b8
lines 69–70why, one step back69test('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 back71TweaksSindre Sorhusbefore adoption698a1b8
line 72why, one step back72test('failed is false on success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 73why, one step back73 const {failed} = await execa('noop.js', ['foo']);TweaksSindre Sorhusbefore adoption698a1b8
line 74why, one step back74 assert.equal(failed, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 75–76why, one step back75});76TweaksSindre Sorhusbefore adoption698a1b8
lines 77–79why, one step back77test('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 back80});81TweaksSindre Sorhusbefore adoption698a1b8
line 82why, one step back82test('error.isTerminated is true if subprocess was killed directly', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 83–86why, one step back83 const subprocess = execa('forever.js', {killSignal: 'SIGINT'});8485 subprocess.kill();86TweaksSindre Sorhusbefore adoption698a1b8
lines 87–92why, one step back87 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 back93});94TweaksSindre Sorhusbefore adoption698a1b8
line 95why, one step back95test('error.isTerminated is true if subprocess was killed indirectly', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 96–101why, one step back96 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 back102 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 back105 } else {TweaksSindre Sorhusbefore adoption698a1b8
lines 106–108why, one step back106 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 back109 }110});111TweaksSindre Sorhusbefore adoption698a1b8
line 112why, one step back112test('result.isTerminated is false if not killed', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 113why, one step back113 const {isTerminated} = await execa('noop.js');TweaksSindre Sorhusbefore adoption698a1b8
line 114why, one step back114 assert.equal(isTerminated, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 115–116why, one step back115});116TweaksSindre Sorhusbefore adoption698a1b8
line 117why, one step back117test('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 back118 const subprocess = execa('noop.js');119 subprocess.kill(0);TweaksSindre Sorhusbefore adoption698a1b8
line 120why, one step back120 assert.equal(subprocess.nodeChildProcess.killed, true);Fix CI tests related to `.kill(0)` (#1212)ehmickybefore adoption23ec6f0
line 121why, one step back121 const {isTerminated} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 122why, one step back122 assert.equal(isTerminated, false);Fix CI tests related to `.kill(0)` (#1212)ehmickybefore adoption23ec6f0
line 123why, one step back123});100% test coverage (#1018)ehmickybefore adoption9f65b86
line 124why, one step back124TweaksSindre Sorhusbefore adoption698a1b8
line 125why, one step back125test('result.isTerminated is false if not killed, in sync mode', () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 126why, one step back126 const {isTerminated} = execaSync('noop.js');TweaksSindre Sorhusbefore adoption698a1b8
line 127why, one step back127 assert.equal(isTerminated, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 128–129why, one step back128});129TweaksSindre Sorhusbefore adoption698a1b8
lines 130–132why, one step back130test('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 back133});134TweaksSindre Sorhusbefore adoption698a1b8
lines 135–136why, one step back135test('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 back137 execaSync('wrong command');138 });TweaksSindre Sorhusbefore adoption698a1b8
line 139why, one step back139 assert.equal(isTerminated, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 140–141why, one step back140});141TweaksSindre Sorhusbefore adoption698a1b8
line 142why, one step back142test('error.code is undefined on success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 143why, one step back143 const {code} = await execa('noop.js');TweaksSindre Sorhusbefore adoption698a1b8
line 144why, one step back144 assert.equal(code, undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 145–146why, one step back145});146TweaksSindre Sorhusbefore adoption698a1b8
lines 147–149why, one step back147test('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 back150});TweaksSindre Sorhusbefore adoption698a1b8
lines 151–152why, one step back151152/* eslint-enable node-test/no-conditional-assertion */