From 9f6577c2142e3093e172ee38a1a1254d5ea9f15e Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 12 Dec 2018 22:16:40 +0100 Subject: [PATCH] Allow reconnecting if Saucelabs terminated session --- .travis.yml | 4 +--- package.json | 5 ++++- src/launcher/launcher.ts | 13 ++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index ca7a32e..7462a5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/package.json b/package.json index 50e35ff..c277087 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/launcher/launcher.ts b/src/launcher/launcher.ts index a9f04e0..c937a82 100644 --- a/src/launcher/launcher.ts +++ b/src/launcher/launcher.ts @@ -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 = [];