Introduction
One of my pet peeves with writing test-driven javascript is the difficulty initial setup. It feels that there is bunch of libraries I need to install to even get going with basics. I set up a simple template that has the very basics for doing test-driven development with javascript. Here is an explanation of what it contains and how it is used.
I chose CoffeeScript because it has neat syntax and removes some of javascript's nastiness. Mocha because I want to run tests on the command line.Phantom.js because it integrates nicely with Mocha.
Usage
First you need to install node.js in order to aquire npm. Then copy the files from my template. Running npm install
on the command line installs all the dependencies. After installation tests can be run with the command npm test
. This command really runs two commands:
node_modules/coffee-script/bin/coffee -cj test/alltests.js test/*.coffee
This takes all CoffeeScript files in directory test, compiles them into javascript and puts them in a single javascript file called alltests.js.node_modules/mocha-phantomjs/bin/mocha-phantomjs test/runner.html
This runs mocha-phantomjs plugin on file runner.html
Runner.html is based on the example on mocha-phatomjs readme-page. Further dependencies can be added there.
Running npm test should display result like this:
Tests can also be run by opening runner.html in browser.
Software professional with a passion for quality. Likes TDD and working in agile teams. Has worked with wide-range of technologies, backend and frontend, from C++ to Javascript. Currently very interested in functional programming.