forked from sindresorhus/execa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.js
138 lines (114 loc) · 3.24 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import path from 'path';
import test from 'ava';
import pEvent from 'p-event';
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 nodePath', async t => {
const {stdout} = await execa.node(
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 execa.node('console.log("foo")', {
stdout: 'pipe',
nodeOptions: ['-e']
});
t.is(stdout, 'foo');
});
test.serial(
'node removes --inspect from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect', '-e'];
const {stdout, stderr} = await execa.node('console.log("foo")', {
stdout: 'pipe'
});
process.execArgv = originalArgv;
t.is(stdout, 'foo');
t.is(stderr, '');
}
);
test.serial(
'node removes --inspect=9222 from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect=9222', '-e'];
const {stdout, stderr} = await execa.node('console.log("foo")', {
stdout: 'pipe'
});
process.execArgv = originalArgv;
t.is(stdout, 'foo');
t.is(stderr, '');
}
);
test.serial(
'node removes --inspect-brk from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect-brk', '-e'];
const childProc = execa.node('console.log("foo")', {
stdout: 'pipe'
});
process.execArgv = originalArgv;
setTimeout(() => {
childProc.cancel();
}, 1000);
const {stdout, stderr} = await childProc.catch(error => error);
t.is(stdout, 'foo');
t.is(stderr, '');
}
);
test.serial(
'node removes --inspect-brk=9222 from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect-brk=9222', '-e'];
const childProc = execa.node('console.log("foo")', {
stdout: 'pipe'
});
process.execArgv = originalArgv;
setTimeout(() => {
childProc.cancel();
}, 1000);
const {stdout, stderr} = await childProc.catch(error => error);
t.is(stdout, 'foo');
t.is(stderr, '');
}
);
test.serial(
'node should not remove --inspect when passed through nodeOptions',
async t => {
const {stdout, stderr} = await execa.node('console.log("foo")', {
stdout: 'pipe',
nodeOptions: ['--inspect', '-e']
});
t.is(stdout, 'foo');
t.regex(
stderr,
/^Debugger listening on ws:\/\/127.0.0.1:9229\/.*[\r\n]+For help, see: https:\/\/nodejs.org\/en\/docs\/inspector$/
);
}
);
test('node\'s forked script has a communication channel', async t => {
const subprocess = execa.node('test/fixtures/send');
subprocess.send('ping');
const message = await pEvent(subprocess, 'message');
t.is(message, 'pong');
});