From 54d45072810f5cda4f3c75eba6d9acd70274a963 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 28 Sep 2017 18:18:20 +0300 Subject: [PATCH] Use sauce_browsers.json. --- build/sauce_browsers.json | 3 +- build/saucelabs-unit-test.js | 118 ++++++++++++++++++++++------------- package-lock.json | 4 +- package.json | 2 +- 4 files changed, 81 insertions(+), 46 deletions(-) diff --git a/build/sauce_browsers.json b/build/sauce_browsers.json index e5aae5eee9..b112d9c5b1 100644 --- a/build/sauce_browsers.json +++ b/build/sauce_browsers.json @@ -1,7 +1,8 @@ [ { "browserName": "safari", - "platform": "OS X 10.11" + "platform": "OS X 10.11", + "version": "latest" }, { "browserName": "chrome", diff --git a/build/saucelabs-unit-test.js b/build/saucelabs-unit-test.js index f158848a34..7607b6d948 100644 --- a/build/saucelabs-unit-test.js +++ b/build/saucelabs-unit-test.js @@ -1,54 +1,86 @@ +'use strict' + +const path = require('path') const JSUnitSaucelabs = require('jsunitsaucelabs') +// Docs: https://wiki.saucelabs.com/display/DOCS/Platform+Configurator +// Mac Opera is not currently supported by Sauce Labs +// Win Opera 15+ is not currently supported by Sauce Labs +// iOS Chrome is not currently supported by Sauce Labs + const jsUnitSaucelabs = new JSUnitSaucelabs({ username: process.env.SAUCE_USERNAME, password: process.env.SAUCE_ACCESS_KEY, build: process.env.TRAVIS_JOB_ID }) +const testURL = 'http://localhost:3000/js/tests/index.html?hidepassed' +const browsersFile = require(path.resolve(__dirname, './sauce_browsers.json')) +let jobsDone = 0 +let jobsSuccess = 0 -// TODO : get all the browsers in sauce_browsers.yml -// Docs: https://wiki.saucelabs.com/display/DOCS/Platform+Configurator -// Mac Opera is not currently supported by Sauce Labs -// Win Opera 15+ is not currently supported by Sauce Labs -// iOS Chrome is not currently supported by Sauce Labs - -const testURL = 'http://localhost:3000/js/tests/index.html?hidepassed' - -jsUnitSaucelabs.start([ - ['Windows 8', 'internet explorer', '10'] -], testURL, 'qunit', (error, success) => { - if (typeof success !== 'undefined') { - const taskIds = success['js tests'] - if (!taskIds || !taskIds.length) { - throw new Error('Error starting tests through SauceLabs API') - } - - const waitingCallback = (error, success) => { - if (error) { - console.error(error) - return - } - - if (typeof success !== 'undefined') { - if (!success.completed) { - jsUnitSaucelabs.getStatus(taskIds[0], waitingCallback) - } else { - const test = success['js tests'][0] - let passed = false - if (test.result !== null) { - passed = test.result.total === test.result.passed - } - console.log(`Tested ${testURL}`) - console.log(`Platform: ${test.platform.join(',')}`) - console.log(`Passed: ${passed.toString()}`) - console.log(`Url ${test.url}`) - } - } - } - - taskIds.forEach((id) => { - jsUnitSaucelabs.getStatus(id, waitingCallback) - }) +const waitingCallback = (error, body, id) => { + if (error) { + console.error(error) + process.exit(1) + return } + + if (typeof body !== 'undefined') { + if (!body.completed) { + setTimeout(() => { + jsUnitSaucelabs.getStatus(id, (error, body) => { + waitingCallback(error, body, id) + }) + }, 2000) + } else { + const test = body['js tests'][0] + let passed = false + + if (test.result !== null) { + passed = test.result.total === test.result.passed + } + + console.log(`Tested ${testURL}`) + console.log(`Platform: ${test.platform.join(',')}`) + console.log(`Passed: ${passed.toString()}`) + console.log(`Url ${test.url} \n`) + + if (passed) { + jobsSuccess++ + } + jobsDone++ + + // Exit + if (jobsDone === browsersFile.length - 1) { + jsUnitSaucelabs.stop() + process.exit(jobsDone === jobsSuccess ? 0 : 1) + } + } + } +} + +jsUnitSaucelabs.on('tunnelCreated', () => { + browsersFile.forEach((tmpBrowser) => { + const broPlatform = typeof tmpBrowser.platform === 'undefined' ? tmpBrowser.platformName : tmpBrowser.platform + const arrayBro = [broPlatform, tmpBrowser.browserName, tmpBrowser.version] + jsUnitSaucelabs.start([arrayBro], testURL, 'qunit', (error, success) => { + if (typeof success !== 'undefined') { + const taskIds = success['js tests'] + + if (!taskIds || !taskIds.length) { + throw new Error('Error starting tests through SauceLabs API') + } + + taskIds.forEach((id) => { + jsUnitSaucelabs.getStatus(id, (error, body) => { + waitingCallback(error, body, id) + }) + }) + } else { + console.error(error) + } + }) + }) }) +jsUnitSaucelabs.initTunnel() diff --git a/package-lock.json b/package-lock.json index cb6579f64e..f7ad2be433 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3345,7 +3345,9 @@ } }, "jsunitsaucelabs": { - "version": "git+https://github.com/Johann-S/JSUnitSaucelabs.git#3847edd62151076e26b4d4af9815d6d5edc64e66", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/jsunitsaucelabs/-/jsunitsaucelabs-1.2.0.tgz", + "integrity": "sha512-Jgqe0+XRvnkF4r6fmfwsEC8DC38EgsCU7XCGGJ8Y+G1ze38isLmzTlCSNwyG/NNJuYivbABauwCk53KAne1cLQ==", "dev": true, "requires": { "sauce-tunnel": "2.5.0" diff --git a/package.json b/package.json index 067646c362..1d5d1d9821 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "eslint": "^4.2.0", "eslint-plugin-compat": "^1.0.4", "htmllint-cli": "^0.0.6", - "jsunitsaucelabs": "^1.1.0", + "jsunitsaucelabs": "^1.2.0", "node-sass": "^4.5.3", "nodemon": "^1.11.0", "npm-run-all": "^4.0.2",