I'm trying to add `grunt-contrib-jasmine` into an existing project that's already using Grunt and having some trouble.
The Jasmine docs aren't super clear about how I should structure my project. And `npm install grunt-contrib-jasmine --save-dev` didn't quite seem to do what it's supposed to.
It adds a `.grunt` directory (which the docs say nothing about), and then running `grunt jasmine` like the docs say to do next, fails and says `>> No "jasmine" targets found.` instead of what the docs say; "Automatically builds and maintains your spec runner and runs your tests headlessly through PhantomJS."
I figure that means I need to put something in my Gruntfile, but I can't find anything consistent in the docs about what to put there. I found a few snippets, but nothing seems to work quite right. I ended up adding;
grunt.initConfig({
jasmine: {
pivotal: {
src: 'src/**/*.js',
options: {
specs: 'spec/*Spec.js',
helpers: 'spec/*Helper.js'
}
}
}
});
Which kind of works. After running `grunt jasmine` again, it creates a `_SpecRunner.html` in the project root that links to a bunch of JS files (most of the things in the `.grunt` directory and all of the .js files in the `src` directory.) but the fails with a warning; "Warning: No specs executed, is there a configuration error?"
So, I manually created a `spec` directory with a `StarterSpec.js` that contains;
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
Now, running `grunt jasmine` runs that test and passes. Yay! But I'm still not testing my application, because it's source is in the project root, not the `src` directory. If I change the Jasmine config in my Gruntfile and set `src` to the root instead, `grunt jasmine` just returns pages of errors for all of my project files and dependencies.
I'm completely lost.
How do I get this set up correctly?
What should my project structure look like?
What's with the .grunt, and src directories?
What is the Spec Runner and what is it supposed to do? (Other than running specs, obviously. I want to run Jasmine from Grunt, so do I even need this HTML file?)
Any help would be greatly appreciated! I've already scoured the following docs;