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

Commit 2ca6541

Browse files
committed
fix(debug): make protractor debug work in the new runner/launcher world
Closes #552
1 parent ad5f3aa commit 2ca6541

File tree

4 files changed

+47
-40
lines changed

4 files changed

+47
-40
lines changed

bin/protractor

+1-38
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,4 @@
22

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

5-
/**
6-
* This tiny wrapper file checks for node debug flags and appends them
7-
* when found, before invoking the real executable. Thanks to mocha for the
8-
* pattern.
9-
*/
10-
11-
var spawn = require('child_process').spawn;
12-
var args = [__dirname + '/../lib/cli.js'];
13-
14-
process.argv.slice(2).forEach(function(arg) {
15-
var flag = arg.split('=')[0];
16-
17-
switch (flag) {
18-
case '-d':
19-
args.unshift('--debug');
20-
break;
21-
case 'debug':
22-
case '--debug':
23-
case '--debug-brk':
24-
args.unshift(arg);
25-
break;
26-
default:
27-
if (0 == arg.indexOf('--trace')) { args.unshift(arg); }
28-
else { args.push(arg); }
29-
break;
30-
}
31-
});
32-
33-
var proc = spawn(process.argv[0], args, { stdio: 'inherit' });
34-
proc.on('exit', function (code, signal) {
35-
process.on('exit', function() {
36-
if (signal) {
37-
process.kill(process.pid, signal);
38-
} else {
39-
process.exit(code);
40-
}
41-
});
42-
});
5+
require('../lib/cli.js');

lib/cli.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66
*/
77
'use strict';
88

9+
var args = [];
10+
11+
process.argv.slice(2).forEach(function(arg) {
12+
var flag = arg.split('=')[0];
13+
14+
switch (flag) {
15+
case 'debug':
16+
args.push('--nodeDebug');
17+
args.push('true');
18+
break;
19+
case '-d':
20+
case '--debug':
21+
case '--debug-brk':
22+
args.push('--v8Debug');
23+
args.push('true');
24+
break;
25+
default:
26+
args.push(arg);
27+
break;
28+
}
29+
});
30+
931
var util = require('util');
1032
var path = require('path');
1133
var child = require('child_process');
@@ -44,7 +66,7 @@ var argv = require('optimist').
4466
throw '';
4567
}
4668
}).
47-
argv;
69+
parse(args);
4870

4971
if (argv.version) {
5072
util.puts('Version ' + require(path.join(__dirname, '../package.json')).version);

lib/launcher.js

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ var init = function(argv) {
7373
}
7474

7575
if (config.multiCapabilities.length) {
76+
if (config.debug) {
77+
throw new Error('Cannot run in debug mode with multiCapabilities');
78+
}
7679
log_('Running using config.multiCapabilities - ' +
7780
'config.capabilities will be ignored');
7881
}

lib/runner.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,26 @@ var Runner = function(config) {
1818
this.driverprovider_ = null;
1919
this.config_ = config;
2020

21-
// Init
21+
if (config.v8Debug) {
22+
process.kill(process.pid, 'SIGUSR1');
23+
}
24+
25+
if (config.nodeDebug) {
26+
process.kill(process.pid, 'SIGUSR1');
27+
var flow = webdriver.promise.controlFlow();
28+
29+
flow.execute(function() {
30+
var nodedebug = require('child_process').fork('debug', ['localhost:5858']);
31+
process.on('exit', function() {
32+
nodedebug.kill('SIGTERM');
33+
});
34+
nodedebug.on('exit', function() {
35+
process.exit('1');
36+
});
37+
});
38+
flow.timeout(1000, 'waiting for debugger to attach');
39+
}
40+
2241
this.loadDriverProvider_(config);
2342
};
2443

0 commit comments

Comments
 (0)