It took me a while to setup unit testing in JavaScript project I’m involved in. I must say the task was so difficult to me that I’ve decided to share my experience and final setup. Not that unit testing itself is hard. PHP, Ruby, Java… never had any problems. JavaScript was a long ride.

without any other parameters and it will print you short help. To run unit tests run “unittest” target:

1

ant unittest

Generating coverage report requires having JSCover running:

1

2

ant startjscover

ant unittestandcoverage

The report will be stored in “build/coverage” folder.

Ant build script is mostly about starting/stopping JSCover and running PhantomJS (unit tests via PhantomJS) – it should be fairly simple to port it to Maven, Grunt or any other build tool. There is only one thing that needs to be taken care when porting, that is, generating application.js file. This file loads all application code using require method of RequireJS. Again, generating this file using any other build tool should be easy.

I hope that you will find this setup useful and it will save you time trying to get Jasmine, RequireJS, PhantomJS and JSCover to work together.

Related

Author: Wojciech Szela

CSM, Consultant, Manager, Entrepreneur and Open Source Contributor. Scrum and eXtreme Programming practitioner. Evangelist of healthy work environment, high quality products, people development and team work. View all posts by Wojciech Szela

Hi Wojciech, Can you tell me if I would have to change anything if I’m using Jasmine 1.3? Also I use HTMLReporter (I see you have used ConsoleReporter). Will that make any difference? After I start my server, I cannot open my tests in the frame. Thanks in advance!