Skip to content

Commit

Permalink
Adds tunnel identifier for saucelabs connection. Closes metal#35
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Souza committed Jan 3, 2017
1 parent cef9e24 commit 0c9deca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ module.exports = function(options) {
singleRun: true
};

var key = process.env.SAUCE_ACCESS_KEY_ENC;
if (key) {
config.sauceLabs.accessKey = new Buffer(key, 'base64').toString('binary');
}
setSaucelabsSecurity(config);
runKarma(options, config, done, 'sauce');
});

Expand All @@ -127,6 +124,20 @@ module.exports = function(options) {
// Private helpers
// ===============

function setSaucelabsSecurity(karmaConfig) {
var sauceAccesssKey = process.env.SAUCE_ACCESS_KEY;
if (sauceAccesssKey) {
karmaConfig.sauceLabs.startConnect = false;
karmaConfig.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
}
else {
var key = process.env.SAUCE_ACCESS_KEY_ENC;
if (key) {
karmaConfig.sauceLabs.accessKey = new Buffer(key, 'base64').toString('binary');
}
}
}

function runKarma(options, config, done, opt_suffix) {
var suffix = opt_suffix ? '-' + opt_suffix : '';
var configFile = path.resolve('karma' + suffix + '.conf.js');
Expand Down
12 changes: 12 additions & 0 deletions test/lib/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ describe('Test Tasks', function() {
});
});

it('should not start a new connection to saucelabs when SAUCE_ACCESS_KEY is present when test:saucelabs is run', function(done) {
process.env.SAUCE_ACCESS_KEY = 'saucelabs access key from jwt connection';
process.env.TRAVIS_JOB_NUMBER = 'mocking travis job number';
registerTestTasks({karma: karmaStub});

gulp.start('test:saucelabs', function() {
var config = karmaStub.Server.args[0][0];
assert.strictEqual(false, config.sauceLabs.startConnect);
done();
});
});

it('should pass singleRun as false when test:watch is run', function(done) {
registerTestTasks({karma: karmaStub});

Expand Down

0 comments on commit 0c9deca

Please sign in to comment.