From 34c8d8dd2e53cf07a630cdd8b8514d9597d9ef01 Mon Sep 17 00:00:00 2001 From: pimterry Date: Sun, 27 Oct 2013 19:30:42 +0000 Subject: [PATCH] Improve console logging output for saucelabs tests, and explicitly close sauce connect --- saucelabs.js | 89 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/saucelabs.js b/saucelabs.js index 41bcd16e9..ffe35aebf 100644 --- a/saucelabs.js +++ b/saucelabs.js @@ -19,6 +19,7 @@ var server = connect.createServer( // Set up sauce connect so we can use this server from saucelabs var tunnelTimeout = 10000; var tunnel = new SauceTunnel(username, accessKey, null, true, tunnelTimeout); + console.log("Opening sauce connect tunnel..."); tunnel.start(function (success) { if (success) { @@ -39,52 +40,68 @@ function runTests() { console.log("Starting saucelabs tests: " + JSON.stringify(testDefinition)); - request.post( - 'https://saucelabs.com/rest/v1/' + username + '/js-tests', - { - auth: { user: username, pass: accessKey }, - json: testDefinition - }, - function (error, response, 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); - } + request.post('https://saucelabs.com/rest/v1/' + username + '/js-tests', { + auth: { user: username, pass: accessKey }, + json: testDefinition + }, function (error, response, 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); - } + 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) { + if (body["completed"] == true) { + handleTestResults(body["js tests"]); } else { - console.error("Failed to check test status on SauceLabs, status " + response.statusCode + ", body:\n" + JSON.stringify(body)); - process.exit(4); + 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'] + var allTestsSuccessful = results.reduce(function (passedSoFar, test) { + return passedSoFar && test.result.failed === 0; }, true); - console.log(allTestsSuccessful ? "Test passed" : "Test failed"); - process.exit(allTestsSuccessful ? 0 : 1); + if (allTestsSuccessful) { + console.log("Tests passed"); + } else { + var failingTests = results.filter(function (test) { + return test.result.failed !== 0; + }); + var failingPlatforms = failingTests.map(function (test) { + return test.platform; + }); + + console.error("Tests failed on platforms: " + JSON.stringify(failingPlatforms)); + + failingTests.forEach(function (test) { + var platform = JSON.stringify(test.platform); + + if (test.result.failed) { + console.error(test.result.failed + " failures on " + platform + ". See " + test.url + " for details."); + } else { + console.error("Testing on " + platform + " failed; no results available. See " + test.url + " for details."); + } + }); + } + + console.log("Shutting down sauce connect tunnel..."); + tunnel.stop(function () { + process.exit(allTestsSuccessful ? 0 : 1); + }) } \ No newline at end of file