zap

2019-01-14 admin

zap是什么

什么是zap,A tiny test runner

zap使用教程帮助文档

zap:

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.

Example

test/winner.test.js

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.done()
  }
  'test asynchronous things': function (test) {
    process.nextTick(function () {
      assert.ok(test.is_awesome)
      test.done()
    })
  }
}

output

<pre>$ zap winner/test that thingy… passed winner/test asynchronous things… passed </pre>

running just one test

<pre>$ zap --one test/winner.test.js "test that thingy" winner/test that thingy… passed </pre>

Installing

Just npm install -g zap.

Details

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 test.fail("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:

<pre>$ zap spec/*/.js </pre>

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-50962.html

文章标题:zap

回到顶部