-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsauce_listener.js
More file actions
64 lines (53 loc) · 2.46 KB
/
Copy pathsauce_listener.js
File metadata and controls
64 lines (53 loc) · 2.46 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
/**
A listener that reports test success/failure to Sauce OnDemand.
Example usage:
node interpreter.js --browser-browserName=firefox --driver-host=ondemand.saucelabs.com --driver-port=80 --browser-username=$SAUCE_USERNAME --browser-accessKey=$SAUCE_ACCESSKEY --listener=./utils/sauce_listener.js examples/tests/get.json
You can also use --listener-silent=true to prevent the default listener output from happening, just like the --silent command.
*/
var https = require('https');
var util = require('util');
function Listener(testRun, params, interpreter_module) {
this.testRun = testRun;
this.originalListener = params.silent ? null : interpreter_module.getInterpreterListener(testRun, params, interpreter_module);
};
Listener.prototype.startTestRun = function(testRun, info) {
this.sessionID = testRun.wd.sessionID;
this.username = testRun.browserOptions.username;
this.accessKey = testRun.browserOptions.accessKey;
if (this.originalListener) { this.originalListener.startTestRun(testRun, info); }
};
Listener.prototype.endTestRun = function(testRun, info) {
var data = null;
if (info.error) {
data = JSON.stringify({'passed': info.success, 'name': testRun.name, 'custom-data': {'interpreter-error': util.inspect(info.error)}});
} else {
data = JSON.stringify({'passed': info.success, 'name': testRun.name});
}
var options = {
'hostname': 'saucelabs.com',
'port': 443,
'path': '/rest/v1/' + this.username + '/jobs/' + this.sessionID,
'method': 'PUT',
'auth': this.username + ':' + this.accessKey,
'headers': { 'Content-Type': 'application/json', 'Content-Length': data.length }
};
var req = https.request(options);
req.on('error', function(e) {
console.error(e);
});
req.write(data);
req.end();
if (this.originalListener) { this.originalListener.endTestRun(testRun, info); }
};
Listener.prototype.startStep = function(testRun, step) {
if (this.originalListener) { this.originalListener.startStep(testRun, step); }
};
Listener.prototype.endStep = function(testRun, step, info) {
if (this.originalListener) { this.originalListener.endStep(testRun, step, info); }
};
Listener.prototype.endAllRuns = function(num_runs, successes) {
if (this.originalListener) { this.originalListener.endAllRuns(num_runs, successes); }
};
exports.getInterpreterListener = function(testRun, options, interpreter_module) {
return new Listener(testRun, options, interpreter_module);
};