Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Mar 25, 2020
1 parent 335d9c2 commit e737046
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# hermione-sauce

Plugin for starting up Sauce Connect when running tests with [hermione](https://github.com/gemini-testing/hermione).

## Installation

`npm install hermione-sauce`

## Configuration

- Use env variables `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY`
33 changes: 33 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const Sauce = require('./lib/sauce');

function expandCredentials(opts) {
if (!opts.username) {
opts.username = process.env.SAUCE_USERNAME;
}
if (!opts.accessKey) {
opts.accessKey = process.env.SAUCE_ACCESS_KEY;
}
if (!opts.username || !opts.accessKey) {
throw Error('Missing Sauce credentials. Did you forget to set SAUCE_USERNAME and/or SAUCE_ACCESS_KEY?');
}
}

module.exports = (hermione, opts) => {
expandCredentials(opts);

const sauce = Sauce.create(opts);

hermione.on(hermione.events.RUNNER_START, async() => {
const { gridUrl, tunnelIdentifier } = await sauce.start();

hermione.config.getBrowserIds().forEach(browserId => {
const browser = hermione.config.forBrowser(browserId);
browser.gridUrl = gridUrl;
browser.desiredCapabilities['tunnel-identifier'] = tunnelIdentifier;
});
});

hermione.on(hermione.events.RUNNER_END, () => {
sauce.stop();
});
}
36 changes: 36 additions & 0 deletions lib/sauce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const uuid = require('uuid');
const { promisify } = require('util');
const sauceConnectLauncher = require('sauce-connect-launcher');
const launchSauceConnect = promisify(sauceConnectLauncher);

module.exports = class Sauce {
static create(config) {
return new this(config);
}

constructor(config) {
this._config = config;
this._sauceConnectProcess = null;
}

async start() {
const { username, accessKey, verbose } = this._config;

const gridUrl = `http://${username}:${accessKey}@ondemand.saucelabs.com:80/wd/hub`;
const tunnelIdentifier = uuid.v4();

this._sauceConnectProcess = await launchSauceConnect({
username,
accessKey,
logger: console.log,
verbose,
tunnelIdentifier
});

return { gridUrl, tunnelIdentifier };
}

stop() {
return this._sauceConnectProcess.close();
}
};
171 changes: 171 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "hermione-sauce",
"version": "0.0.0",
"author": "Serhii Kulykov",
"license": "MIT",
"description": "Plugin for starting up Sauce Connect when running tests with hermione",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/web-padawan/hermione-sauce.git"
},
"files": [
"index.js",
"lib"
],
"keywords": [
"hermione",
"hermione-plugin",
"saucelabs",
"sauce",
"connect",
"testing"
],
"dependencies": {
"lodash": "^4.17.15",
"sauce-connect-launcher": "^1.3.1",
"uuid": "^2.0.1"
}
}

0 comments on commit e737046

Please sign in to comment.