Skip to content
Myr

node.js

This file

Path

test/node.js

104 lines · 2.5 KiB · JavaScript

Last changed by

Meta tweaksSindre Sorhusbefore adoption5bac052

History of this file

Take it

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

lines 1–3why, one step back
1import path from 'node:path';
2import process from 'node:process';3import {fileURLToPath} from 'node:url';

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

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

Minor tweaksSindre Sorhusbefore adoption244e87a

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

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

line 6why, one step back
6import {execaNode} from '../index.js';

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

line 7why, one step back
7

Meta tweaksSindre Sorhusbefore adoption5bac052

line 8why, one step back
8process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

line 9why, one step back
9

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 10–13why, one step back
10async function inspectMacro(t, input) {
11 const originalArgv = process.execArgv;12 process.execArgv = [input, '-e'];13 try {

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

lines 14–15why, one step back
14 const subprocess = execaNode('console.log("foo")', {
15 reject: false,

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 16–26why, one step back
16 });
1718 const {stdout, stderr} = await subprocess;1920 t.is(stdout, 'foo');21 t.is(stderr, '');22 } finally {23 process.execArgv = originalArgv;24 }25}26

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

line 27why, one step back
27test('node()', async t => {

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

line 28why, one step back
28 const {exitCode} = await execaNode('test/fixtures/noop.js');

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

lines 29–32why, one step back
29 t.is(exitCode, 0);
30});3132test('node pipe stdout', async t => {

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

lines 33–34why, one step back
33 const {stdout} = await execaNode('test/fixtures/noop.js', ['foo'], {
34 stdout: 'pipe',

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

lines 35–40why, one step back
35 });
3637 t.is(stdout, 'foo');38});3940test('node correctly use nodePath', async t => {

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

line 41why, one step back
41 const {stdout} = await execaNode(process.platform === 'win32' ? 'hello.cmd' : 'hello.sh', {

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

lines 42–43why, one step back
42 stdout: 'pipe',
43 nodePath: process.platform === 'win32' ? 'cmd.exe' : 'bash',

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

line 44why, one step back
44 nodeOptions: process.platform === 'win32' ? ['/c'] : [],

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

lines 45–49why, one step back
45 });
4647 t.is(stdout, 'Hello World');48});49

Rename `nodeArguments` to `nodeOptions` (#299)ehmickybefore adoptionb979534

line 50why, one step back
50test('node pass on nodeOptions', async t => {

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

line 51why, one step back
51 const {stdout} = await execaNode('console.log("foo")', {

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

line 52why, one step back
52 stdout: 'pipe',

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

line 53why, one step back
53 nodeOptions: ['-e'],

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

lines 54–57why, one step back
54 });
5556 t.is(stdout, 'foo');57});

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 58–61why, one step back
58
59test.serial(60 'node removes --inspect from nodeOptions when defined by parent process',61 inspectMacro,

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

line 62why, one step back
62 '--inspect',

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 63–67why, one step back
63);
6465test.serial(66 'node removes --inspect=9222 from nodeOptions when defined by parent process',67 inspectMacro,

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

line 68why, one step back
68 '--inspect=9222',

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 69–73why, one step back
69);
7071test.serial(72 'node removes --inspect-brk from nodeOptions when defined by parent process',73 inspectMacro,

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

line 74why, one step back
74 '--inspect-brk',

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 75–79why, one step back
75);
7677test.serial(78 'node removes --inspect-brk=9222 from nodeOptions when defined by parent process',79 inspectMacro,

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

line 80why, one step back
80 '--inspect-brk=9222',

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 81–85why, one step back
81);
8283test.serial(84 'node should not remove --inspect when passed through nodeOptions',85 async t => {

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

line 86why, one step back
86 const {stdout, stderr} = await execaNode('console.log("foo")', {

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

line 87why, one step back
87 reject: false,

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

line 88why, one step back
88 nodeOptions: ['--inspect', '-e'],

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

lines 89–92why, one step back
89 });
9091 t.is(stdout, 'foo');92 t.true(stderr.includes('Debugger listening'));

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

line 93why, one step back
93 },

Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64

line 94why, one step back
94);

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

lines 95–96why, one step back
95
96test('node\'s forked script has a communication channel', async t => {

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

lines 97–99why, one step back
97 const subprocess = execaNode('test/fixtures/send.js');
98 await pEvent(subprocess, 'message');99

Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf

lines 100–104why, one step back
100 subprocess.send('ping');
101102 const message = await pEvent(subprocess, 'message');103 t.is(message, 'pong');104});