From 81c8e0bf621a8c7e99d7275bb2ed9d9b45469d5c Mon Sep 17 00:00:00 2001 From: develar Date: Sat, 18 Jun 2016 18:41:30 +0200 Subject: [PATCH] =?UTF-8?q?fix=20#342=20=E2=80=94=20support=20--inspect=20?= =?UTF-8?q?arg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.js | 17 +++++++++++++++-- test/api.js | 28 +++++++++++++++++++++------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/api.js b/api.js index 187d820733..9d77fe913d 100644 --- a/api.js +++ b/api.js @@ -137,14 +137,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([]); } @@ -153,7 +166,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/test/api.js b/test/api.js index 48025191f3..1062c3f1ee 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']);