2012-11-02 13:03:09 +08:00
|
|
|
|
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: {
|
|
|
|
src: 'src/**/*.js'
|
|
|
|
options: {
|
|
|
|
specs: 'spec/*Spec.js',
|
|
|
|
helpers: 'spec/*Helper.js'
|
|
|
|
}
|
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',
|
|
|
|
helpers: 'spec/*Helper.js'
|
|
|
|
template: 'custom.tmpl'
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Sample RequireJS usage
|
|
|
|
|
|
|
|
```js
|
2012-12-03 16:17:06 +08:00
|
|
|
// 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/'
|
|
|
|
}
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2012-12-03 16:17:06 +08:00
|
|
|
*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
|
2012-11-02 13:03:09 +08:00
|
|
|
|
2012-12-03 16:17:06 +08:00
|
|
|
## RequireJS notes
|
2012-11-02 13:03:09 +08:00
|
|
|
|
2012-12-03 16:17:06 +08:00
|
|
|
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:
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
```js
|
|
|
|
require([*YOUR SOURCE*], function() {
|
|
|
|
require([*YOUR SPECS*], function() {
|
2012-12-03 16:17:06 +08:00
|
|
|
require([*GRUNT-CONTRIB-JASMINE FILES*], function() {
|
2012-11-02 13:03:09 +08:00
|
|
|
// at this point your tests are already running.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|