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 18, 2016
1 parent 1cf393b commit 3754db3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
17 changes: 15 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
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 3754db3

Please sign in to comment.