Erik
Start running your client Jasmine
tests headlessly with Headless Chrome and gulp
today.
When should I use Erik?
You should use Erik when you have a suite of client Jasmine tests that you currently run by opening a SpecRunner.html
file but would prefer to run headlessly via a gulp
task.
Erik utilizes Karma to run your Jasmine tests with Headless Chrome.
It abstracts away Karma's details and configuration so that you can begin running your tests with Headless Chrome quickly and easily.
Simply adapt the below example configuration for your use.
Installation
$ npm install -D erik
or
$ npm install --save-dev erik
Can I use this with my CI platform
?
Yes! Erik's exit code is determined by the outcome of your test suite, so integration with your CI platform should be easy.
Notes on our assumed configuration (or, "How we make it easy for you")
Fetching remote dependencies
We use gulp-remote-src
to fetch the remote dependencies that currently live in your SpecRunner.html
script
tags.
No Karma-configured pre-processing
If you're like us, you already have gulp
tasks for bundling (and perhaps transpiling) your test suite along with its dependencies. It's easier to keep that configuration and simply pass the path of your bundled, transpiled test suite than it is to duplicate that configuration with Karma preprocessing. Additionally, we've disabled Karma's default preprocessing of coffeescript
files.
The mocha
reporter
Karma's default progress
reporter isn't quite as nice as the report shown by Jasmine. Erik uses karma-mocha-reporter
so that you can see a similar, friendly, hierarchical overview of your specs as they complete.
Example usage
(in your gulpfile
)
const SHOULD_WATCH = !!argv.watch;
new Erik({
gulp,
watch: SHOULD_WATCH,
taskDependencies: [
'build-spec-bundle',
'bower'
],
localDependencies: [
'public/build-lib.js',
'public/lib/ext/**/*',
'spec/client/tests.js',
],
remoteDependencies: [
'https://cdn.jsdelivr.net/g/es6.shim@0.35.3',
'https://cdn.jsdelivr.net/g/jquery@2.1.4',
'https://cdn.jsdelivr.net/g/underscorejs@1.8.3',
],
karmaConfig: {
port: 1337
},
bundlePath: 'spec/client'
});
gulp.on('task_start', function(e) {
if (e.task === 'erik') {
if (SHOULD_WATCH) {
console.log('Watching tests…');
gulp.watch(TEST_FILES, ['build-spec-bundle']);
}
}
});
Run your test suite!
$ gulp erik [--watch]
Testing on other browsers
Should you desire to use a browser other than Headless Chrome, you can do so by providing a browsers
array in the karmaConfig
object. Note that you'll need to install the appropriate browser plugins for Karma.
new Erik({
gulp,
...
karmaConfig: {
port: 1337,
browsers: ['Chrome', 'Firefox']
}
});
Contributing
We welcome pull requests! Please lint your code using the JSHint configuration in this project.
Release history
- 3.1.0 Add support for the
customLaunchers
Karma field
- 3.0.0 Fail on empty test suites.
- 2.0.0 Replace PhantomJS with Headless Chrome.
- 1.2.1 Allow browser configuration by browsers array.
- 1.2.0 Work around Karma bug to support
console.log
output among test cases as they run.
- 1.1.2 Don't fail when the test suite run is empty.
- 1.1.1 Documentation updates. Require non-empty
options.localDependencies
argument.
- 1.1.0 Re-run specs on any local dependency changes. Wrap
options.bundledSpecPath
into options.localDependencies
, deprecating options.bundledSpecPath
.
- 1.0.3 Don't specify exact dependency versions.
- 1.0.2 Add event-based watch example.
- 1.0.1 Move dependencies to be non-dev dependencies.
- 1.0.0 Initial release.
Etymology
Erik is the name of the Phantom in Phantom of the Opera :D. This library used to use PhantomJS instead of Headless Chrome.