sauce.js
3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* This is an implementation of the SauceLabs Driver Provider.
* It is responsible for setting up the account object, tearing
* it down, and setting up the driver correctly.
*/
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var q = require("q");
var util = require("util");
var logger_1 = require("../logger");
var driverProvider_1 = require("./driverProvider");
var SauceLabs = require('saucelabs');
var logger = new logger_1.Logger('sauce');
var Sauce = (function (_super) {
__extends(Sauce, _super);
function Sauce(config) {
return _super.call(this, config) || this;
}
/**
* Hook to update the sauce job.
* @public
* @param {Object} update
* @return {q.promise} A promise that will resolve when the update is complete.
*/
Sauce.prototype.updateJob = function (update) {
var _this = this;
var deferredArray = this.drivers_.map(function (driver) {
var deferred = q.defer();
driver.getSession().then(function (session) {
logger.info('SauceLabs results available at http://saucelabs.com/jobs/' + session.getId());
_this.sauceServer_.updateJob(session.getId(), update, function (err) {
if (err) {
throw new Error('Error updating Sauce pass/fail status: ' + util.inspect(err));
}
deferred.resolve();
});
});
return deferred.promise;
});
return q.all(deferredArray);
};
/**
* Configure and launch (if applicable) the object's environment.
* @public
* @return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
Sauce.prototype.setupEnv = function () {
var deferred = q.defer();
this.sauceServer_ = new SauceLabs({
username: this.config_.sauceUser,
password: this.config_.sauceKey,
agent: this.config_.sauceAgent,
proxy: this.config_.sauceProxy
});
this.config_.capabilities['username'] = this.config_.sauceUser;
this.config_.capabilities['accessKey'] = this.config_.sauceKey;
this.config_.capabilities['build'] = this.config_.sauceBuild;
var auth = 'http://' + this.config_.sauceUser + ':' + this.config_.sauceKey + '@';
this.config_.seleniumAddress =
auth + (this.config_.sauceSeleniumAddress ? this.config_.sauceSeleniumAddress :
'ondemand.saucelabs.com:80/wd/hub');
// Append filename to capabilities.name so that it's easier to identify
// tests.
if (this.config_.capabilities.name && this.config_.capabilities.shardTestFiles) {
this.config_.capabilities.name +=
(':' + this.config_.specs.toString().replace(/^.*[\\\/]/, ''));
}
logger.info('Using SauceLabs selenium server at ' +
this.config_.seleniumAddress.replace(/\/\/.+@/, '//'));
deferred.resolve();
return deferred.promise;
};
return Sauce;
}(driverProvider_1.DriverProvider));
exports.Sauce = Sauce;