node.js
This file
Path
test/node.js
104 lines · 2.5 KiB · JavaScript
Last changed by
Meta tweaksSindre Sorhusbefore adoption5bac052
History of this fileTake it
Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 1–3why, one step back1import 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 back4import test from 'ava';Minor tweaksSindre Sorhusbefore adoption244e87a
line 5why, one step back5import {pEvent} from 'p-event';Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 6why, one step back6import {execaNode} from '../index.js';Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
line 7why, one step back7Meta tweaksSindre Sorhusbefore adoption5bac052
line 8why, one step back8process.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 back9Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 10–13why, one step back10async 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 back14 const subprocess = execaNode('console.log("foo")', {15 reject: false,Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 16–26why, one step back16 });1718 const {stdout, stderr} = await subprocess;1920 t.is(stdout, 'foo');21 t.is(stderr, '');22 } finally {23 process.execArgv = originalArgv;24 }25}26Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
line 27why, one step back27test('node()', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 28why, one step back28 const {exitCode} = await execaNode('test/fixtures/noop.js');Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
lines 29–32why, one step back29 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 back33 const {stdout} = await execaNode('test/fixtures/noop.js', ['foo'], {34 stdout: 'pipe',Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
lines 35–40why, one step back35 });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 back41 const {stdout} = await execaNode(process.platform === 'win32' ? 'hello.cmd' : 'hello.sh', {Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
lines 42–43why, one step back42 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 back44 nodeOptions: process.platform === 'win32' ? ['/c'] : [],Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
lines 45–49why, one step back45 });4647 t.is(stdout, 'Hello World');48});49Rename `nodeArguments` to `nodeOptions` (#299)ehmickybefore adoptionb979534
line 50why, one step back50test('node pass on nodeOptions', async t => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 51why, one step back51 const {stdout} = await execaNode('console.log("foo")', {Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
line 52why, one step back52 stdout: 'pipe',Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 53why, one step back53 nodeOptions: ['-e'],Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
lines 54–57why, one step back54 });5556 t.is(stdout, 'foo');57});Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 58–61why, one step back5859test.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 back62 '--inspect',Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 63–67why, one step back63);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 back68 '--inspect=9222',Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 69–73why, one step back69);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 back74 '--inspect-brk',Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 75–79why, one step back75);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 back80 '--inspect-brk=9222',Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 81–85why, one step back81);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 back86 const {stdout, stderr} = await execaNode('console.log("foo")', {Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
line 87why, one step back87 reject: false,Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 88why, one step back88 nodeOptions: ['--inspect', '-e'],Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
lines 89–92why, one step back89 });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 back93 },Remove `--inspect` & `--inspect-brk` from `execArgv` (#435)Ward Peetersbefore adoption8fd3f64
line 94why, one step back94);Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
lines 95–96why, one step back9596test('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 back97 const subprocess = execaNode('test/fixtures/send.js');98 await pEvent(subprocess, 'message');99Add `.node()` method (#200)Guillaume Martignybefore adoptionc2f5edf
lines 100–104why, one step back100 subprocess.send('ping');101102 const message = await pEvent(subprocess, 'message');103 t.is(message, 'pong');104});