grunt-contrib-jasmine/docs/jasmine-examples.md

91 lines
1.9 KiB
Markdown
Raw Normal View History

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',
helpers: 'spec/*Helper.js'
template: 'custom.tmpl'
}
}
}
}
```
## Sample RequireJS usage
```js
// Example configuration
grunt.initConfig({
connect: {
test : {
port : 8000
}
}
jasmine: {
requirejs: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js',
host: 'http://127.0.0.1:8000/',
template: 'requirejs',
templateOptions: {
requireConfig: {
baseUrl: 'src/'
}
}
}
}
}
}
```
*Note* the usage of the 'connect' task configuration. You will need to use a task like
[grunt-contrib-connect][] if you need to test your tasks on a running server.
[grunt-contrib-connect]: https://github.com/gruntjs/grunt-contrib-connect
## RequireJS notes
If you end up using the requirejs template, it's worth looking at the
[RequireJS template source](https://github.com/gruntjs/grunt-contrib-jasmine/blob/master/tasks/jasmine/templates/RequireJSRunner.tmpl)
in order to familiarize yourself with how it loads your files. The load process essentially
consists of a series of nested `require` blocks, incrementally loading your source and specs:
```js
require([*YOUR SOURCE*], function() {
require([*YOUR SPECS*], function() {
require([*GRUNT-CONTRIB-JASMINE FILES*], function() {
// at this point your tests are already running.
}
}
}
```