UNPKG

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