Skip to content

Commit

Permalink
Merge pull request #3 from nomilous/release/2.0.2
Browse files Browse the repository at this point in the history
fix child fork with debug port in-use
  • Loading branch information
nomilous committed Jul 11, 2017
2 parents a2009f0 + 9d9757d commit ec01f9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,28 @@ function start(hook, script, opts) {

};

child = childRef._child = child_process.fork(script);
var options = {};

var isDebugMode = (function (array, contains) {
return contains.some(function (el) {
return array.indexOf(el) >= 0;
});
})(process.execArgv, [
'--inspect',
'--inspect-brk',
'--debug', // does not support --debug=9999 (port)
'--debug-brk'
]);

if (isDebugMode) {
// child inherits debugmode from parent, but then port is in-use
// and crashes, fix:
// use random debug port for child
var random = Math.floor(Math.random() * 64511) + 1024;
options.execArgv = ['--debug=' + random];
}

child = childRef._child = child_process.fork(script, [], options);

children[child.pid] = child;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mocha-fork",
"version": "2.0.1",
"version": "2.0.2",
"description": "Mocha hooks to start/stop background proccess in tests.",
"engines": {
"node": ">=4"
Expand Down

0 comments on commit ec01f9d

Please sign in to comment.