grunt-contrib-jasmine/README.md

362 lines
12 KiB
Markdown
Raw Normal View History

2017-01-13 02:10:10 +08:00
# grunt-contrib-jasmine v1.1.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-jasmine.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-jasmine) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/5985958by5rhnh31/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-jasmine/branch/master)
2012-11-02 13:03:09 +08:00
2015-07-10 23:56:47 +08:00
> Run jasmine specs headlessly through PhantomJS
2012-11-02 13:03:09 +08:00
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
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
```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
## Jasmine task
_Run this task with the `grunt jasmine` command._
2012-11-02 13:03:09 +08:00
2014-01-30 00:51:59 +08:00
Automatically builds and maintains your spec runner and runs your tests headlessly through PhantomJS.
2014-01-30 00:51:59 +08:00
#### Run specs locally or on a remote server
Run your tests on your local filesystem or via a server task like [grunt-contrib-connect][].
#### Customize your SpecRunner with templates
2014-01-30 00:51:59 +08:00
Use your own SpecRunner templates to customize how `grunt-contrib-jasmine` builds the SpecRunner. See the
[wiki](https://github.com/gruntjs/grunt-contrib-jasmine/wiki/Jasmine-Templates) for details and third party templates for examples.
##### AMD Support
Supports AMD tests via the [grunt-template-jasmine-requirejs](https://github.com/jsoverson/grunt-template-jasmine-requirejs) module
##### Third party templates
- [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)
[grunt-contrib-connect]: https://github.com/gruntjs/grunt-contrib-connect
2012-11-02 13:03:09 +08:00
### Options
#### src
Type: `String|Array`
Your source files. These are the files that you are testing. If you are using RequireJS your source files will be loaded as dependencies into your spec modules and will not need to be placed here.
2012-11-02 13:03:09 +08:00
#### options.specs
Type: `String|Array`
2012-11-02 13:03:09 +08:00
2014-01-30 00:51:59 +08:00
Your Jasmine specs.
2012-11-02 13:03:09 +08:00
#### options.vendor
Type: `String|Array`
2012-11-02 13:03:09 +08:00
2014-01-30 00:51:59 +08:00
Third party libraries like jQuery & generally anything loaded before source, specs, and helpers.
2012-11-02 13:03:09 +08:00
#### options.helpers
Type: `String|Array`
2012-11-02 13:03:09 +08:00
2014-01-30 00:51:59 +08:00
Non-source, non-spec helper files. In the default runner these are loaded after `vendor` files
#### options.styles
Type: `String|Array`
2014-01-30 00:51:59 +08:00
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
2016-01-26 23:59:23 +08:00
Type: `String`
2016-01-26 23:59:41 +08:00
Default: `'2.2.0'`
2013-04-05 01:57:11 +08:00
This is the jasmine-version which will be used. currently available versions are:
2016-01-26 23:59:23 +08:00
* 2.2.0
2014-07-24 05:32:40 +08:00
* 2.0.1
2014-01-30 00:51:59 +08:00
* 2.0.0
*Due to changes in Jasmine, pre-2.0 versions have been dropped and tracking will resume at 2.0.0*
2013-04-05 01:57:11 +08:00
#### options.tempDir
Type: `String`
Default: `.grunt/grunt-contrib-jasmine`
The temporary directory that runners use to load jasmine files.
Automatically deleted upon normal runs.
#### options.outfile
2013-06-16 03:25:30 +08:00
Type: `String`
Default: `_SpecRunner.html`
2012-11-02 13:03:09 +08:00
The auto-generated specfile that phantomjs will use to run your tests.
2014-01-30 00:51:59 +08:00
Automatically deleted upon normal runs. Use the `:build` flag to generate a SpecRunner manually e.g.
`grunt jasmine:myTask:build`
#### options.keepRunner
2013-06-16 03:25:30 +08:00
Type: `Boolean`
Default: `false`
Prevents the auto-generated specfile used to run your tests from being automatically deleted.
#### options.junit.path
2013-06-16 03:25:30 +08:00
Type: `String`
2016-01-26 23:43:37 +08:00
Default: `undefined`
Path to output JUnit xml
#### options.junit.consolidate
2013-06-16 03:25:30 +08:00
Type: `Boolean`
Default: `false`
Consolidate the JUnit XML so that there is one file per top level suite.
2014-06-01 12:18:53 +08:00
#### options.junit.template
Type: `String`
2016-01-26 23:43:37 +08:00
Default: `undefined`
2014-06-01 12:18:53 +08:00
Specify a custom JUnit template instead of using the default `junitTemplate`.
#### options.host
2013-06-16 03:25:30 +08:00
Type: `String`
2016-01-26 23:43:37 +08:00
Default: `''`
2014-01-30 00:51:59 +08:00
The host you want PhantomJS to connect against to run your tests.
e.g. if using an ad hoc server from within grunt
2012-11-02 13:03:09 +08:00
```js
host : 'http://127.0.0.1:8000/'
```
2014-01-30 00:51:59 +08:00
Without a `host`, your specs will be run from the local filesystem.
#### options.template
2013-06-16 03:25:30 +08:00
Type: `String` `Object`
2016-01-26 23:43:37 +08:00
Default: `undefined`
Custom template used to generate your Spec Runner. Parsed as underscore templates and provided
the expanded list of files needed to build a specrunner.
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.
#### options.templateOptions
2013-06-16 03:25:30 +08:00
Type: `Object`
Default: `{}`
2014-01-30 00:51:59 +08:00
Options that will be passed to your template. Used to pass settings to the template.
2014-09-18 10:12:42 +08:00
#### options.polyfills
Type: `String|Array`
2016-04-25 08:10:03 +08:00
Third party polyfill libraries like json2 that are loaded at the very top before anything else.
2014-09-18 10:12:42 +08:00
#### options.display
Type: `String`
2016-01-26 23:43:37 +08:00
Default: `'full'`
* `full` displays the full specs tree
* `short` only displays a success or failure character for each test (useful with large suites)
2014-06-08 06:07:02 +08:00
* `none` displays nothing
2014-02-28 06:06:29 +08:00
#### options.summary
Type: `Boolean`
Default: `false`
Display a list of all failed tests and their failure messages
### Flags
Name: `build`
2014-01-30 00:51:59 +08:00
Turn on this flag in order to build a SpecRunner html file. This is useful when troubleshooting templates,
running in a browser, or as part of a watch chain e.g.
```js
watch: {
pivotal : {
files: ['src/**/*.js', 'specs/**/*.js'],
tasks: 'jasmine:pivotal:build'
}
}
```
2013-09-03 02:03:05 +08:00
### Filtering specs
**filename**
`grunt jasmine --filter=foo` will run spec files that have `foo` in their file name.
**folder**
`grunt jasmine --filter=/foo` will run spec files within folders that have `foo*` in their name.
**wildcard**
`grunt jasmine --filter=/*-bar` will run anything that is located in a folder `*-bar`
**comma separated filters**
`grunt jasmine --filter=foo,bar` will run spec files that have `foo` or `bar` in their file name.
**flags with space**
`grunt jasmine --filter="foo bar"` will run spec files that have `foo bar` in their file name.
`grunt jasmine --filter="/foo bar"` will run spec files within folders that have `foo bar*` in their name.
#### 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
Sample configuration to run Pivotal Labs' example Jasmine application.
```js
// Example configuration
grunt.initConfig({
jasmine: {
pivotal: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js'
}
}
}
});
```
#### Supplying a custom template
Supplying a custom template to the above example
```js
// 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',
template: 'custom.tmpl'
}
}
}
});
```
2014-03-20 07:21:24 +08:00
#### Supplying template modules and vendors
A complex version for the above example
```js
// Example configuration
grunt.initConfig({
jasmine: {
customTemplate: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js',
2016-01-26 23:43:37 +08:00
template: require('exports-process.js'),
2014-03-20 07:21:24 +08:00
vendor: [
2016-04-07 15:30:01 +08:00
'vendor/*.js',
'http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'
2014-03-20 07:21:24 +08:00
]
}
}
}
});
```
2013-01-10 13:14:50 +08:00
#### Sample RequireJS/NPM Template usage
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-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.
#### Keeping temp files in an existing directory
Supplying a custom temp directory
```js
// Example configuration
grunt.initConfig({
jasmine: {
pivotal: {
src: 'src/**/*.js',
options: {
keepRunner: true,
tempDir: 'bin/jasmine/',
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js'
}
}
}
});
```
2012-11-02 13:03:09 +08:00
## Release History
2017-01-13 02:10:10 +08:00
* 2017-01-12v1.1.0adds `tempDir` option. locks jasmine version
2016-04-08 00:22:49 +08:00
* 2016-04-07v1.0.3Move to a non-deprecated sprintf.
2016-04-08 00:11:25 +08:00
* 2016-04-07v1.0.2Fix sprintf issues in error calls.
2016-04-07 15:30:01 +08:00
* 2016-04-07v1.0.1Allow to use custom bootfile. Doc updates. Fix and use lodash directly.
2016-03-19 01:31:28 +08:00
* 2016-01-26v1.0.0Bump grunt-lib-phantomjs to 1.0.0. Bump jasmine to 2.2.0.
* 2015-09-24v0.9.2Fixes npm@3 issues.
* 2015-09-04v0.9.1Fix summary logging.
* 2015-07-10v0.9.0Fix deprecated package.json licenses. Fix Phantomjs dependency to include correct phantom kill.
2015-01-09 05:19:06 +08:00
* 2015-01-08v0.8.2Fixes to test summary reporting.
2016-03-19 01:31:28 +08:00
* 2014-10-20v0.8.1Now removes listeners when using the build flag. Adds handler for `fail.load`.
* 2014-07-26v0.8.0Plugin now uses Jasmine 2.0.4 from npm. Updates other dependencies. Added `options.polyfills`.
* 2014-07-26v0.7.0Merged #153 to add stack trace to summary. Updated for Jasmine 2.0.1. Merged #133 for minimal output. Merged #139 changing file exclusion logic.
* 2014-05-31v0.6.5Option to allow specifying a `junitTemplate`.
2014-04-29 03:49:12 +08:00
* 2014-04-28v0.6.4Indent level fix. Moved scripts inside the body tag.
2016-03-19 01:31:28 +08:00
* 2014-01-29v0.6.0Jasmine 2.0.0 support. Improved logging support. Various merges/bugfixes.
* 2013-08-02v0.5.2Fixed breakage with iframes / #44. Added filter flag / #70. Fixed junit failure output / #77.
* 2013-06-18v0.5.1Merged #69: grunt async not called when tests fail or `keepRunner` is true.
* 2013-06-15v0.5.0Updated rimraf. Made teardown async. Added Function.prototype.bind polyfill. Breaking (templates) changed input options for `getRelativeFileList`. Breaking (usage) failing task on phantom error (SyntaxError, TypeError, et al).
* 2013-04-03v0.4.2Updated grunt-lib-phantomjs to 0.3.0/1.9 (closes #45). Merged #38, #51. Addressed #40, #43, #48, #45.
* 2013-03-08v0.4.0Updated 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 #30, #34.
* 2013-02-24v0.3.3Added better console output (via Gabor Kiss @Neverl).
2013-06-16 00:38:39 +08:00
* 2013-02-17v0.3.2Ensure Gruntfile.js is included on npm.
* 2013-02-15v0.3.1First official release for Grunt 0.4.0.
* 2013-01-22v0.3.1rc7Exposed phantom and sendMessage to templates
* 2013-01-22v0.3.0rc7Updated dependencies for grunt v0.4.0rc6/rc7
2016-03-19 01:31:28 +08:00
* 2013-01-08v0.3.0rc5Updating 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-03v0.2.0Generalized requirejs template config. Added loader plugin. Tests for templates. Updated jasmine to 1.3.0.
* 2012-11-24v0.1.2Updated for new grunt/grunt-contrib APIs.
* 2012-11-07v0.1.1Fixed race condition in requirejs template.
* 2012-11-07v0.1.0Ported grunt-jasmine-runner and grunt-jasmine-task to grunt-contrib.
---
2012-11-02 13:03:09 +08:00
Task submitted by [Jarrod Overson](http://jarrodoverson.com)
2012-11-02 13:03:09 +08:00
2017-01-13 02:10:10 +08:00
*This file was generated on Thu Jan 12 2017 13:09:46.*