Skip to content

Commit

Permalink
add listenered to connection only when testRun is started
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Sep 7, 2018
1 parent 39e7cf7 commit a7a45c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/browser/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class BrowserConnection extends EventEmitter {
this.initScriptsQueue = [];
this.browserConnectionGateway = gateway;
this.errorSupressed = false;
this.testRunAborted = false;

this.browserInfo = browserInfo;
this.browserInfo.userAgent = '';
Expand Down Expand Up @@ -121,7 +122,7 @@ export default class BrowserConnection extends EventEmitter {

this.opened = false;
this.errorSupressed = false;
this.cancelTestRun = true;
this.testRunAborted = true;

this.emit('disconnected', err);

Expand Down Expand Up @@ -301,9 +302,9 @@ export default class BrowserConnection extends EventEmitter {
}

if (this.opened) {
const testRunUrl = await this._getTestRunUrl(isTestDone || this.cancelTestRun);
const testRunUrl = await this._getTestRunUrl(isTestDone || this.testRunAborted);

this.cancelTestRun = false;
this.testRunAborted = false;

if (testRunUrl) {
this.idle = false;
Expand Down
12 changes: 8 additions & 4 deletions src/test-run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ export default class TestRun extends EventEmitter {
this.requestHooks = Array.from(this.test.requestHooks);

this._initRequestHooks();

this.browserConnection.once('disconnected', err => this.disconnect(err));
}

get id () {
Expand Down Expand Up @@ -277,6 +275,10 @@ export default class TestRun extends EventEmitter {

this.emit('start');

const onDisconnected = err => this._disconnect(err);

this.browserConnection.once('disconnected', onDisconnected);

if (await this._runBeforeHook()) {
await this._executeTestFn(PHASE.inTest, this.test.fn);
await this._runAfterHook();
Expand All @@ -285,6 +287,8 @@ export default class TestRun extends EventEmitter {
if (this.disconnected)
return;

this.browserConnection.removeListener('disconnected', onDisconnected);

if (this.errs.length && this.debugOnFail)
await this._enqueueSetBreakpointCommand(null, this.debugReporterPluginHost.formatError(this.errs[0]));

Expand Down Expand Up @@ -381,7 +385,7 @@ export default class TestRun extends EventEmitter {
}

_rejectCurrentDriverTask (err) {
err.callsite = err.callsite || this.driverTaskQueue[0].callsite;
err.callsite = err.callsite || this.currentDriverTask.callsite;
err.isRejectedDriverTask = true;

this.currentDriverTask.reject(err);
Expand Down Expand Up @@ -677,7 +681,7 @@ export default class TestRun extends EventEmitter {
return await getLocation();
}

disconnect (err) {
_disconnect (err) {
this.disconnected = true;

this._rejectCurrentDriverTask(err);
Expand Down

0 comments on commit a7a45c9

Please sign in to comment.