From 87297d2a07dc7b956699eeb1d96b1edbfc46025c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 31 Oct 2013 00:02:47 -0700 Subject: [PATCH] Cleanup saucelabs.js round two. --- test/saucelabs.js | 215 +++++++++++++++++++++++----------------------- 1 file changed, 109 insertions(+), 106 deletions(-) diff --git a/test/saucelabs.js b/test/saucelabs.js index 3e2178884..d1bac363b 100644 --- a/test/saucelabs.js +++ b/test/saucelabs.js @@ -1,124 +1,127 @@ -var connect = require('connect'), - path = require('path'), - request = require('request'), - SauceTunnel = require('sauce-tunnel'); +;(function() { + 'use strict'; -var port = 8081, - username = process.env.SAUCE_USERNAME, - accessKey = process.env.SAUCE_ACCESS_KEY; -console.log(process.env) -var platforms = [ - ['Windows 7', 'chrome', ''], - ['Windows 7', 'firefox', '24'], - ['Windows 7', 'firefox', '20'], - ['Windows 7', 'firefox', '10'], - ['Windows 7', 'firefox', '6'], - ['Windows 7', 'firefox', '4'], - ['Windows 7', 'firefox', '3'], - ['Windows 7', 'internet explorer', '10'], - ['Windows 7', 'internet explorer', '9'], - ['Windows 7', 'internet explorer', '8'], - ['Windows XP', 'internet explorer', '7'], - ['Windows XP', 'internet explorer', '6'], - ['OS X 10.8', 'safari', '6'], - ['Windows 7', 'safari', '5'] -]; + var connect = require('connect'), + path = require('path'), + request = require('request'), + SauceTunnel = require('sauce-tunnel'); -// create a web server for the local dir -var server = connect.createServer( - connect.static(path.resolve(__dirname, '..')) -).listen(port); + var port = 8081, + username = process.env.SAUCE_USERNAME, + accessKey = process.env.SAUCE_ACCESS_KEY; -// set up sauce connect so we can use this server from saucelabs -var tunnelTimeout = 10000, - tunnel = new SauceTunnel(username, accessKey, null, true, tunnelTimeout); + var platforms = [ + ['Windows 7', 'chrome', ''], + ['Windows 7', 'firefox', '25'], + ['Windows 7', 'firefox', '20'], + ['Windows 7', 'firefox', '10'], + ['Windows 7', 'firefox', '6'], + ['Windows 7', 'firefox', '4'], + ['Windows 7', 'firefox', '3'], + ['Windows 7', 'internet explorer', '10'], + ['Windows 7', 'internet explorer', '9'], + ['Windows 7', 'internet explorer', '8'], + ['Windows XP', 'internet explorer', '7'], + ['Windows XP', 'internet explorer', '6'], + ['OS X 10.8', 'safari', '6'], + ['Windows 7', 'safari', '5'] + ]; -console.log('Opening sauce connect tunnel...'); + // create a web server for the local dir + var server = connect.createServer( + connect.static(path.resolve(__dirname, '..')) + ).listen(port); -tunnel.start(function(success) { - if (success) { - console.log('Sauce connect tunnel opened'); - runTests(); - } else { - console.error('Failed to open sauce connect tunnel') - process.exit(2); - } -}); + // set up sauce connect so we can use this server from saucelabs + var tunnelTimeout = 10000, + tunnel = new SauceTunnel(username, accessKey, null, true, tunnelTimeout); -function runTests() { - var testDefinition = { - 'framework': 'qunit', - 'platforms': platforms, - 'url': 'http://localhost:' + port + '/test/index.html' - }; + console.log('Opening sauce connect tunnel...'); - 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); + tunnel.start(function(success) { + if (success) { + console.log('Sauce connect tunnel opened'); + runTests(); } else { - console.error('Failed to submit test to SauceLabs, status ' + response.statusCode + ', body:\n' + JSON.stringify(body)); - process.exit(3); + console.error('Failed to open sauce connect tunnel') + process.exit(2); } }); -} -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) { + function runTests() { + var testDefinition = { + 'framework': 'qunit', + 'platforms': platforms, + 'url': 'http://localhost:' + port + '/test/index.html' + }; + + 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) { - if (body.completed) { - handleTestResults(body['js tests']); + 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) { + if (body.completed) { + handleTestResults(body['js tests']); + } else { + waitForTestCompletion(testIdentifier); + } } else { - waitForTestCompletion(testIdentifier); + console.error('Failed to check test status on SauceLabs, status ' + response.statusCode + ', body:\n' + JSON.stringify(body)); + process.exit(4); } - } 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, test) { - return passedSoFar && test.result.failed === 0; - }, true); - - 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...'); + function handleTestResults(results) { + var allTestsSuccessful = results.every(function(test) { + return !test.result.failed; + }); - tunnel.stop(function() { - process.exit(allTestsSuccessful ? 0 : 1); - }) -} + if (allTestsSuccessful) { + console.log('Tests passed'); + } + else { + var failingTests = results.filter(function(test) { + return test.result.failed; + }); + + 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); + }); + } +}());