Skip to content
Myr

node.js

This file

Path

test/node.js

134 lines · 5.4 KiB · JavaScript

Last changed by

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

History of this file

Take it

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

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 1why, one step back
1import {dirname} from 'node:path';

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

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

Allow `nodePath` option to be a file URL (#632)ehmickybefore adoption77e1477

line 3why, one step back
3import {pathToFileURL} from 'node:url';

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 4why, one step back
4import test from 'ava';

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

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

Minor tweaksSindre Sorhusbefore adoption244e87a

line 6why, one step back
6import {pEvent} from 'p-event';

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 7–9why, one step back
7import {execa, execaSync, execaNode} from '../index.js';
8import {FIXTURES_DIR} from './helpers/fixtures-dir.js';9import {identity, fullStdio} from './helpers/stdio.js';

Improve tests for `execaNode()` (#777)ehmickybefore adoption27bb798

line 10why, one step back
10import {foobarString} from './helpers/input.js';

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 11why, one step back
11

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 12why, one step back
12process.chdir(FIXTURES_DIR);

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 13why, one step back
13

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 14–15why, one step back
14test('execaNode() succeeds', async t => {
15 const {exitCode} = await execaNode('noop.js');

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 16–18why, one step back
16 t.is(exitCode, 0);
17});18

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 19–20why, one step back
19test('execaNode() returns stdout', async t => {
20 const {stdout} = await execaNode('noop.js', ['foo']);

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 21–23why, one step back
21 t.is(stdout, 'foo');
22});23

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 24–42why, one step back
24const getNodePath = async () => {
25 const {path} = await getNode(TEST_NODE_VERSION);26 return path;27};2829const TEST_NODE_VERSION = '16.0.0';3031const testNodePath = async (t, mapPath) => {32 const nodePath = mapPath(await getNodePath());33 const {stdout} = await execaNode('--version', {nodePath});34 t.is(stdout, `v${TEST_NODE_VERSION}`);35};3637test.serial('The "nodePath" option can be used', testNodePath, identity);38test.serial('The "nodePath" option can be a file URL', testNodePath, pathToFileURL);3940test('The "nodePath" option defaults to the current Node.js binary', async t => {41 const {stdout} = await execaNode('--version');42 t.is(stdout, process.version);

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

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

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 45why, one step back
45const nodePathArguments = ['node', ['-p', 'process.env.Path || process.env.PATH']];

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 46why, one step back
46

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 47–58why, one step back
47const testExecPath = async (t, mapPath) => {
48 const execPath = mapPath(await getNodePath());49 const {stdout} = await execa(...nodePathArguments, {preferLocal: true, execPath});50 t.true(stdout.includes(TEST_NODE_VERSION));51};5253test.serial('The "execPath" option can be used', testExecPath, identity);54test.serial('The "execPath" option can be a file URL', testExecPath, pathToFileURL);5556test('The "execPath" option defaults to the current Node.js binary', async t => {57 const {stdout} = await execa(...nodePathArguments, {preferLocal: true});58 t.true(stdout.includes(dirname(process.execPath)));

Allow `nodePath` option to be a file URL (#632)ehmickybefore adoption77e1477

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

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 61–64why, one step back
61test.serial('The "execPath" option requires "preferLocal: true"', async t => {
62 const execPath = await getNodePath();63 const {stdout} = await execa(...nodePathArguments, {execPath});64 t.false(stdout.includes(TEST_NODE_VERSION));

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 65–66why, one step back
65});
66

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 67–69why, one step back
67test('The "nodeOptions" option can be used', async t => {
68 const {stdout} = await execaNode('empty.js', {nodeOptions: ['--version']});69 t.is(stdout, process.version);

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

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

Improve tests for `execaNode()` (#777)ehmickybefore adoption27bb798

lines 72–75why, one step back
72const spawnNestedExecaNode = (realExecArgv, fakeExecArgv, nodeOptions) => execa(
73 'node',74 [...realExecArgv, 'nested-node.js', fakeExecArgv, nodeOptions, 'noop.js', foobarString],75 {...fullStdio, cwd: FIXTURES_DIR},

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 76–77why, one step back
76);
77

Improve tests for `execaNode()` (#777)ehmickybefore adoption27bb798

lines 78–82why, one step back
78const testInspectRemoval = async (t, fakeExecArgv) => {
79 const {stdout, stdio} = await spawnNestedExecaNode([], fakeExecArgv, '');80 t.is(stdout, foobarString);81 t.is(stdio[3], '');82};

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 83why, one step back
83

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 84–87why, one step back
84test('The "nodeOptions" option removes --inspect without a port when defined by parent process', testInspectRemoval, '--inspect');
85test('The "nodeOptions" option removes --inspect with a port when defined by parent process', testInspectRemoval, '--inspect=9222');86test('The "nodeOptions" option removes --inspect-brk without a port when defined by parent process', testInspectRemoval, '--inspect-brk');87test('The "nodeOptions" option removes --inspect-brk with a port when defined by parent process', testInspectRemoval, '--inspect-brk=9223');

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 88why, one step back
88

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 89why, one step back
89test('The "nodeOptions" option allows --inspect with a different port even when defined by parent process', async t => {

Improve tests for `execaNode()` (#777)ehmickybefore adoption27bb798

lines 90–93why, one step back
90 const {stdout, stdio} = await spawnNestedExecaNode(['--inspect=9225'], '', '--inspect=9224');
91 t.is(stdout, foobarString);92 t.true(stdio[3].includes('Debugger listening'));93});

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 94why, one step back
94

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

line 95why, one step back
95test('The "nodeOptions" option forbids --inspect with the same port when defined by parent process', async t => {

Improve tests for `execaNode()` (#777)ehmickybefore adoption27bb798

lines 96–99why, one step back
96 const {stdout, stdio} = await spawnNestedExecaNode(['--inspect=9226'], '', '--inspect=9226');
97 t.is(stdout, foobarString);98 t.true(stdio[3].includes('address already in use'));99});

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 100why, one step back
100

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 101–104why, one step back
101const runWithIpc = (file, options) => execa('node', [file], {...options, ipc: true});
102103const testIpc = async (t, execaMethod, options) => {104 const subprocess = execaMethod('send.js', options);

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 105why, one step back
105 await pEvent(subprocess, 'message');

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 106–111why, one step back
106 subprocess.send(foobarString);
107 const {stdout, stdio} = await subprocess;108 t.is(stdout, foobarString);109 t.is(stdio.length, 4);110 t.is(stdio[3], undefined);111};

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 112why, one step back
112

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 113–118why, one step back
113test('execaNode() adds an ipc channel', testIpc, execaNode, {});
114test('The "ipc" option adds an ipc channel', testIpc, runWithIpc, {});115test('The "ipc" option works with "stdio: \'pipe\'"', testIpc, runWithIpc, {stdio: 'pipe'});116test('The "ipc" option works with "stdio: [\'pipe\', \'pipe\', \'pipe\']"', testIpc, runWithIpc, {stdio: ['pipe', 'pipe', 'pipe']});117test('The "ipc" option works with "stdio: [\'pipe\', \'pipe\', \'pipe\', \'ipc\']"', testIpc, runWithIpc, {stdio: ['pipe', 'pipe', 'pipe', 'ipc']});118test('The "ipc" option works with "stdout: \'pipe\'"', testIpc, runWithIpc, {stdout: 'pipe'});

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 119why, one step back
119

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 120–123why, one step back
120test('No ipc channel is added by default', async t => {
121 const {stdio} = await t.throwsAsync(execa('node', ['send.js']), {message: /process.send is not a function/});122 t.is(stdio.length, 3);123});

Fix processes not exiting on `inputFile` validation (#588)ehmickybefore adoption5b1a1c7

line 124why, one step back
124

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 125–128why, one step back
125test('Can disable "ipc" with execaNode', async t => {
126 const {stdio} = await t.throwsAsync(execaNode('send.js', {ipc: false}), {message: /process.send is not a function/});127 t.is(stdio.length, 3);128});

Improve some tests (#655)ehmickybefore adoption6cf1c5e

line 129why, one step back
129

Add `ipc` option (#794)ehmickybefore adoptionc8a7961

lines 130–133why, one step back
130test('Cannot use the "ipc" option with execaSync()', t => {
131 t.throws(() => {132 execaSync('node', ['send.js'], {ipc: true});133 }, {message: /The "ipc: true" option cannot be used/});

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 134why, one step back
134});