bandage
Generator best test harness and test runner.
Usage
Use like if tape supported generator functions. Just always pass a generator function to test
and stop calling end/done
. The test is always done when the function is done.
var test = ; ; ;
Which you can run with the bundled (vowel-free) bndg
executable:
$ bndg test.jsTAP version 13# yielding test ok 1 addition worksok 2 promise resolved correctly# plain test ok 3 multiplication works 1..3# tests 3 # pass 3 # fail 0
Error handling
By default, bandage catches errors and reports it as a test failure with a stack trace if you do not catch it, or use t.throws
. Here's an example:
var test = ; var { return { ; };}; ;
Which will output:
TAP version 13# error is caught not ok 1 Error: async reject --- operator: error expected: undefined actual: [Error: async reject] at: null._onTimeout stack: Error: async reject at null._onTimeout at Timer.listOnTimeout ... 1..1# tests 1 # pass 0 # fail 1
If you would like to test that errors are correctly passed through, just catch them yourself:
var test = ; var { return { ; };}; ;
Which will output:
TAP version 13# error is caught ok 1 caught async rejectok 2 we do reach this 1..2# tests 2 # pass 2 # fail 0
If something unexpectedly throws in some callback stack that isn't matched by anything, that will still provide a TAP breaking stack trace. That is still a failed test though - there's only so much we can do at this point.
Subtests
Subtests work with bandage. The only difference is you need to yield
it:
var test = ; var { return { ; };}; ;
Which outputs
TAP version 13# nested tests ok 1 waited
Setup and Teardown
Because tests are executed sequentially in the order of the file, you can create setup tests at the top of your file, and teardown tests at the bottom.