Automation BDD

Plug your Jasmine BDD Specs with Grunt

Jasmine

Jasmine is a Behaviour Driven Development tool for the JavaScript. It’s an awesome idea to get our JavaScript unit tested with Jasmine. You can read more about how Jasmine works on official documentation here

Jasmine documentation covers how to get started and run our Specs in the browser, however it’s not enough to run Jasmine Spec with Spec runner html as we have to have special setup on CI.

In this post, we will cover how to setup Jasmine Specs with Grunt to run on CI.

Grunt

Grunt is a JavaScript task runner which acts as a build tool for the JavaScript. We can setup various tasks in the Gruntfile.js and execute them as required.

In order to setup Jasmine BDD Specs with grunt, we need a ‘package.json’ file with following dependencies. Assuming we have Node and npm setup.

Now we can install all these dependencies with ‘npm install’ command. Once installed, we should have ‘node_modules’ directory with all the packages and binaries installed.

Now that we have node setup, we have to write some Jasmine Specs for our JavaScript. Let’s use couple od the JS files and Specs from the Jasmine Demo itself.

Now  we have to create a Gruntfile and configure Jasmine Specs using ‘grunt-contrib-jasmine‘ package. Our Example Gruntfile will look like this:

gruntfile

In the Gruntfile.js we have loaded ‘grunt-contrib-jasmine’ package and specified location of our ‘scr’ JS files and ‘Specs’ files.

Now we should be able to execute Grunt ‘jasmine’ task like this

You can see our Specs executed like this :

jasmine-runner

This can be used to our Jasmine Specs on any Continuous Integration server easily.

Source-Code

Source Code for this demo is available on GitHub : Jasmine-Grunt-Setup

 

Video-Demo