diff --git a/Gruntfile.js b/Gruntfile.js index e328d94..1eec68b 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('testLocal', ['jshint', 'jscs'], 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/README.md b/README.md index 2eec11f..35f20ad 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,22 @@ 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 +``` + +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: + +[mocha-headless-chrome](https://www.npmjs.com/package/mocha-headless-chrome) + ## License Copyright 2015-2018 Open Whisper Systems diff --git a/package.json b/package.json index 4136cc5..7f42d60 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,12 @@ "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", + "testLocal": "grunt testLocal", "lint": "grunt jshint" } }