Skip to content

Commit

Permalink
chore(runner): wait for debugger using then block (#4014)
Browse files Browse the repository at this point in the history
Closes #3898
  • Loading branch information
sjelin committed Jan 26, 2017
1 parent f4cf277 commit cbbae47
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class Runner extends EventEmitter {
plugins_: Plugins;
restartPromise: q.Promise<any>;
frameworkUsesAfterEach: boolean;
ready_?: wdpromise.Promise<void>;

constructor(config: Config) {
super();
Expand All @@ -49,16 +50,18 @@ export class Runner extends EventEmitter {
process['_debugProcess'](process.pid);
let flow = wdpromise.controlFlow();

flow.execute(() => {
let nodedebug = require('child_process').fork('debug', ['localhost:5858']);
process.on('exit', function() {
nodedebug.kill('SIGTERM');
});
nodedebug.on('exit', function() {
process.exit(1);
});
}, 'start the node debugger');
flow.timeout(1000, 'waiting for debugger to attach');
this.ready_ = flow.execute(() => {
let nodedebug =
require('child_process').fork('debug', ['localhost:5858']);
process.on('exit', function() {
nodedebug.kill('SIGTERM');
});
nodedebug.on('exit', function() {
process.exit(1);
});
}, 'start the node debugger').then(() => {
return flow.timeout(1000, 'waiting for debugger to attach');
});
}

if (config.capabilities && config.capabilities.seleniumAddress) {
Expand Down Expand Up @@ -304,9 +307,13 @@ export class Runner extends EventEmitter {
throw new Error('Spec patterns did not match any files.');
}

// 1) Setup environment
// noinspection JSValidateTypes
return this.driverprovider_.setupEnv()
// 0) Wait for debugger
return q(this.ready_)
.then(() => {
// 1) Setup environment
// noinspection JSValidateTypes
return this.driverprovider_.setupEnv();
})
.then(() => {
// 2) Create a browser and setup globals
browser_ = this.createBrowser(plugins);
Expand Down

0 comments on commit cbbae47

Please sign in to comment.