Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(debug): make protractor debug work in the new runner/launcher world
Browse files Browse the repository at this point in the history
Closes #552
  • Loading branch information
juliemr committed Mar 3, 2014
1 parent ad5f3aa commit 2ca6541
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
39 changes: 1 addition & 38 deletions bin/protractor
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,4 @@

process.env.NODE_ENV = process.env.NODE_ENV || 'test';

/**
* This tiny wrapper file checks for node debug flags and appends them
* when found, before invoking the real executable. Thanks to mocha for the
* pattern.
*/

var spawn = require('child_process').spawn;
var args = [__dirname + '/../lib/cli.js'];

process.argv.slice(2).forEach(function(arg) {
var flag = arg.split('=')[0];

switch (flag) {
case '-d':
args.unshift('--debug');
break;
case 'debug':
case '--debug':
case '--debug-brk':
args.unshift(arg);
break;
default:
if (0 == arg.indexOf('--trace')) { args.unshift(arg); }
else { args.push(arg); }
break;
}
});

var proc = spawn(process.argv[0], args, { stdio: 'inherit' });
proc.on('exit', function (code, signal) {
process.on('exit', function() {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
});
});
require('../lib/cli.js');
24 changes: 23 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
*/
'use strict';

var args = [];

process.argv.slice(2).forEach(function(arg) {
var flag = arg.split('=')[0];

switch (flag) {
case 'debug':
args.push('--nodeDebug');
args.push('true');
break;
case '-d':
case '--debug':
case '--debug-brk':
args.push('--v8Debug');
args.push('true');
break;
default:
args.push(arg);
break;
}
});

var util = require('util');
var path = require('path');
var child = require('child_process');
Expand Down Expand Up @@ -44,7 +66,7 @@ var argv = require('optimist').
throw '';
}
}).
argv;
parse(args);

if (argv.version) {
util.puts('Version ' + require(path.join(__dirname, '../package.json')).version);
Expand Down
3 changes: 3 additions & 0 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ var init = function(argv) {
}

if (config.multiCapabilities.length) {
if (config.debug) {
throw new Error('Cannot run in debug mode with multiCapabilities');
}
log_('Running using config.multiCapabilities - ' +
'config.capabilities will be ignored');
}
Expand Down
21 changes: 20 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,26 @@ var Runner = function(config) {
this.driverprovider_ = null;
this.config_ = config;

// Init
if (config.v8Debug) {
process.kill(process.pid, 'SIGUSR1');
}

if (config.nodeDebug) {
process.kill(process.pid, 'SIGUSR1');
var flow = webdriver.promise.controlFlow();

flow.execute(function() {
var nodedebug = require('child_process').fork('debug', ['localhost:5858']);
process.on('exit', function() {
nodedebug.kill('SIGTERM');
});
nodedebug.on('exit', function() {
process.exit('1');
});
});
flow.timeout(1000, 'waiting for debugger to attach');
}

this.loadDriverProvider_(config);
};

Expand Down

0 comments on commit 2ca6541

Please sign in to comment.