forked from sindresorhus/execa
/
node.js
46 lines (36 loc) · 1.16 KB
/
node.js
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
import test from 'ava';
import pEvent from 'p-event';
import path from 'path';
import execa from '..';
process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;
test('node()', async t => {
const {exitCode} = await execa.node('test/fixtures/noop');
t.is(exitCode, 0);
});
test('node pipe stdout', async t => {
const {stdout} = await execa.node('test/fixtures/noop', ['foo'], {
stdout: 'pipe'
});
t.is(stdout, 'foo');
});
test('node correctly use execPath', async t => {
const {stdout} = await execa.node(process.platform === 'win32' ? 'hello.cmd' : 'hello.sh', {
stdout: 'pipe',
execPath: process.platform === 'win32' ? 'cmd.exe' : 'bash',
execArgv: process.platform === 'win32' ? ['/c'] : []
});
t.is(stdout, 'Hello World');
});
test('node pass on execArgv', async t => {
const {stdout} = await execa.node('console.log("foo")', {
stdout: 'pipe',
execArgv: ['-e']
});
t.is(stdout, 'foo');
});
test('node\'s forked script has a communication channel', async t => {
const subprocess = execa.node('test/fixtures/send.js');
subprocess.send('ping');
const message = await pEvent(subprocess, 'message');
t.is(message, 'pong');
});