January 03, 2014

Integration Testing in Node.js

What's the best way to run integration tests on an AJAX-heavy website?

I have been toughening up the pencilcode.net deployment environment. (git repos here.) While the pencilcode server is an nginx webserver backed by a small python-uwsgi app server, the pencilcode development environment is 100% javascript, with a node.js and npm and grunt-based build, and a small express.js test server that proxies backend calls to the production server.

If you think that's just a lot of hipster coder buzwords, wait... there's more.

This morning I broke pencilcode.net due to a code change: while refactoring the editor source code to use proper require.js organization, I messed up by bringing in an old version of seedrandom that wasn't compatible with AMD loading. Seedrandom is my own library, and so it was doubly my own fault! The result was that all password checking was broken on the site for a few hours. The bug took about 10 minutes to fix: I just had to use bowercopy to upgrade seedrandom to its latest bower package, then run the requirejs optimizer, then redeploy.

But the real bug? I don't have any integration tests on pencilcode.net. I should have never pushed broken passwords in the first place. While I have some little unit tests, I really need end-to-end integration tests that bring up the whole website, browse it with a headless browser, and click around authenticating and editing and running and saving, to make sure it all works as expected.

The 2010 way of doing this used to be a big system like Selenium. But it feels like in 2013 I should be able to do this in lighter-weight way. I have seen that grunt-phantomjs works pretty well with QUnit unit tests. But almost all the javascript-based tools I've seen are designed for tiny unit tests.

How do I run tests that exercise the whole system end-to-end? Maybe something like travist's jquery.go.js? Has anybody found the right way to do integration tests in the node.js world?

Posted by David at January 3, 2014 06:52 PM
Comments
Post a comment









Remember personal info?