File: node.js

package info (click to toggle)
node-execa 8.0.1%2Bdfsg1%2B~cs12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,588 kB
  • sloc: javascript: 2,940; makefile: 11; sh: 1
file content (103 lines) | stat: -rw-r--r-- 2,427 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import process from 'node:process';
import test from 'ava';
import {pEvent} from 'p-event';
import {execaNode} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

setFixtureDir();

async function inspectMacro(t, input) {
	const originalArgv = process.execArgv;
	process.execArgv = [input, '-e'];
	try {
		const subprocess = execaNode('console.log("foo")', {
			reject: false,
		});

		const {stdout, stderr} = await subprocess;

		t.is(stdout, 'foo');
		t.is(stderr, '');
	} finally {
		process.execArgv = originalArgv;
	}
}

test('node()', async t => {
	const {exitCode} = await execaNode('test/fixtures/noop.js');
	t.is(exitCode, 0);
});

test('node pipe stdout', async t => {
	const {stdout} = await execaNode('test/fixtures/noop.js', ['foo'], {
		stdout: 'pipe',
	});

	t.is(stdout, 'foo');
});

test('node correctly use nodePath', async t => {
	const {stdout} = await execaNode(process.platform === 'win32' ? 'hello.cmd' : 'hello.sh', {
		stdout: 'pipe',
		nodePath: process.platform === 'win32' ? 'cmd.exe' : 'bash',
		nodeOptions: process.platform === 'win32' ? ['/c'] : [],
	});

	t.is(stdout, 'Hello World');
});

test('node pass on nodeOptions', async t => {
	const {stdout} = await execaNode('console.log("foo")', {
		stdout: 'pipe',
		nodeOptions: ['-e'],
	});

	t.is(stdout, 'foo');
});

test.serial(
	'node removes --inspect from nodeOptions when defined by parent process',
	inspectMacro,
	'--inspect',
);

test.serial(
	'node removes --inspect=9222 from nodeOptions when defined by parent process',
	inspectMacro,
	'--inspect=9222',
);

test.serial(
	'node removes --inspect-brk from nodeOptions when defined by parent process',
	inspectMacro,
	'--inspect-brk',
);

test.serial(
	'node removes --inspect-brk=9222 from nodeOptions when defined by parent process',
	inspectMacro,
	'--inspect-brk=9222',
);

test.serial(
	'node should not remove --inspect when passed through nodeOptions',
	async t => {
		const {stdout, stderr} = await execaNode('console.log("foo")', {
			reject: false,
			nodeOptions: ['--inspect', '-e'],
		});

		t.is(stdout, 'foo');
		t.true(stderr.includes('Debugger listening'));
	},
);

test('node\'s forked script has a communication channel', async t => {
	const subprocess = execaNode('test/fixtures/send.js');
	await pEvent(subprocess, 'message');

	subprocess.send('ping');

	const message = await pEvent(subprocess, 'message');
	t.is(message, 'pong');
});