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

Commit

Permalink
fix: correctly reset running state
Browse files Browse the repository at this point in the history
handle errors from openConnection too
  • Loading branch information
w33ble committed Apr 4, 2018
1 parent 6f2a2a0 commit 2f0829c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class HorseySauce extends events.EventEmitter {

return getBrowser(this.sauceUser, this.sauceKey, capabilities, this.tunnelId).then(
browser => {
this.isRunning = false;
this.emit('browser-ready');

// do things in the browser
Expand All @@ -43,6 +42,7 @@ export default class HorseySauce extends events.EventEmitter {
new Promise((resolve, reject) => {
this.emit('runner-start');
runner(browser, (err, data) => {
this.isRunning = false;
closeConnection().then(() => {
if (err) {
this.emit('runner-error', err);
Expand All @@ -53,7 +53,12 @@ export default class HorseySauce extends events.EventEmitter {
}
});
});
})
}),
err => {
this.isRunning = false;
this.emit('connection-error', err);
throw err;
}
);
},
err => {
Expand All @@ -64,6 +69,7 @@ export default class HorseySauce extends events.EventEmitter {
);
},
err => {
this.isRunning = false;
this.emit('tunnel-error', err);
throw err;
}
Expand Down
1 change: 1 addition & 0 deletions src/open_connection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function openConnection(src, browser, options = {}) {
.then(port => initRemote(port, browser))
.then(
() =>
// return a method to clean up connections
function closeConnection() {
return new Promise(resolve => {
server.close(() => browser.quit(() => resolve()));
Expand Down

0 comments on commit 2f0829c

Please sign in to comment.