Skip to content

Commit

Permalink
improved test runner, only load sauce connect for desktop and mobile …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
christian-bromann committed Aug 23, 2015
1 parent 22d4e11 commit 2ee280a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 23 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ script: "sleep 5 && npm run coverage"
after_script:
- "[ -d ./coverage ] && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"

addons:
sauce_connect: true

env:
global:
- secure: f6+NU5WBW9GPLRV2WhtCozPOjFOAdh52hXfr0dZopxl0eqJ426fl5UCt54duUQV/abBpNEKzBm2015EsBP14wepNJ9+Q6nRwrj/h2PvI3UM8vEPqgH08hqiS7kFszA0Wy+Ki3umncQbA5WAgq6grmZs9naELWmOX5Yum40Wl9/0=
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"istanbul": "^0.3.13",
"mocha": "^2.2.4",
"nock": "~1.7.1",
"sauce-connect-launcher": "^0.12.0",
"saucelabs": "~0.1.1",
"should": "^6.0.1"
},
Expand Down
83 changes: 63 additions & 20 deletions test/runner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var WebdriverIO = require('../index.js'),
q = require('q'),
Mocha = require('mocha'),
should = require('should'), // jshint ignore:line
SauceLabs = require('saucelabs'),
sauceConnectLauncher = require('sauce-connect-launcher'),
glob = require('glob'),
merge = require('deepmerge'),
env = process.env._ENV,
Expand All @@ -26,39 +28,80 @@ if(specDir) {
specFiles = '{test/spec/' + env + '/**/*.js,test/spec/*.js}';
}

glob(process.env._SPEC || specFiles, function(er, files) {
q.nfcall(glob, process.env._SPEC || specFiles).then(function(files) {

files.forEach(function(file) {
mocha.addFile(file);
});

mocha.run(function(failures) {
/**
* start sauce connect only in CI and for desktop and mobile tests
*/
if(!process.env.TRAVIS_BUILD_ID || specDir) {
return;
}

console.log('-> Starting Sauce Connect');
return q.nfcall(sauceConnectLauncher, {
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY
});

}).then(function(sauceConnectProcess) {

if(sauceConnectProcess) {
console.log('-> Sauce Connect ready');
}

console.log('-> Start Mocha tests');
var mochaDefer = q.defer();
mocha.run.call(mocha, mochaDefer.resolve.bind(mochaDefer));
return mochaDefer.promise;

}).then(function(failures) {

if (!client) {
return process.exit(failures);
}

var sessionID = (client.requestHandler || {}).sessionID,
endCommand = conf.runsWithSauce ? 'end' : 'endAll';

client[endCommand]().then(function() {
if (process.env.TRAVIS_BUILD_NUMBER) {
var sauceAccount = new SauceLabs({
username: process.env.SAUCE_USERNAME,
password: process.env.SAUCE_ACCESS_KEY
});

sauceAccount.updateJob(sessionID, {
passed: failures === 0,
public: true
}, function(err, res) {
console.log(err || res);
process.exit(failures);
});
} else {
process.exit(failures);
}
});
console.log('-> end all clients');
return client[endCommand]();

}).then(function() {

/**
* only update sauce job when running in CI
*/
if (!process.env.TRAVIS_BUILD_NUMBER) {
return process.exit(failures);
}

var sauceAccount = new SauceLabs({
username: process.env.SAUCE_USERNAME,
password: process.env.SAUCE_ACCESS_KEY
});

console.log('-> update sauce job');
return q.nfcall(sauceAccount.updateJob, sessionID, {
passed: failures === 0,
public: true
});

}).then(function(res) {

console.log('-> sauce job updated', res);
process.exit(failures);

console.log('-> shutting down sauce connect');
return q.nfcall(sauceConnectProcess.close);

}).then(function() {

console.log("-> closed Sauce Connect process");

});

h = {
Expand Down

0 comments on commit 2ee280a

Please sign in to comment.