Add utils to manage tunnel and stuff

This commit is contained in:
vrde 2016-01-25 11:05:01 +01:00
parent a95a0fd2ea
commit 778c61bfdc
7 changed files with 75 additions and 9 deletions

View File

@ -1,2 +1,3 @@
SAUCE_USERNAME=ascribe SAUCE_USERNAME=ascribe
SAUCE_ACCESS_KEY= SAUCE_ACCESS_KEY=
SAUCE_DEFAULT_URL=

View File

@ -11,7 +11,9 @@
"preinstall": "export SAUCE_CONNECT_DOWNLOAD_ON_INSTALL=true", "preinstall": "export SAUCE_CONNECT_DOWNLOAD_ON_INSTALL=true",
"postinstall": "npm run build", "postinstall": "npm run build",
"build": "gulp build --production", "build": "gulp build --production",
"start": "node server.js" "start": "node server.js",
"test": "mocha",
"tunnel": "node test/tunnel.js"
}, },
"browser": { "browser": {
"fineUploader": "./js/components/ascribe_uploader/vendor/s3.fine-uploader.js" "fineUploader": "./js/components/ascribe_uploader/vendor/s3.fine-uploader.js"
@ -38,6 +40,7 @@
"babel-jest": "^5.2.0", "babel-jest": "^5.2.0",
"chai": "^3.4.1", "chai": "^3.4.1",
"chai-as-promised": "^5.1.0", "chai-as-promised": "^5.1.0",
"colors": "^1.1.2",
"dotenv": "^1.2.0", "dotenv": "^1.2.0",
"gulp-sass": "^2.1.1", "gulp-sass": "^2.1.1",
"jest-cli": "^0.4.0", "jest-cli": "^0.4.0",

View File

@ -1,3 +1,13 @@
# TL;DR
Copy the file `.env-template` in `.env` and fill up the missing keys.
```bash
$ npm install
$ npm run tunnel
$ npm test && git commit
```
# Welcome to our test suite, let me be your guide # Welcome to our test suite, let me be your guide
Dear reader, first of all thanks for taking your time reading this document. Dear reader, first of all thanks for taking your time reading this document.
@ -199,3 +209,10 @@ $ mocha
By default the test suite runs on `http://www.localhost.com:3000/`, if you By default the test suite runs on `http://www.localhost.com:3000/`, if you
want to change the URL, change the `APP_URL` env variable. want to change the URL, change the `APP_URL` env variable.
# How to have fun
Try this!
```bash
$ mocha -R nyan
```

View File

@ -1,5 +1,7 @@
'use strict'; 'use strict';
require('dotenv').load();
// https://code.google.com/p/selenium/wiki/DesiredCapabilities // https://code.google.com/p/selenium/wiki/DesiredCapabilities
const BROWSERS = [ const BROWSERS = [
@ -9,8 +11,9 @@ const BROWSERS = [
'internet explorer,10,VISTA' 'internet explorer,10,VISTA'
]; ];
const APP_URL = process.env.APP_URL || 'http://www.localhost.com:3000';
module.exports = {
module.exports.BROWSERS = BROWSERS.map(x => x.split(',')); BROWSERS: BROWSERS.map(x => x.split(',')),
module.exports.APP_URL = APP_URL; APP_URL: process.env.SAUCE_DEFAULT_URL || 'http://www.localhost.com:3000',
TUNNEL_AUTO_CONNECT: process.env.SAUCE_AUTO_CONNECT
};

View File

@ -1,14 +1,27 @@
'use strict'; 'use strict';
require('dotenv').load(); const config = require('./config');
const colors = require('colors');
const sauceConnectLauncher = require('sauce-connect-launcher'); const sauceConnectLauncher = require('sauce-connect-launcher');
let globalSauceProcess; let globalSauceProcess;
if (!process.env.SAUCE_USERNAME) {
console.log(colors.red('SAUCE_USERNAME is missing. Please check the README.md file.'));
process.exit(1); //eslint-disable-line no-process-exit
}
if (process.env.SAUCE_AUTO_CONNECT) { if (!process.env.SAUCE_ACCESS_KEY2) {
console.log(colors.red('SAUCE_ACCESS_KEY is missing. Please check the README.md file.'));
process.exit(1); //eslint-disable-line no-process-exit
}
if (config.TUNNEL_AUTO_CONNECT) {
before(function(done) { before(function(done) {
// Creating the tunnel takes a bit of time. For this case we can safely disable it. console.log(colors.yellow('Setting up tunnel from Saucelabs to your lovely computer, will take a while.'));
// Creating the tunnel takes a bit of time. For this case we can safely disable Mocha timeouts.
this.timeout(0); this.timeout(0);
sauceConnectLauncher(function (err, sauceConnectProcess) { sauceConnectLauncher(function (err, sauceConnectProcess) {
@ -30,4 +43,8 @@ if (process.env.SAUCE_AUTO_CONNECT) {
globalSauceProcess.close(done); globalSauceProcess.close(done);
} }
}); });
} else if (config.APP_URL.match(/localhost/)) {
console.log(colors.yellow(`You are running tests on ${config.APP_URL}, make sure you already have a tunnel running.`));
console.log(colors.yellow('To create the tunnel, run:'));
console.log(colors.yellow(' $ node test/tunnel.js'));
} }

View File

@ -16,6 +16,8 @@ function testSuite(browserName, version, platform) {
let browser; let browser;
before(function() { before(function() {
// No need to inject `username` or `access_key`, by default the constructor
// looks up the values in `process.env.SAUCE_USERNAME` and `process.env.SAUCE_ACCESS_KEY`
browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80); browser = wd.promiseChainRemote('ondemand.saucelabs.com', 80);
return browser.init({ browserName, version, platform }); return browser.init({ browserName, version, platform });
}); });

23
test/tunnel.js Normal file
View File

@ -0,0 +1,23 @@
'use strict';
const config = require('./config'); //eslint-disable-line no-unused-vars
const colors = require('colors');
const sauceConnectLauncher = require('sauce-connect-launcher');
function connect() {
console.log(colors.yellow('Setting up tunnel from Saucelabs to your lovely computer, will take a while.'));
// Creating the tunnel takes a bit of time. For this case we can safely disable Mocha timeouts.
sauceConnectLauncher(function (err) {
if (err) {
console.error(err.message);
return;
}
console.log(colors.green('Connected! Keep this process running and execute your tests.'));
});
}
if (require.main === module) {
connect();
}