Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Add grunt task to run tests vs headless chrome #51

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ module.exports = function(grunt) {
base: '.',
port: 9998
}
},
https: {
options: {
base: '.',
port: 9998,
protocol: 'https'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is necessary because chrome has a few weird security rules:

  1. crypto apis are not available on http
  2. service workers are not available on http or file://

}
}
},
'saucelabs-mocha': {
Expand Down Expand Up @@ -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');
});
};
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}