Skip to content

Commit

Permalink
Remove --inspect & --inspect-brk from execArgv (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Oct 28, 2020
1 parent 1e5cb36 commit 8fd3f64
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -234,8 +234,12 @@ module.exports.node = (scriptPath, args, options = {}) => {
}

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

const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;
const {
nodePath = process.execPath,
nodeOptions = defaultExecArgv
} = options;

return execa(
nodePath,
Expand Down
54 changes: 54 additions & 0 deletions test/node.js
Expand Up @@ -5,6 +5,23 @@ import execa from '..';

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

async function inspectMacro(t, input) {
const originalArgv = process.execArgv;
process.execArgv = [input, '-e'];
try {
const subprocess = execa.node('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 execa.node('test/fixtures/noop');
t.is(exitCode, 0);
Expand Down Expand Up @@ -37,6 +54,43 @@ test('node pass on nodeOptions', async t => {
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 execa.node('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 = execa.node('test/fixtures/send');
subprocess.send('ping');
Expand Down

0 comments on commit 8fd3f64

Please sign in to comment.