Skip to content

Commit

Permalink
fix avajs#342 — support --inspect arg
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 20, 2016
1 parent 048b7a4 commit 81c8e0b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
17 changes: 15 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand All @@ -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';
Expand Down
28 changes: 21 additions & 7 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
});
});
}
Expand All @@ -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']);

0 comments on commit 81c8e0b

Please sign in to comment.