parse the test anything protocol
var parser = require('tap-parser');
var p = parser(function (results) {
console.dir(results);
});
process.stdin.pipe(p);
given some TAP-formatted input:
$ node test.js
TAP version 13
# beep
ok 1 should be equal
ok 2 should be equivalent
# boop
ok 3 should be equal
ok 4 (unnamed assert)
1..4
# tests 4
# pass 4
# ok
parse the output:
$ node test.js | node parse.js
{ ok: true, count: 4, pass: 4, plan: { start: 1, end: 4 } }
This package also has a tap-parser
command.
Usage:
tap-parser [-j [<indent>] | --json[=indent]]
Parses TAP data from stdin, and outputs an object representing
the data found in the TAP stream to stdout.
If there are any failures in the TAP stream, then exits with a
non-zero status code.
Data is output by default using node's `util.format()` method, but
JSON can be specified using the `-j` or `--json` flag with a number
of spaces to use as the indent (default=2).
var parser = require('tap-parser')
Return a writable stream p
that emits parse events.
If cb
is given it will listen for the 'complete'
event.
The results
object contains a summary of the number of tests
skipped, failed, passed, etc., as well as a boolean ok
member which
is true if and only if the planned test were all found, and either
"ok" or marked as "TODO".
Every /^(not )?ok\b/
line will emit an 'assert'
event.
Every assert
object has these keys:
assert.ok
- true if the assertion succeeded, false if failedassert.id
- the assertion numberassert.name
- optional short description of the assertion
and may also have
assert.todo
- optional description of why the assertion failure is not a problem. (Booleantrue
if no explaination provided)assert.skip
- optional description of why this assertion was skipped (booleantrue
if no explanation provided)assert.diag
- a diagnostic object with additional information about the test point.
Every /^# (.+)/
line will emit the string contents of comment
.
Every /^\d+\.\.\d+/
line emits a 'plan'
event for the test numbers
plan.start
through plan.end
, inclusive.
If the test is completely skipped the result will look like
{ ok: true,
count: 0,
pass: 0,
plan:
{ start: 1,
end: 0,
skipAll: true,
skipReason: 'This code has no seat belt' } }
A /^TAP version (\d+)/
line emits a 'version'
event with a version
number or string.
A bail out!
line will cause the parser to completely stop doing
anything. Child parser bailouts will bail out their parents as well.
If a child test set is embedded in the stream like this:
TAP Version 13
1..2
# nesting
1..2
ok 1 - true is ok
ok 2 - doag is also okay
ok 1 - nesting
ok 2 - second
then the child stream will be parsed and events will be raised on the
childParser
object.
Since TAP streams with child tests should follow child test sets with a pass or fail assert based on the child test's results, failing to handle child tests should always result in the same end result. However, additional information from those child tests will obviously be lost.
All other lines will trigger an 'extra'
event with the line text.
With npm do:
npm install tap-parser
You can use browserify to require('tap-parser')
in
the browser.
MIT