node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



a tiny testing tool for node.js

zap was inspired by a conversation on the freenode #nodejs channel, in which ry told me that require('assert') was all the testing framework I needed. I was enlightened, and modelled this after a small makefile that ry wrote.

zap does a little more than that makefile. I wanted:

  • multiple tests per file, in the style of expresso,
  • assurance that the tests actually finished (via test.done()),
  • pretty output.



var assert = require('assert')
module.exports = {
  setup: function (test) {
    test.is_awesome = true
  'test that thingy': function (test) {
    assert.ok(test.is_awesome, 'test passed!')
  'test asynchronous things': function (test) {
    process.nextTick(function () {


$ zap
winner/test that thingy... passed
winner/test asynchronous things... passed

running just one test

$ zap --one test/winner.test.js "test that thingy"
winner/test that thingy... passed


Just npm install -g zap.


Each test is run in a separate node instance. zap require()s your module once to work out what tests are in it, then once for each test in a new node process. So it's a bad idea to connect to databases or do any real work in the top level of your test file—though defining helper functions and so on is fine.

Test module exports called setup or teardown are treated specially: setup will be called before your test runs, and teardown will be called after the test finishes.

Call"a splode") to escape the test early (though assert.ok(false) will do just fine).

If your tests are not in the form of test/(subdir/)?name.test.js, you can tell zap where your tests are by giving the locations on the command line:

$ zap spec/**/*.js