Initial working saucelabs test result recording

This commit is contained in:
Tim Perry
2013-10-23 23:10:26 +01:00
committed by pimterry
parent 3a711790c5
commit a717f5c030

View File

@@ -7,6 +7,7 @@ var server = connect.createServer(
).listen(port);
// Tell saucelabs to run some tests
var browser = JSON.parse(process.env['SAUCE_BROWSER']);
var username = process.env['SAUCE_USERNAME'];
var accessKey = process.env['SAUCE_ACCESS_KEY'];
@@ -17,13 +18,50 @@ request.post(
{
auth: { user: username, pass: accessKey },
json: {
platforms: [[ "Windows 7", "chrome", "27" ]],
platforms: [ browser ],
url: "http://localhost:" + port + "/test/index.html",
framework: "qunit"
}
},
function (error, response, body) {
console.log(response.statusCode);
console.log(body);
if (response.statusCode == 200) {
var testIdentifier = body;
waitForTestCompletion(testIdentifier);
} else {
console.error("Failed to submit test to SauceLabs, status " + response.statusCode + ", body:\n" + JSON.stringify(body));
process.exit(3);
}
}
);
);
function waitForTestCompletion(testIdentifier) {
request.post(
'https://saucelabs.com/rest/v1/' + username + '/js-tests/status',
{
auth: { user: username, pass: accessKey },
json: testIdentifier
},
function (error, response, body) {
if (response.statusCode == 200) {
console.log(JSON.stringify(body));
if (body["completed"] == true) {
handleTestResults(body["js tests"]);
} else {
waitForTestCompletion(testIdentifier);
}
} else {
console.error("Failed to check test status on SauceLabs, status " + response.statusCode + ", body:\n" + JSON.stringify(body));
process.exit(4);
}
}
);
}
function handleTestResults(results) {
var allTestsSuccessful = results.reduce(function (passedSoFar, result) {
return passedSoFar && !!result['passed']
}, true);
console.log(allTestsSuccessful ? "Test passed" : "Test failed");
process.exit(allTestsSuccessful ? 0 : 1);
}