Skip to content
Myr

node.js

This file

Path

test/methods/node.js

368 lines · 20.9 KiB · JavaScript

Last changed by

Fix `execaNode()` and the `node` option missing IPC in their typesSindre Sorhusbefore adoption2633abb

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';

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 3–4why, one step back
3import process, {version} from 'node:process';
4import {pathToFileURL} from 'node:url';

TweaksSindre Sorhusbefore adoption698a1b8

line 5why, one step back
5import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 6why, one step back
6import getNode from 'get-node';

TweaksSindre Sorhusbefore adoption698a1b8

line 7why, one step back
7import {assertThrows, assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 8–11why, one step back
8import {execa, execaSync, execaNode} from '../../index.js';
9import {FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';10import {identity, fullStdio} from '../helpers/stdio.js';11import {foobarString} from '../helpers/input.js';

Fix deno node:process execPath compatibility (#1160)CJbefore adoptionf3a1bf3

line 12why, one step back
12import {getDenoNodePath} from '../helpers/file-path.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 13–23why, one step back
13
14process.chdir(FIXTURES_DIRECTORY);1516const runWithNodeOption = (file, commandArguments, options) => Array.isArray(commandArguments)17 ? execa(file, commandArguments, {...options, node: true})18 : execa(file, {...options, node: true});19const runWithNodeOptionSync = (file, commandArguments, options) => Array.isArray(commandArguments)20 ? execaSync(file, commandArguments, {...options, node: true})21 : execaSync(file, {...options, node: true});22const runWithIpc = (file, options) => execa('node', [file], {...options, ipc: true});23

TweaksSindre Sorhusbefore adoption698a1b8

line 24why, one step back
24const testNodeSuccess = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 25why, one step back
25 const {exitCode, stdout} = await execaMethod('noop.js', [foobarString]);

TweaksSindre Sorhusbefore adoption698a1b8

lines 26–27why, one step back
26 assert.equal(exitCode, 0);
27 assert.equal(stdout, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 28–29why, one step back
28};
29

TweaksSindre Sorhusbefore adoption698a1b8

lines 30–32why, one step back
30test('execaNode() succeeds', () => testNodeSuccess(execaNode));
31test('The "node" option succeeds', () => testNodeSuccess(runWithNodeOption));32test('The "node" option succeeds - sync', () => testNodeSuccess(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 33why, one step back
33

TweaksSindre Sorhusbefore adoption698a1b8

line 34why, one step back
34test('execaNode(options) succeeds', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 35why, one step back
35 const {stdout} = await execaNode({stripFinalNewline: false})('noop.js', [foobarString]);

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36 assert.equal(stdout, `${foobarString}\n`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 39why, one step back
39test('execaNode`...` succeeds', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 40why, one step back
40 const {stdout} = await execaNode`noop.js ${foobarString}`;

TweaksSindre Sorhusbefore adoption698a1b8

line 41why, one step back
41 assert.equal(stdout, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 42–43why, one step back
42});
43

TweaksSindre Sorhusbefore adoption698a1b8

line 44why, one step back
44test('execaNode().pipe(execaNode()) succeeds', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 45why, one step back
45 const {stdout} = await execaNode('noop.js').pipe(execaNode('--version'));

TweaksSindre Sorhusbefore adoption698a1b8

line 46why, one step back
46 assert.equal(stdout, version);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 49–50why, one step back
49test('execaNode().pipe(execa()) requires using "node"', async () => {
50 await assertRejects(execaNode('noop.js').pipe(execa('--version')));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 51–52why, one step back
51});
52

TweaksSindre Sorhusbefore adoption698a1b8

lines 53–54why, one step back
53test('execaNode().pipe(...) requires using "node"', async () => {
54 await assertRejects(execaNode('noop.js').pipe('--version'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 57–58why, one step back
57test('execaNode().pipe`...` requires using "node"', async () => {
58 await assertRejects(execaNode('noop.js').pipe`--version`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–62why, one step back
61test('execaNode() cannot set the "node" option to false', () => {
62 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 63–66why, one step back
63 execaNode('empty.js', {node: false});
64 }, {message: /The "node" option cannot be false/});65});66

TweaksSindre Sorhusbefore adoption698a1b8

lines 67–68why, one step back
67const testDoubleNode = (nodePath, execaMethod) => {
68 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 69–72why, one step back
69 execaMethod(nodePath, ['noop.js']);
70 }, {message: /does not need to be "node"/});71};72

TweaksSindre Sorhusbefore adoption698a1b8

lines 73–81why, one step back
73test('Cannot use "node" as binary - execaNode()', () => testDoubleNode('node', execaNode));
74test('Cannot use "node" as binary - "node" option', () => testDoubleNode('node', runWithNodeOption));75test('Cannot use "node" as binary - "node" option sync', () => testDoubleNode('node', runWithNodeOptionSync));76test('Cannot use path to "node" as binary - execaNode()', () => testDoubleNode(process.execPath, execaNode));77test('Cannot use path to "node" as binary - "node" option', () => testDoubleNode(process.execPath, runWithNodeOption));78test('Cannot use path to "node" as binary - "node" option sync', () => testDoubleNode(process.execPath, runWithNodeOptionSync));79test('Cannot use deno style nodePath as binary - execaNode()', () => testDoubleNode(getDenoNodePath(), execaNode));80test('Cannot use deno style nodePath as binary - "node" option', () => testDoubleNode(getDenoNodePath(), runWithNodeOption));81test('Cannot use deno style nodePath as binary - "node" option sync', () => testDoubleNode(getDenoNodePath(), runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 82–89why, one step back
82
83const getNodePath = async () => {84 const {path} = await getNode(TEST_NODE_VERSION);85 return path;86};8788const TEST_NODE_VERSION = '16.0.0';89

TweaksSindre Sorhusbefore adoption698a1b8

lines 90–94why, one step back
90// `nodeOptions` defaults to `process.execArgv`, which `node --test` fills with its own flags.
91// Those flags are unknown to the Node.js version downloaded by `getNode()`, so they are not forwarded.92const downloadedNodeOptions = {nodeOptions: []};9394const testNodePath = async (execaMethod, mapPath) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 95why, one step back
95 const nodePath = mapPath(await getNodePath());

TweaksSindre Sorhusbefore adoption698a1b8

lines 96–97why, one step back
96 const {stdout} = await execaMethod('--version', [], {nodePath, ...downloadedNodeOptions});
97 assert.equal(stdout, `v${TEST_NODE_VERSION}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 98–99why, one step back
98};
99

TweaksSindre Sorhusbefore adoption698a1b8

lines 100–105why, one step back
100test('The "nodePath" option can be used - execaNode()', () => testNodePath(execaNode, identity));
101test('The "nodePath" option can be a file URL - execaNode()', () => testNodePath(execaNode, pathToFileURL));102test('The "nodePath" option can be used - "node" option', () => testNodePath(runWithNodeOption, identity));103test('The "nodePath" option can be a file URL - "node" option', () => testNodePath(runWithNodeOption, pathToFileURL));104test('The "nodePath" option can be used - "node" option sync', () => testNodePath(runWithNodeOptionSync, identity));105test('The "nodePath" option can be a file URL - "node" option sync', () => testNodePath(runWithNodeOptionSync, pathToFileURL));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 106why, one step back
106

TweaksSindre Sorhusbefore adoption698a1b8

line 107why, one step back
107const testNodePathDefault = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 108why, one step back
108 const {stdout} = await execaMethod('--version');

TweaksSindre Sorhusbefore adoption698a1b8

line 109why, one step back
109 assert.equal(stdout, process.version);

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 112–114why, one step back
112test('The "nodePath" option defaults to the current Node.js binary - execaNode()', () => testNodePathDefault(execaNode));
113test('The "nodePath" option defaults to the current Node.js binary - "node" option', () => testNodePathDefault(runWithNodeOption));114test('The "nodePath" option defaults to the current Node.js binary - "node" option sync', () => testNodePathDefault(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 115why, one step back
115

TweaksSindre Sorhusbefore adoption698a1b8

lines 116–117why, one step back
116const testNodePathInvalid = execaMethod => {
117 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 118–121why, one step back
118 execaMethod('noop.js', [], {nodePath: true});
119 }, {message: /The "nodePath" option must be a string or a file URL/});120};121

TweaksSindre Sorhusbefore adoption698a1b8

lines 122–124why, one step back
122test('The "nodePath" option must be a string or URL - execaNode()', () => testNodePathInvalid(execaNode));
123test('The "nodePath" option must be a string or URL - "node" option', () => testNodePathInvalid(runWithNodeOption));124test('The "nodePath" option must be a string or URL - "node" option sync', () => testNodePathInvalid(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 125why, one step back
125

TweaksSindre Sorhusbefore adoption698a1b8

lines 126–127why, one step back
126const testFormerNodePath = execaMethod => {
127 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 128–131why, one step back
128 execaMethod('noop.js', [], {execPath: process.execPath});
129 }, {message: /The "execPath" option has been removed/});130};131

TweaksSindre Sorhusbefore adoption698a1b8

lines 132–134why, one step back
132test('The "execPath" option cannot be used - execaNode()', () => testFormerNodePath(execaNode));
133test('The "execPath" option cannot be used - "node" option', () => testFormerNodePath(runWithNodeOption));134test('The "execPath" option cannot be used - "node" option sync', () => testFormerNodePath(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 135–137why, one step back
135
136const nodePathArguments = ['-p', ['process.env.Path || process.env.PATH']];137

TweaksSindre Sorhusbefore adoption698a1b8

line 138why, one step back
138const testSubprocessNodePath = async (execaMethod, mapPath) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 139why, one step back
139 const nodePath = mapPath(await getNodePath());

TweaksSindre Sorhusbefore adoption698a1b8

lines 140–141why, one step back
140 const {stdout} = await execaMethod(...nodePathArguments, {nodePath, ...downloadedNodeOptions});
141 assert.ok(stdout.includes(TEST_NODE_VERSION));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 142–143why, one step back
142};
143

TweaksSindre Sorhusbefore adoption698a1b8

lines 144–146why, one step back
144test('The "nodePath" option impacts the subprocess - execaNode()', () => testSubprocessNodePath(execaNode, identity));
145test('The "nodePath" option impacts the subprocess - "node" option', () => testSubprocessNodePath(runWithNodeOption, identity));146test('The "nodePath" option impacts the subprocess - "node" option sync', () => testSubprocessNodePath(runWithNodeOptionSync, identity));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 147why, one step back
147

TweaksSindre Sorhusbefore adoption698a1b8

line 148why, one step back
148const testSubprocessNodePathDefault = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 149why, one step back
149 const {stdout} = await execaMethod(...nodePathArguments);

TweaksSindre Sorhusbefore adoption698a1b8

line 150why, one step back
150 assert.ok(stdout.includes(path.dirname(process.execPath)));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 151–152why, one step back
151};
152

TweaksSindre Sorhusbefore adoption698a1b8

lines 153–155why, one step back
153test('The "nodePath" option defaults to the current Node.js binary in the subprocess - execaNode()', () => testSubprocessNodePathDefault(execaNode));
154test('The "nodePath" option defaults to the current Node.js binary in the subprocess - "node" option', () => testSubprocessNodePathDefault(runWithNodeOption));155test('The "nodePath" option defaults to the current Node.js binary in the subprocess - "node" option sync', () => testSubprocessNodePathDefault(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 156why, one step back
156

TweaksSindre Sorhusbefore adoption698a1b8

line 157why, one step back
157test('The "nodePath" option requires "node: true" to impact the subprocess', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 158–159why, one step back
158 const nodePath = await getNodePath();
159 const {stdout} = await execa('node', nodePathArguments.flat(), {nodePath});

TweaksSindre Sorhusbefore adoption698a1b8

line 160why, one step back
160 assert.ok(!stdout.includes(TEST_NODE_VERSION));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 161–162why, one step back
161});
162

TweaksSindre Sorhusbefore adoption698a1b8

line 163why, one step back
163const testSubprocessNodePathCwd = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 164why, one step back
164 const nodePath = await getNodePath();

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

lines 165–166why, one step back
165 const cwd = path.dirname(path.dirname(nodePath));
166 const relativeExecPath = path.relative(cwd, nodePath);

TweaksSindre Sorhusbefore adoption698a1b8

lines 167–168why, one step back
167 const {stdout} = await execaMethod(...nodePathArguments, {nodePath: relativeExecPath, cwd, ...downloadedNodeOptions});
168 assert.ok(stdout.includes(TEST_NODE_VERSION));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 169–170why, one step back
169};
170

TweaksSindre Sorhusbefore adoption698a1b8

lines 171–173why, one step back
171test('The "nodePath" option is relative to "cwd" when used in the subprocess - execaNode()', () => testSubprocessNodePathCwd(execaNode));
172test('The "nodePath" option is relative to "cwd" when used in the subprocess - "node" option', () => testSubprocessNodePathCwd(runWithNodeOption));173test('The "nodePath" option is relative to "cwd" when used in the subprocess - "node" option sync', () => testSubprocessNodePathCwd(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 174why, one step back
174

TweaksSindre Sorhusbefore adoption698a1b8

line 175why, one step back
175const testCwdNodePath = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 176why, one step back
176 const nodePath = await getNodePath();

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

lines 177–178why, one step back
177 const cwd = path.dirname(path.dirname(nodePath));
178 const relativeExecPath = path.relative(cwd, nodePath);

TweaksSindre Sorhusbefore adoption698a1b8

lines 179–180why, one step back
179 const {stdout} = await execaMethod('--version', [], {nodePath: relativeExecPath, cwd, ...downloadedNodeOptions});
180 assert.equal(stdout, `v${TEST_NODE_VERSION}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 181–182why, one step back
181};
182

TweaksSindre Sorhusbefore adoption698a1b8

lines 183–185why, one step back
183test('The "nodePath" option is relative to "cwd" - execaNode()', () => testCwdNodePath(execaNode));
184test('The "nodePath" option is relative to "cwd" - "node" option', () => testCwdNodePath(runWithNodeOption));185test('The "nodePath" option is relative to "cwd" - "node" option sync', () => testCwdNodePath(runWithNodeOptionSync));

Fix deno node:process execPath compatibility (#1160)CJbefore adoptionf3a1bf3

line 186why, one step back
186

TweaksSindre Sorhusbefore adoption698a1b8

line 187why, one step back
187const testDenoExecPath = async execaMethod => {

Fix deno node:process execPath compatibility (#1160)CJbefore adoptionf3a1bf3

line 188why, one step back
188 const {exitCode, stdout} = await execaMethod('noop.js', [], {nodePath: getDenoNodePath()});

TweaksSindre Sorhusbefore adoption698a1b8

lines 189–190why, one step back
189 assert.equal(exitCode, 0);
190 assert.equal(stdout, foobarString);

Fix deno node:process execPath compatibility (#1160)CJbefore adoptionf3a1bf3

lines 191–192why, one step back
191};
192

TweaksSindre Sorhusbefore adoption698a1b8

lines 193–195why, one step back
193test('The deno style "nodePath" option can be used - execaNode()', () => testDenoExecPath(execaNode));
194test('The deno style "nodePath" option can be used - "node" option', () => testDenoExecPath(runWithNodeOption));195test('The deno style "nodePath" option can be used - "node" option sync', () => testDenoExecPath(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 196why, one step back
196

TweaksSindre Sorhusbefore adoption698a1b8

line 197why, one step back
197const testNodeOptions = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 198why, one step back
198 const {stdout} = await execaMethod('empty.js', [], {nodeOptions: ['--version']});

TweaksSindre Sorhusbefore adoption698a1b8

line 199why, one step back
199 assert.equal(stdout, process.version);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 200–201why, one step back
200};
201

TweaksSindre Sorhusbefore adoption698a1b8

lines 202–204why, one step back
202test('The "nodeOptions" option can be used - execaNode()', () => testNodeOptions(execaNode));
203test('The "nodeOptions" option can be used - "node" option', () => testNodeOptions(runWithNodeOption));204test('The "nodeOptions" option can be used - "node" option sync', () => testNodeOptions(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 205why, one step back
205

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

lines 206–213why, one step back
206test('The "nodeOptions" option must be an array of strings', () => {
207 assertThrows(() => execaNode('empty.js', {nodeOptions: '--version'}), {instanceOf: TypeError, message: /The "nodeOptions" option must be an array of strings/});208});209210test('The "nodeOptions" option items must be strings', () => {211 assertThrows(() => execaNode('empty.js', {nodeOptions: ['--version', 5]}), {instanceOf: TypeError, message: /The "nodeOptions" option must be an array of strings/});212});213

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 214–219why, one step back
214const spawnNestedExecaNode = (realExecArgv, fakeExecArgv, execaMethod, nodeOptions) => execa(
215 'node',216 [...realExecArgv, 'nested-node.js', fakeExecArgv, execaMethod, nodeOptions, 'noop.js', foobarString],217 {...fullStdio, cwd: FIXTURES_DIRECTORY},218);219

TweaksSindre Sorhusbefore adoption698a1b8

line 220why, one step back
220const testInspectRemoval = async (fakeExecArgv, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 221why, one step back
221 const {stdout, stdio} = await spawnNestedExecaNode([], fakeExecArgv, execaMethod, '');

TweaksSindre Sorhusbefore adoption698a1b8

lines 222–223why, one step back
222 assert.equal(stdout, foobarString);
223 assert.equal(stdio[3], '');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 224–225why, one step back
224};
225

TweaksSindre Sorhusbefore adoption698a1b8

lines 226–233why, one step back
226test('The "nodeOptions" option removes --inspect without a port when defined by current process - execaNode()', () => testInspectRemoval('--inspect', 'execaNode'));
227test('The "nodeOptions" option removes --inspect without a port when defined by current process - "node" option', () => testInspectRemoval('--inspect', 'nodeOption'));228test('The "nodeOptions" option removes --inspect with a port when defined by current process - execaNode()', () => testInspectRemoval('--inspect=9222', 'execaNode'));229test('The "nodeOptions" option removes --inspect with a port when defined by current process - "node" option', () => testInspectRemoval('--inspect=9222', 'nodeOption'));230test('The "nodeOptions" option removes --inspect-brk without a port when defined by current process - execaNode()', () => testInspectRemoval('--inspect-brk', 'execaNode'));231test('The "nodeOptions" option removes --inspect-brk without a port when defined by current process - "node" option', () => testInspectRemoval('--inspect-brk', 'nodeOption'));232test('The "nodeOptions" option removes --inspect-brk with a port when defined by current process - execaNode()', () => testInspectRemoval('--inspect-brk=9223', 'execaNode'));233test('The "nodeOptions" option removes --inspect-brk with a port when defined by current process - "node" option', () => testInspectRemoval('--inspect-brk=9223', 'nodeOption'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 234why, one step back
234

Fix template strings, `parseCommandString()` and `execaNode()` edge casesSindre Sorhusbefore adoptionfb92da1

lines 235–284why, one step back
235// When the current process runs `node --eval` or `node --print`, `process.execArgv` contains that code, which must not be run by the subprocess instead of its file.
236// The environment variable prevents a fork bomb, if that code is run.237const indexUrl = pathToFileURL(path.resolve(FIXTURES_DIRECTORY, '../../index.js')).href;238const evalCode = `if (process.env.EXECA_TEST_EVAL) {239 console.log('eval code was run by the subprocess');240} else {241 import(${JSON.stringify(indexUrl)}).then(async execaModule => {242 const {stdout} = await execaModule.execaNode('noop.js', [${JSON.stringify(foobarString)}], {env: {EXECA_TEST_EVAL: '1'}});243 console.log(stdout);244 });245}`;246247const testEvalRemoval = async nodeArguments => {248 const {stdout} = await execa('node', nodeArguments, {cwd: FIXTURES_DIRECTORY});249 // With `--print`, the value of the code is printed too250 assert.ok(stdout.split('\n').includes(foobarString));251 assert.ok(!stdout.includes('eval code was run'));252};253254test('The "nodeOptions" option removes -e when defined by current process', () => testEvalRemoval(['-e', evalCode]));255test('The "nodeOptions" option removes --eval when defined by current process', () => testEvalRemoval(['--eval', evalCode]));256test('The "nodeOptions" option removes --eval= when defined by current process', () => testEvalRemoval([`--eval=${evalCode}`]));257test('The "nodeOptions" option removes -p when defined by current process', () => testEvalRemoval(['-p', evalCode]));258test('The "nodeOptions" option removes --print when defined by current process', () => testEvalRemoval(['--print', evalCode]));259test('The "nodeOptions" option removes -pe when defined by current process', () => testEvalRemoval(['-pe', evalCode]));260test('The "nodeOptions" option removes -p -e when defined by current process', () => testEvalRemoval(['-p', '-e', evalCode]));261test('The "nodeOptions" option removes --print --eval when defined by current process', () => testEvalRemoval(['--print', '--eval', evalCode]));262test('The "nodeOptions" option removes -e -p when defined by current process', () => testEvalRemoval(['-e', evalCode, '-p']));263test('The "nodeOptions" option removes --input-type= when defined by current process', () => testEvalRemoval(['--input-type=commonjs', '-e', evalCode]));264test('The "nodeOptions" option removes --input-type when defined by current process', () => testEvalRemoval(['--input-type', 'commonjs', '-e', evalCode]));265// `--inspect-port` does not start the inspector by itself, so this does not need a free port266test('The "nodeOptions" option removes --inspect-port with a separate value when defined by current process', () => testEvalRemoval(['--inspect-port', '9339', '-e', evalCode]));267test('The "nodeOptions" option removes --inspect-port= when defined by current process', () => testEvalRemoval(['--inspect-port=9339', '-e', evalCode]));268269const testKeptFlags = async (keptFlags, removedFlags = []) => {270 const {stdout} = await execa('node', [...keptFlags, ...removedFlags, '-e', `import(${JSON.stringify(indexUrl)}).then(async execaModule => {271 const {stdout} = await execaModule.execaNode('-p', ['process.execArgv.join(" ")']);272 console.log(stdout);273 });`], {cwd: FIXTURES_DIRECTORY});274 assert.equal(stdout, [...keptFlags, '-p', 'process.execArgv.join(" ")'].join(' '));275};276277test('The "nodeOptions" option keeps other flags when -e is defined by current process', () => testKeptFlags(['--no-warnings']));278test('The "nodeOptions" option keeps the value of other flags when -e is defined by current process', () => testKeptFlags(['-r', './empty.js'], ['--input-type', 'commonjs']));279280test('The "nodeOptions" option is not filtered when passed explicitly', async () => {281 const {stdout} = await execaNode('-p', ['process.execArgv.join(" ")'], {nodeOptions: ['--input-type=commonjs', '--inspect-port=9339']});282 assert.equal(stdout, '--input-type=commonjs --inspect-port=9339 -p process.execArgv.join(" ")');283});284

TweaksSindre Sorhusbefore adoption698a1b8

line 285why, one step back
285const testInspectDifferentPort = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 286why, one step back
286 const {stdout, stdio} = await spawnNestedExecaNode(['--inspect=9225'], '', execaMethod, '--inspect=9224');

TweaksSindre Sorhusbefore adoption698a1b8

lines 287–288why, one step back
287 assert.equal(stdout, foobarString);
288 assert.ok(stdio[3].includes('Debugger listening'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 289–290why, one step back
289};
290

TweaksSindre Sorhusbefore adoption698a1b8

lines 291–292why, one step back
291test('The "nodeOptions" option allows --inspect with a different port even when defined by current process - execaNode()', () => testInspectDifferentPort('execaNode'));
292test('The "nodeOptions" option allows --inspect with a different port even when defined by current process - "node" option', () => testInspectDifferentPort('nodeOption'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 293why, one step back
293

TweaksSindre Sorhusbefore adoption698a1b8

line 294why, one step back
294const testInspectSamePort = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 295why, one step back
295 const {stdout, stdio} = await spawnNestedExecaNode(['--inspect=9226'], '', execaMethod, '--inspect=9226');

TweaksSindre Sorhusbefore adoption698a1b8

lines 296–297why, one step back
296 assert.equal(stdout, foobarString);
297 assert.ok(stdio[3].includes('address already in use'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 298–299why, one step back
298};
299

TweaksSindre Sorhusbefore adoption698a1b8

lines 300–301why, one step back
300test('The "nodeOptions" option forbids --inspect with the same port when defined by current process - execaNode()', () => testInspectSamePort('execaNode'));
301test('The "nodeOptions" option forbids --inspect with the same port when defined by current process - "node" option', () => testInspectSamePort('nodeOption'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 302why, one step back
302

TweaksSindre Sorhusbefore adoption698a1b8

line 303why, one step back
303const testIpc = async (execaMethod, options) => {

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 304–305why, one step back
304 const subprocess = execaMethod('ipc-echo.js', [], options);
305

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 306why, one step back
306 await subprocess.sendMessage(foobarString);

TweaksSindre Sorhusbefore adoption698a1b8

line 307why, one step back
307 assert.equal(await subprocess.getOneMessage(), foobarString);

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 308–309why, one step back
308
309 const {stdio} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 310–311why, one step back
310 assert.equal(stdio.length, 4);
311 assert.equal(stdio[3], undefined);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 312–313why, one step back
312};
313

TweaksSindre Sorhusbefore adoption698a1b8

lines 314–315why, one step back
314test('execaNode() adds an ipc channel', () => testIpc(execaNode, {}));
315test('The "node" option adds an ipc channel', () => testIpc(runWithNodeOption, {}));

Fix `execaNode()` and the `node` option missing IPC in their typesSindre Sorhusbefore adoption2633abb

lines 316–318why, one step back
316// Like other options, `undefined` uses the default value
317test('execaNode() adds an ipc channel, with "ipc: undefined"', () => testIpc(execaNode, {ipc: undefined}));318test('The "node" option adds an ipc channel, with "ipc: undefined"', () => testIpc(runWithNodeOption, {ipc: undefined}));

TweaksSindre Sorhusbefore adoption698a1b8

lines 319–322why, one step back
319test('The "ipc" option adds an ipc channel', () => testIpc(runWithIpc, {}));
320test('The "ipc" option works with "stdio: \'pipe\'"', () => testIpc(runWithIpc, {stdio: 'pipe'}));321test('The "ipc" option works with "stdio: [\'pipe\', \'pipe\', \'pipe\']"', () => testIpc(runWithIpc, {stdio: ['pipe', 'pipe', 'pipe']}));322test('The "ipc" option works with "stdout: \'pipe\'"', () => testIpc(runWithIpc, {stdout: 'pipe'}));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 323why, one step back
323

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

lines 324–325why, one step back
324const NO_SEND_MESSAGE = 'sendMessage() can only be used';
325

TweaksSindre Sorhusbefore adoption698a1b8

lines 326–329why, one step back
326test('No ipc channel is added by default', async () => {
327 const {message, stdio} = await assertRejects(execa('node', ['ipc-send.js']));328 assert.ok(message.includes(NO_SEND_MESSAGE));329 assert.equal(stdio.length, 3);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 330–331why, one step back
330});
331

TweaksSindre Sorhusbefore adoption698a1b8

line 332why, one step back
332const testDisableIpc = async execaMethod => {

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 333why, one step back
333 const {failed, message, stdio} = await execaMethod('ipc-send.js', [], {ipc: false, reject: false});

TweaksSindre Sorhusbefore adoption698a1b8

lines 334–336why, one step back
334 assert.equal(failed, true);
335 assert.ok(message.includes(NO_SEND_MESSAGE));336 assert.equal(stdio.length, 3);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 337–338why, one step back
337};
338

TweaksSindre Sorhusbefore adoption698a1b8

lines 339–341why, one step back
339test('Can disable "ipc" - execaNode()', () => testDisableIpc(execaNode));
340test('Can disable "ipc" - "node" option', () => testDisableIpc(runWithNodeOption));341test('Can disable "ipc" - "node" option sync', () => testDisableIpc(runWithNodeOptionSync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 342–344why, one step back
342
343const NO_IPC_MESSAGE = /The "ipc: true" option cannot be used/;344

TweaksSindre Sorhusbefore adoption698a1b8

lines 345–346why, one step back
345const testNoIpcSync = node => {
346 assertThrows(() => {

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 347why, one step back
347 execaSync('node', ['ipc-send.js'], {ipc: true, node});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 348–350why, one step back
348 }, {message: NO_IPC_MESSAGE});
349};350

TweaksSindre Sorhusbefore adoption698a1b8

lines 351–352why, one step back
351test('Cannot use "ipc: true" with execaSync()', () => testNoIpcSync(undefined));
352test('Cannot use "ipc: true" with execaSync() - "node: false"', () => testNoIpcSync(false));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 353why, one step back
353

TweaksSindre Sorhusbefore adoption698a1b8

lines 354–355why, one step back
354test('Cannot use "ipc: true" with execaSync() - "node: true"', () => {
355 assertThrows(() => {

Add promise-based IPC (#1059)ehmickybefore adoptionacc2b68

line 356why, one step back
356 execaSync('ipc-send.js', {ipc: true, node: true});

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 357–359why, one step back
357 }, {message: NO_IPC_MESSAGE});
358});359

TweaksSindre Sorhusbefore adoption698a1b8

line 360why, one step back
360const testNoShell = async execaMethod => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 361why, one step back
361 const {failed, message} = await execaMethod('node --version', [], {shell: true, reject: false});

TweaksSindre Sorhusbefore adoption698a1b8

lines 362–363why, one step back
362 assert.equal(failed, true);
363 assert.ok(message.includes('MODULE_NOT_FOUND'));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 364–365why, one step back
364};
365

TweaksSindre Sorhusbefore adoption698a1b8

lines 366–368why, one step back
366test('Cannot use "shell: true" - execaNode()', () => testNoShell(execaNode));
367test('Cannot use "shell: true" - "node" option', () => testNoShell(runWithNodeOption));368test('Cannot use "shell: true" - "node" option sync', () => testNoShell(runWithNodeOptionSync));