From 210bb221a8905e0482f939a7e03256de701a60c7 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Thu, 28 Sep 2017 14:55:15 +0200 Subject: [PATCH] Use jsunitsaucelabs to run our unit tests on Saucelabs --- build/saucelabs-unit-test.js | 48 ++++++++++++++++++++++++++++++++++++ package-lock.json | 6 +++++ package.json | 3 ++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 build/saucelabs-unit-test.js diff --git a/build/saucelabs-unit-test.js b/build/saucelabs-unit-test.js new file mode 100644 index 0000000000..76576128ee --- /dev/null +++ b/build/saucelabs-unit-test.js @@ -0,0 +1,48 @@ +const JSUnitSaucelabs = require('jsunitsaucelabs') + +var jsUnitSaucelabs = new JSUnitSaucelabs({ + username: process.env.SAUCE_USERNAME, + password: process.env.SAUCE_ACCESS_KEY +}) + + +// TODO : get all the browsers in sauce_browsers.yml + +var testURL = 'http://localhost:3000/js/tests/index.html?hidepassed' +jsUnitSaucelabs.start([ + ['Windows 8', 'internet explorer', '10'] +], testURL, 'qunit', function (error, success) { + if (typeof success !== 'undefined') { + var taskIds = success['js tests'] + if (!taskIds || !taskIds.length) { + throw new Error('Error starting tests through SauceLabs API') + } + + var waitingCallback = function (error, success) { + if (error) { + console.error(error) + return + } + + if (typeof success !== 'undefined') { + if (!success.completed) { + jsUnitSaucelabs.getStatus(taskIds[0], waitingCallback) + } else { + var test = success['js tests'][0] + var 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(function (id) { + jsUnitSaucelabs.getStatus(id, waitingCallback) + }) + } +}) diff --git a/package-lock.json b/package-lock.json index 417db57fd1..65f0b24178 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3699,6 +3699,12 @@ "verror": "1.10.0" } }, + "jsunitsaucelabs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/jsunitsaucelabs/-/jsunitsaucelabs-1.0.0.tgz", + "integrity": "sha512-5/PCsSwLGMLCiA4IOlbuxOcangxnEadEZTPwGvF4sHQ+NQoPbSIbCtK4Wce1IReJiyY6fQldA2uITycXZOhqrQ==", + "dev": true + }, "kew": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", diff --git a/package.json b/package.json index 85a641b34e..9ab637cb0b 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "js-minify-bundle": "uglifyjs --compress typeofs=false --mangle --comments \"/^!/\" --output dist/js/bootstrap.bundle.min.js dist/js/bootstrap.bundle.js", "js-minify-docs": "uglifyjs --mangle --comments \"/^!/\" --output assets/js/docs.min.js assets/js/vendor/anchor.min.js assets/js/vendor/clipboard.min.js assets/js/vendor/holder.min.js assets/js/src/application.js assets/js/src/pwa.js", "js-test": "phantomjs ./node_modules/qunit-phantomjs-runner/runner.js js/tests/index.html 60", - "js-test-cloud": "ruby -r webrick -e \"s = WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd, :Logger => WEBrick::Log.new('/dev/null'), :AccessLog => []); trap('INT') { s.shutdown }; s.start\" & grunt saucelabs-qunit", + "js-test-cloud": "ruby -r webrick -e \"s = WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd, :Logger => WEBrick::Log.new('/dev/null'), :AccessLog => []); trap('INT') { s.shutdown }; s.start\" & node build/saucelabs-unit-test.js", "docs": "npm-run-all docs-compile docs-lint", "docs-lint": "htmllint --rc build/.htmllintrc _gh_pages/*.html _gh_pages/**/*.html js/tests/visual/*.html", "docs-compile": "bundle exec jekyll build", @@ -90,6 +90,7 @@ "grunt-cli": "^1.2.0", "grunt-saucelabs": "^9.0.0", "htmllint-cli": "^0.0.6", + "jsunitsaucelabs": "^1.0.0", "node-sass": "^4.5.3", "nodemon": "^1.11.0", "npm-run-all": "^4.0.2",