Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Sauce Job with passed and build attribute #7

Merged
merged 1 commit into from
May 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Enable SauceLabs in your `.min-wd` file:
```
{
"sauceLabs": true,
"sauceJobName" : "TEST PROJECT",
"BUILD_VAR" : "TRAVIS_BUILD_NUMBER",
"browsers": [...]
}
```
Expand Down
24 changes: 18 additions & 6 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

var through = require('through2');
var listen = require('listen');
var http = require('http');
var fs = require('fs');
var sourceMap = require('source-mapper');
var request = require('./request');
var updateJob = require('./saucelabs').updateSauceJob;


function close(context, callback) {
Expand Down Expand Up @@ -43,10 +42,21 @@ function pollLogs(context, callback) {
context.out.write(res.value.substring(0, match.index));

var localCallback = function () {
if (match[1] === '0') {
callback();
} else {
callback(new Error('Build failed: ' + match[1]));
var passed = match[1] === '0';

context.sauceLabs ? updateJob(res.sessionId, passed, {
build: process.env[context.BUILD_VAR],
sauceJobName: context.sauceJobName
}, _getCallback(passed)) : _getCallback(passed)();

function _getCallback(passed) {
if (passed) {
return function () { callback(); }
} else {
return function () {
callback(new Error('Build failed: ' + match[1]))
}
}
}
};

Expand Down Expand Up @@ -171,6 +181,8 @@ function createContext(options, browser, out) {
timeout : options.timeout,
basePath : '/wd/hub',
browser : browser,
BUILD_VAR : options.BUILD_VAR,
sauceJobName : options.sauceJobName,
out : out,
sauceLabs : options.sauceLabs,
closeOnError : options.closeOnError,
Expand Down
24 changes: 24 additions & 0 deletions lib/saucelabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var SauceLabs = require('saucelabs');

module.exports.updateSauceJob = function (sessionId, passed, options, callback) {
if (!callback) {
callback = options;
options = {
build: null,
sauceJobName: null
};
}

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

sauceClient.updateJob(
sessionId,
{ name: options.sauceJobName, passed: passed, build: options.build },
function (err) {
callback(err);
}
);
};
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
"url": "https://github.com/mantoni/min-webdriver.git"
},
"dependencies": {
"through2": "^0.6",
"resolve": "^1.0",
"listen": "^1.0",
"brout": "^1.0",
"source-mapper": "^1.0"
"listen": "^1.0",
"resolve": "^1.0",
"saucelabs": "^0.1.1",
"source-mapper": "^1.0",
"through2": "^0.6"
},
"devDependencies": {
"jslint": "^0.8"
Expand Down