2012-11-02 13:03:09 +08:00
# grunt-contrib-jasmine [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-contrib-jasmine.png?branch=master)](http://travis-ci.org/gruntjs/grunt-contrib-jasmine)
> Run jasmine specs headlessly through PhantomJS.
2013-02-16 07:53:59 +08:00
2012-11-02 13:03:09 +08:00
## Getting Started
2013-02-18 21:42:28 +08:00
This plugin requires Grunt `~0.4.0`
2013-02-16 07:53:59 +08:00
If you haven't used [Grunt ](http://gruntjs.com/ ) before, be sure to check out the [Getting Started ](http://gruntjs.com/getting-started ) guide, as it explains how to create a [Gruntfile ](http://gruntjs.com/sample-gruntfile ) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
2012-11-02 13:03:09 +08:00
2012-12-03 16:17:06 +08:00
```shell
2012-11-02 13:03:09 +08:00
npm install grunt-contrib-jasmine --save-dev
```
2013-02-21 01:42:59 +08:00
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
2013-02-18 21:42:28 +08:00
```js
grunt.loadNpmTasks('grunt-contrib-jasmine');
```
2013-02-16 07:53:59 +08:00
2012-11-02 13:03:09 +08:00
2012-12-03 16:17:06 +08:00
## Jasmine task
_Run this task with the `grunt jasmine` command._
2012-11-02 13:03:09 +08:00
2013-02-16 07:53:59 +08:00
Automatically builds and maintains your spec runner and runs your tests headlessly through phantomjs.
2012-11-02 13:03:09 +08:00
Substantial credit goes to [Camille Reynders ](http://creynders.be/ ) (@creynders) for the first decent implementation
of jasmine through grunt which served as motivation for all the future work.
#### Run specs locally or on an ad hoc server
Run your tests on your local filesystem or via a server task like [grunt-contrib-connect][].
2013-06-16 02:15:01 +08:00
#### Customize your SpecRunner with templates
2012-11-02 13:03:09 +08:00
2013-06-16 02:15:01 +08:00
Supply your templates that will be used to automatically build the SpecRunner.
2012-11-02 13:03:09 +08:00
2013-06-16 02:15:01 +08:00
##### AMD Support
2012-11-02 13:03:09 +08:00
2013-06-16 02:15:01 +08:00
Supports AMD tests via the [grunt-template-jasmine-requirejs ](https://github.com/jsoverson/grunt-template-jasmine-requirejs ) module
2012-11-02 13:03:09 +08:00
2013-06-16 02:15:01 +08:00
##### Third party templates
2013-03-01 22:58:22 +08:00
- [RequireJS ](https://github.com/jsoverson/grunt-template-jasmine-requirejs )
- [Code coverage output with Istanbul ](https://github.com/maenu/grunt-template-jasmine-istanbul )
- [StealJS ](https://github.com/jaredstehler/grunt-template-jasmine-steal )
2012-11-02 13:03:09 +08:00
[grunt-contrib-connect]: https://github.com/gruntjs/grunt-contrib-connect
2012-11-02 13:03:09 +08:00
### Options
2012-11-02 13:03:09 +08:00
#### src
Type: `String|Array`
2013-03-11 13:15:29 +08:00
*Minimatch* - Your source files. These are the files that you are testing.
2012-11-02 13:03:09 +08:00
2012-11-02 13:03:09 +08:00
#### options.specs
Type: `String|Array`
2012-11-02 13:03:09 +08:00
2013-03-11 13:15:29 +08:00
*Minimatch* - Your Jasmine specs.
2012-11-02 13:03:09 +08:00
2012-11-02 13:03:09 +08:00
#### options.vendor
Type: `String|Array`
2012-11-02 13:03:09 +08:00
2013-03-11 13:15:29 +08:00
*Minimatch* - Third party libraries, generally loaded before anything else happens in your tests. Libraries
like jQuery and Backbone.
2012-11-02 13:03:09 +08:00
2012-11-02 13:03:09 +08:00
#### options.helpers
Type: `String|Array`
2012-11-02 13:03:09 +08:00
2013-03-11 13:15:29 +08:00
*Minimatch* - Non-source, non-spec helper files. In the default runner these are loaded after `vendor` files
#### options.styles
Type: `String|Array`
*Minimatch* - CSS files that get loaded after the jasmine.css
2012-11-02 13:03:09 +08:00
2013-04-05 01:57:11 +08:00
#### options.version
2013-06-16 03:25:30 +08:00
Type: `String`
2013-04-05 01:57:11 +08:00
Default: '1.3.1'
This is the jasmine-version which will be used. currently available versions are:
* 1.0.0
* 1.1.0
* 1.2.0
* 1.3.0
* 1.3.1
2012-11-02 13:03:09 +08:00
#### options.outfile
2013-06-16 03:25:30 +08:00
Type: `String`
2012-11-02 13:03:09 +08:00
Default: `_SpecRunner.html`
2012-11-02 13:03:09 +08:00
2013-03-11 13:15:29 +08:00
The auto-generated specfile that phantomjs will use to run your tests.
Automatically deleted upon normal runs
2013-01-09 03:28:26 +08:00
2013-04-13 08:47:13 +08:00
#### options.keepRunner
2013-06-16 03:25:30 +08:00
Type: `Boolean`
Default: `false`
2013-04-13 08:47:13 +08:00
Prevents the auto-generated specfile used to run your tests from being automatically deleted.
2013-01-09 03:28:26 +08:00
#### options.junit.path
2013-06-16 03:25:30 +08:00
Type: `String`
2013-01-09 03:28:26 +08:00
Default: undefined
Path to output JUnit xml
#### options.junit.consolidate
2013-06-16 03:25:30 +08:00
Type: `Boolean`
2013-01-09 03:28:26 +08:00
Default: `false`
Consolidate the JUnit XML so that there is one file per top level suite.
2012-11-02 13:03:09 +08:00
#### options.host
2013-06-16 03:25:30 +08:00
Type: `String`
2012-11-02 13:03:09 +08:00
Default: ''
2013-03-11 13:15:29 +08:00
The host you want phantomjs to connect against to run your tests.
2012-11-02 13:03:09 +08:00
e.g. if using an ad hoc server from within grunt
2012-11-02 13:03:09 +08:00
```js
2012-12-03 16:17:06 +08:00
host : 'http://127.0.0.1:8000/'
2012-11-02 13:03:09 +08:00
```
Or, using templates
```js
2012-12-03 16:17:06 +08:00
host : 'http://127.0.0.1:< %= connect.port %>/'
2012-11-02 13:03:09 +08:00
```
Not defining a host will mean your specs will be run from the local filesystem.
#### options.template
2013-06-16 03:25:30 +08:00
Type: `String` `Object`
2013-01-09 03:28:26 +08:00
Default: undefined
2012-11-02 13:03:09 +08:00
2013-03-11 13:15:29 +08:00
Custom template used to generate your Spec Runner. Parsed as underscore templates and provided
2012-11-02 13:03:09 +08:00
the expanded list of files needed to build a specrunner.
2013-01-09 03:28:26 +08:00
You can specify an object with a `process` method that will be called as a template function.
2013-01-10 13:14:50 +08:00
See the [Template API Documentation ](https://github.com/gruntjs/grunt-contrib-jasmine/wiki/Jasmine-Templates ) for more details.
2013-01-09 03:28:26 +08:00
2012-11-02 13:03:09 +08:00
#### options.templateOptions
2013-06-16 03:25:30 +08:00
Type: `Object`
2012-11-02 13:03:09 +08:00
Default: `{}`
2013-03-11 13:15:29 +08:00
Options that will be passed to your template via an 'options' hash. Used to pass settings to the template.
2012-11-02 13:03:09 +08:00
2012-11-09 08:57:30 +08:00
### Flags
Name: `build`
2013-03-11 13:15:29 +08:00
Turn on this flag in order to rebuild the specrunner without deleting it. This is useful when troubleshooting templates,
2012-12-03 16:17:06 +08:00
running in a browser, or as part of a watch chain e.g.
2012-11-09 08:57:30 +08:00
```js
2012-12-03 16:17:06 +08:00
watch: {
pivotal : {
files: ['src/**/*.js', 'specs/**/*.js'],
tasks: 'jasmine:pivotal:build'
2012-11-09 08:57:30 +08:00
}
2012-12-03 16:17:06 +08:00
}
2012-11-09 08:57:30 +08:00
```
2013-06-16 02:15:01 +08:00
#### Example application usage
- [Pivotal Labs' sample application ](https://github.com/jsoverson/grunt-contrib-jasmine-example )
2012-11-02 13:03:09 +08:00
#### Basic Use
2012-11-02 13:03:09 +08:00
Sample configuration to run Pivotal Labs' example Jasmine application.
```js
2012-12-03 16:17:06 +08:00
// Example configuration
grunt.initConfig({
jasmine: {
pivotal: {
2013-02-23 02:06:43 +08:00
src: 'src/**/*.js',
2012-12-03 16:17:06 +08:00
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js'
}
2012-11-02 13:03:09 +08:00
}
}
2013-02-23 02:06:43 +08:00
});
2012-11-02 13:03:09 +08:00
```
#### Supplying a custom template
Supplying a custom template to the above example
```js
2012-12-03 16:17:06 +08:00
// Example configuration
grunt.initConfig({
jasmine: {
customTemplate: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
2013-04-05 01:57:11 +08:00
helpers: 'spec/*Helper.js',
2012-12-03 16:17:06 +08:00
template: 'custom.tmpl'
}
2012-11-02 13:03:09 +08:00
}
}
2013-02-23 02:06:43 +08:00
});
2012-11-02 13:03:09 +08:00
```
2013-01-10 13:14:50 +08:00
#### Sample RequireJS/NPM Template usage
2012-11-02 13:03:09 +08:00
2013-01-10 13:14:50 +08:00
```js
// Example configuration
grunt.initConfig({
jasmine: {
yourTask: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
template: require('grunt-template-jasmine-requirejs')
}
}
}
2013-02-23 02:06:43 +08:00
});
2013-01-10 13:14:50 +08:00
```
NPM Templates are just node modules, so you can write and treat them as such.
Please see the [grunt-template-jasmine-requirejs ](https://github.com/jsoverson/grunt-template-jasmine-requirejs ) documentation
for more information on the RequireJS template.
2012-11-02 13:03:09 +08:00
2012-11-02 13:03:09 +08:00
## Release History
2013-06-16 03:25:30 +08:00
* 2013-06-15 v0.5.0 updated rimraf made teardown async, added Function.prototype.bind polyfill [object Object] [object Object]
2013-06-16 00:38:39 +08:00
* 2013-04-03 v0.4.2 bumped grunt-lib-phantomjs to 0.3.0/1.9 (closes merged addressed
* 2013-03-08 v0.4.0 bumped grunt-lib-phantomjs to 0.2.0/1.8 allowed spec/vendor/helper list to return non-matching files (e.g. for remote, http) merged merged
* 2013-02-24 v0.3.3 Added better console output (via Gabor Kiss @Neverl )
* 2013-02-17 v0.3.2 Ensure Gruntfile.js is included on npm.
* 2013-02-15 v0.3.1 First official release for Grunt 0.4.0.
* 2013-01-22 v0.3.1rc7 Exposed phantom and sendMessage to templates
* 2013-01-22 v0.3.0rc7 Updated dependencies for grunt v0.4.0rc6/rc7
* 2013-01-08 v0.3.0rc5 Updating to work with grunt v0.4.0rc5. Switching to this.filesSrc api. Added JUnit xml output (via Kelvin Luck @vitch ) Passing console.log from browser to verbose grunt logging Support for templates as separate node modules Removed internal requirejs template (see grunt-template-jasmine-requirejs)
* 2012-12-03 v0.2.0 Generalized requirejs template config Added loader plugin Tests for templates Updated jasmine to 1.3.0
* 2012-11-24 v0.1.2 Updated for new grunt/grunt-contrib apis
* 2012-11-07 v0.1.1 Fixed race condition in requirejs template
* 2012-11-07 v0.1.0 Ported grunt-jasmine-runner and grunt-jasmine-task to grunt-contrib
2012-12-03 16:17:06 +08:00
---
2012-11-02 13:03:09 +08:00
2012-12-03 16:17:06 +08:00
Task submitted by [Jarrod Overson ](http://jarrodoverson.com )
2012-11-02 13:03:09 +08:00
2013-06-16 03:25:30 +08:00
*This file was generated on Sat Jun 15 2013 12:25:20.*