Skip to content

Instantly share code, notes, and snippets.

@geekdave
Created September 11, 2014 19:10
Show Gist options
  • Save geekdave/f2f482d2f1ac8db0cb7b to your computer and use it in GitHub Desktop.
Save geekdave/f2f482d2f1ac8db0cb7b to your computer and use it in GitHub Desktop.
Nightwatch / SauceLabs Stats Updating
updateStats: function (client, allPassed, callback) {
var data = JSON.stringify({
"passed" : allPassed
});
var requestPath = '/rest/v1/'+ client.options.username +'/jobs/' + client.sessionId;
try {
console.log('Updaing saucelabs', requestPath);
var req = https.request({
hostname: 'saucelabs.com',
path: requestPath,
method: 'PUT',
auth : client.options.username + ':' + client.options.accessKey,
headers : {
'Content-Type': 'application/json',
'Content-Length' : data.length
}
}, function(res) {
res.setEncoding('utf8');
console.log('Response: ', res.statusCode, JSON.stringify(res.headers));
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
res.on('end', function () {
callback();
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write(data);
req.end();
} catch (err) {
console.log('Error', err);
callback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment