2015-12-19 17:40:53 +01:00
|
|
|
'use strict';
|
|
|
|
|
2016-01-25 11:05:01 +01:00
|
|
|
const colors = require('colors');
|
2015-12-19 17:40:53 +01:00
|
|
|
const sauceConnectLauncher = require('sauce-connect-launcher');
|
2016-06-02 16:42:20 +02:00
|
|
|
const config = require('./config');
|
2016-01-25 11:05:01 +01:00
|
|
|
|
|
|
|
|
2015-12-19 17:40:53 +01:00
|
|
|
let globalSauceProcess;
|
|
|
|
|
2016-01-25 11:05:01 +01:00
|
|
|
if (!process.env.SAUCE_USERNAME) {
|
|
|
|
console.log(colors.red('SAUCE_USERNAME is missing. Please check the README.md file.'));
|
2016-06-02 16:42:20 +02:00
|
|
|
process.exit(1);
|
2016-01-25 11:05:01 +01:00
|
|
|
}
|
|
|
|
|
2016-01-25 11:24:35 +01:00
|
|
|
if (!process.env.SAUCE_ACCESS_KEY) {
|
2016-01-25 11:05:01 +01:00
|
|
|
console.log(colors.red('SAUCE_ACCESS_KEY is missing. Please check the README.md file.'));
|
2016-06-02 16:42:20 +02:00
|
|
|
process.exit(1);
|
2016-01-25 11:05:01 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 17:40:53 +01:00
|
|
|
|
2016-01-25 11:32:43 +01:00
|
|
|
if (process.env.SAUCE_AUTO_CONNECT) {
|
2016-06-02 16:42:20 +02:00
|
|
|
before(function (done) {
|
2016-01-25 11:05:01 +01:00
|
|
|
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.
|
2015-12-19 17:40:53 +01:00
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
sauceConnectLauncher(function (err, sauceConnectProcess) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
globalSauceProcess = sauceConnectProcess;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
// Creating the tunnel takes a bit of time. For this case we can safely disable it.
|
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
if (globalSauceProcess) {
|
|
|
|
globalSauceProcess.close(done);
|
|
|
|
}
|
|
|
|
});
|
2016-01-25 11:05:01 +01:00
|
|
|
} 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'));
|
2015-12-19 17:40:53 +01:00
|
|
|
}
|