Node Roundup: Browser Tests

Alex R. Young





testing node modules npm

Node Roundup: Browser Tests

Posted by Alex R. Young on .

testing node modules npm

Node Roundup: Browser Tests

Posted by Alex R. Young on .

I wanted to write about Substack's Testling project, but then coincidentally Chris Scribner sent in his Browser Harness project. Let's look at both to see how they shape up.


Testling (GitHub: substack / testling, License: MIT, npm: testling) is a tool for running tests in local instances of browsers. It works by using browserify -- this allows Node modules to be used in browsers.


But what's really going on? Follow Testling's source into browser/prelude.js and you'll find xhr-write-stream. Also, Testling uses browser-launcher which allows browsers to be launched headlessly through Xvfb or PhantomJS.

I installed browserify and testling then ran browserify test.js | testling and it opened Chrome and ran my tests. I wasn't sure how to make Testling run it headlessly, or run it in a different browser, but apparently if you define a "testling" field in your package.json it should pick up your desired browser settings from there. Read more in testling field documentation.

Browser Harness

Browser Harness (GitHub: scriby / browser-harness, License: MIT, npm: browser-harness) takes a different approach. It uses client-side code to listen for commands to run tests. It currently uses NowJS for communication, but the author wants to replace it with Socket.IO.

It requires a file to be served from the domain of the site being tested, and has a few other limitations which are documented in the readme file.

The harness has built-in support for fibers, so if you install asyncblock you can write tests in a blocking style.

The example in the documentation uses Mocha, but the author notes that other test frameworks should work as well.