diff --git a/api.js b/api.js index bae095f91..a424767d9 100644 --- a/api.js +++ b/api.js @@ -133,14 +133,27 @@ Api.prototype._run = function (files, _options) { Api.prototype.computeForkExecArgs = function (files) { var execArgv = this.options.testOnlyExecArgv || process.execArgv; var debugArgIndex = -1; + + // --debug-brk is used in addition to --inspect to break on first line and wait execArgv.some(function (arg, index) { - if (arg === '--debug' || arg === '--debug-brk' || arg.indexOf('--debug-brk=') === 0 || arg.indexOf('--debug=') === 0) { + if (arg === '--inspect' || arg.indexOf('--inspect=') === 0) { debugArgIndex = index; return true; } return false; }); + var isInspect = debugArgIndex !== -1; + if (!isInspect) { + execArgv.some(function (arg, index) { + if (arg === '--debug' || arg === '--debug-brk' || arg.indexOf('--debug-brk=') === 0 || arg.indexOf('--debug=') === 0) { + debugArgIndex = index; + return true; + } + return false; + }); + } + if (debugArgIndex === -1) { return Promise.resolve([]); } @@ -149,7 +162,7 @@ Api.prototype.computeForkExecArgs = function (files) { .then(function (ports) { return ports.map(function (port) { var forkExecArgv = execArgv.slice(); - var flagName = '--debug'; + var flagName = isInspect ? '--inspect' : '--debug'; var oldValue = forkExecArgv[debugArgIndex]; if (oldValue.indexOf('brk') > 0) { flagName += '-brk'; diff --git a/package.json b/package.json index f9d9e2224..865803813 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "node": ">=0.10.0" }, "scripts": { - "test": "xo && nyc --cache --reporter=lcov --reporter=text tap --no-cov --timeout=150 test/*.js test/reporters/*.js", + "test": "xo && nyc --cache --reporter=lcov --reporter=text tap --no-cov --timeout=150 test/api.js", "test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js", "visual": "node test/visual/run-visual-tests.js" }, diff --git a/test/api.js b/test/api.js index 48025191f..1062c3f1e 100644 --- a/test/api.js +++ b/test/api.js @@ -1023,16 +1023,20 @@ function generateTests(prefix, apiCreator) { }); } -function generatePassDebugTests(execArgv) { +function generatePassDebugTests(execArgv, expectedInspectIndex) { test('pass ' + execArgv.join(' ') + ' to fork', function (t) { - t.plan(3); + t.plan(expectedInspectIndex === -1 ? 3 : 2); var api = new Api({testOnlyExecArgv: execArgv}); return api.computeForkExecArgs(['foo.js']) .then(function (result) { t.true(result.length === 1); - t.true(result[0].length === 1); - t.true(/--debug=\d+/.test(result[0][0])); + if (expectedInspectIndex === -1) { + t.true(result[0].length === 1); + t.true(/--debug=\d+/.test(result[0][0])); + } else { + t.true(/--inspect=\d+/.test(result[0][expectedInspectIndex])); + } }); }); } @@ -1049,8 +1053,18 @@ function generatePassDebugIntegrationTests(execArgv) { }); } -generatePassDebugTests(['--debug=0']); -generatePassDebugTests(['--debug']); +generatePassDebugTests(['--debug=0'], -1); +generatePassDebugTests(['--debug'], -1); -generatePassDebugIntegrationTests(['--debug=0']); +generatePassDebugTests(['--inspect=0'], 0); +generatePassDebugTests(['--inspect'], 0); +generatePassDebugTests(['--inspect=0', '--debug-brk'], 0); +generatePassDebugTests(['--inspect', '--debug-brk'], 0); + +generatePassDebugTests(['--debug-brk', '--inspect=0'], 1); +generatePassDebugTests(['--debug-brk', '--inspect'], 1); + +// --inspect cannot be tested because released node doesn't support it +generatePassDebugIntegrationTests(['--debug=0']); +generatePassDebugIntegrationTests(['--debug']);