Skip to content

Commit

Permalink
Allow reconnecting if Saucelabs terminated session (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion authored and vikerman committed Dec 12, 2018
1 parent 7c35282 commit 6a9768d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ node_js:

script:
- yarn
- yarn build
- mv dist/ node_modules/karma-sauce-launcher
- yarn karma start examples/karma.conf-ci.js
- yarn run-example

cache:
yarn: true
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"description": "A Karma plugin. Launch any browser on SauceLabs!",
"main": "./index.js",
"scripts": {
"build": "tsc -p src/ && cp package.json dist/"
"build": "tsc -p src/ && cp package.json dist/",
"run-example": "yarn build && yarn copy-dist-to-modules && yarn run-example-karma",
"copy-dist-to-modules": "rm -rf node_modules/karma-sauce-launcher && mv dist/ node_modules/karma-sauce-launcher",
"run-example-karma": "yarn karma start examples/karma.conf-ci.js"
},
"repository": {
"type": "git",
Expand Down
13 changes: 12 additions & 1 deletion src/launcher/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ export function SaucelabsLauncher(args,
});

this.on('kill', async (doneFn: () => void) => {
await Promise.all(connectedDrivers.map(driver => driver.quit()));
await Promise.all(connectedDrivers.map(driver => {
try {
return driver.quit();
} catch (e) {
// We need to ignore the exception here because we want to make sure that Karma is still
// able to retry connecting if Saucelabs itself terminated the session (and not Karma)
// For example if the "idleTimeout" is exceeded and Saucelabs errored the session. See:
// https://wiki.saucelabs.com/display/DOCS/Test+Didn%27t+See+a+New+Command+for+90+Seconds
log.error('Could not quit the Saucelabs selenium connection. Failure message:');
log.error(e);
}
}));

// Reset connected drivers in case the launcher will be reused.
connectedDrivers = [];
Expand Down

0 comments on commit 6a9768d

Please sign in to comment.