Integration testing node.js web apps with JavaScript

These are some loose guidelines for integration testing a web app in JavaScript. Ideal if you need to test an ExpressJS app or any kind of web service.

The key issue is being able to stop and start the service as part of the test harness. Two ways of doing this are:

Using Mocha

Mocha is really useful because it has before and after hooks that can be used. These run once at the beginning and end of the test run and can be used to stop/start the service like so:

var server;
before(function (done) {
   server = new HttpServer({port: 8080}).start(done);

after(function (done) {

The full code can be seen here:

Using a wrapper file

A wrapper file can be used that uses node.js spawn via require('child_process').spawn. This will spawn subprocess as if running a shell command. I have an example gist here:

Tagged with: , , ,
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: