Skip to content

Commit 8fd3f64

Browse files
authoredOct 28, 2020
Remove --inspect & --inspect-brk from execArgv (#435)
1 parent 1e5cb36 commit 8fd3f64

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
 

‎index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,12 @@ module.exports.node = (scriptPath, args, options = {}) => {
234234
}
235235

236236
const stdio = normalizeStdio.node(options);
237+
const defaultExecArgv = process.execArgv.filter(arg => !arg.startsWith('--inspect'));
237238

238-
const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;
239+
const {
240+
nodePath = process.execPath,
241+
nodeOptions = defaultExecArgv
242+
} = options;
239243

240244
return execa(
241245
nodePath,

‎test/node.js

+54
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ import execa from '..';
55

66
process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;
77

8+
async function inspectMacro(t, input) {
9+
const originalArgv = process.execArgv;
10+
process.execArgv = [input, '-e'];
11+
try {
12+
const subprocess = execa.node('console.log("foo")', {
13+
reject: false
14+
});
15+
16+
const {stdout, stderr} = await subprocess;
17+
18+
t.is(stdout, 'foo');
19+
t.is(stderr, '');
20+
} finally {
21+
process.execArgv = originalArgv;
22+
}
23+
}
24+
825
test('node()', async t => {
926
const {exitCode} = await execa.node('test/fixtures/noop');
1027
t.is(exitCode, 0);
@@ -37,6 +54,43 @@ test('node pass on nodeOptions', async t => {
3754
t.is(stdout, 'foo');
3855
});
3956

57+
test.serial(
58+
'node removes --inspect from nodeOptions when defined by parent process',
59+
inspectMacro,
60+
'--inspect'
61+
);
62+
63+
test.serial(
64+
'node removes --inspect=9222 from nodeOptions when defined by parent process',
65+
inspectMacro,
66+
'--inspect=9222'
67+
);
68+
69+
test.serial(
70+
'node removes --inspect-brk from nodeOptions when defined by parent process',
71+
inspectMacro,
72+
'--inspect-brk'
73+
);
74+
75+
test.serial(
76+
'node removes --inspect-brk=9222 from nodeOptions when defined by parent process',
77+
inspectMacro,
78+
'--inspect-brk=9222'
79+
);
80+
81+
test.serial(
82+
'node should not remove --inspect when passed through nodeOptions',
83+
async t => {
84+
const {stdout, stderr} = await execa.node('console.log("foo")', {
85+
reject: false,
86+
nodeOptions: ['--inspect', '-e']
87+
});
88+
89+
t.is(stdout, 'foo');
90+
t.true(stderr.includes('Debugger listening'));
91+
}
92+
);
93+
4094
test('node\'s forked script has a communication channel', async t => {
4195
const subprocess = execa.node('test/fixtures/send');
4296
subprocess.send('ping');

0 commit comments

Comments
 (0)
Please sign in to comment.