From b940e78a90266cc5d540e7c922c4e858b2008361 Mon Sep 17 00:00:00 2001 From: cwmoo740 Date: Sat, 12 May 2018 18:43:01 -0400 Subject: [PATCH 1/4] test: add local testing feature using headless chrome allows running tests against latest chrome without sauce labs --- Gruntfile.js | 32 ++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index e328d94..033ac27 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -162,6 +162,13 @@ module.exports = function(grunt) { base: '.', port: 9998 } + }, + https: { + options: { + base: '.', + port: 9998, + protocol: 'https' + } } }, 'saucelabs-mocha': { @@ -225,5 +232,30 @@ module.exports = function(grunt) { grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']); grunt.registerTask('default', ['concat']); grunt.registerTask('build', ['compile', 'concat']); + grunt.registerTask('localTest', function () { + const {runner} = require('mocha-headless-chrome'); + grunt.event.once('connect.https.listening', async (host, port) => { + const done = this.async(); + const url = `https://${host}:${port}/test`; + const options = { + file: url, + timeout: 120000, + args: ['no-sandbox'] + }; + runner(options) + .then(({result: {failures}})=> { + if (failures && failures.length) { + done(new Error(failures.map(failure => `${failure.fullTitle}: ${failure.err.stack}`).join('\n') + '\n')); + } else { + done(); + } + }) + .catch(err => { + grunt.log.writeln(err); + done(err); + }); + }); + grunt.task.run('connect:https:keepalive'); + }); }; diff --git a/package.json b/package.json index 4136cc5..ad73a75 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "grunt-preen": "^1.0.0", "grunt-saucelabs": "^8.3.3", "jquery": "^2.2.3", - "mocha": "^2.4.5" + "mocha": "^2.4.5", + "mocha-headless-chrome": "^2.0.0" }, "scripts": { "test": "grunt test", From 5f64ffa49e207a04a0e7901be02d31c379fc8228 Mon Sep 17 00:00:00 2001 From: Nick Weingartner Date: Thu, 10 May 2018 21:44:12 -0400 Subject: [PATCH 2/4] Update README to include testing details. Fixes #9 and #49. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 2eec11f..278eb3f 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,14 @@ To compile curve25519 from C souce files in `/native`, install grunt compile ``` +## Testing + +In order to run the automated tests, you must sign up for a [SauceLabs](https://saucelabs.com/) account, and use your username and access code to run the test. Once these are generated, include them in the test command. + +``` +SAUCE_USERNAME="your-usrname" SAUCE_ACCESS_KEY="your-access-key" grunt test +``` + ## License Copyright 2015-2018 Open Whisper Systems From e8b711aa90e0fd3e27cf46333f5333ea4921e921 Mon Sep 17 00:00:00 2001 From: cwmoo740 Date: Sat, 12 May 2018 18:46:13 -0400 Subject: [PATCH 3/4] docs: notes on local testing vs headless chrome --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 278eb3f..d38d3a6 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,12 @@ In order to run the automated tests, you must sign up for a [SauceLabs](https:// SAUCE_USERNAME="your-usrname" SAUCE_ACCESS_KEY="your-access-key" grunt test ``` +There is also a task to run tests against headless chrome locally: `grunt localTest`. + +For information on how to configure options, please see: + +[mocha-headless-chrome](https://www.npmjs.com/package/mocha-headless-chrome) + ## License Copyright 2015-2018 Open Whisper Systems From 7892f84ae0f6e753e7666954ce6dd5cf982a5749 Mon Sep 17 00:00:00 2001 From: cwmoo740 Date: Sat, 12 May 2018 18:48:34 -0400 Subject: [PATCH 4/4] refactor: rename localTest script to testLocal --- Gruntfile.js | 2 +- README.md | 4 +++- package.json | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 033ac27..1eec68b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -232,7 +232,7 @@ module.exports = function(grunt) { grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']); grunt.registerTask('default', ['concat']); grunt.registerTask('build', ['compile', 'concat']); - grunt.registerTask('localTest', function () { + grunt.registerTask('testLocal', ['jshint', 'jscs'], function () { const {runner} = require('mocha-headless-chrome'); grunt.event.once('connect.https.listening', async (host, port) => { diff --git a/README.md b/README.md index d38d3a6..35f20ad 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,9 @@ In order to run the automated tests, you must sign up for a [SauceLabs](https:// SAUCE_USERNAME="your-usrname" SAUCE_ACCESS_KEY="your-access-key" grunt test ``` -There is also a task to run tests against headless chrome locally: `grunt localTest`. +There is also a task to run tests against headless chrome locally: + +`grunt testLocal` or `yarn run testLocal` For information on how to configure options, please see: diff --git a/package.json b/package.json index ad73a75..7f42d60 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "scripts": { "test": "grunt test", + "testLocal": "grunt testLocal", "lint": "grunt jshint" } }