prettytap
v0.2.0
Published
Pretty-print TAP results.
Readme
prettytap
Pretty-print TAP (v13) as spec output or JSON.
Install
npm install prettytapCLI:
npm install -g prettytapor npx prettytap.
Example
This repo uses brittle as the TAP producer and formats it with prettytap:
node examples/demo.js | npx prettytapA saved TAP stream works the same:
cat test/fixtures/example.txt | npx prettytap
Exit code
A pipe only returns the formatter's status, so a runner that crashes after printing a clean TAP stream
(an uncaught error on stderr, a non-zero exit) is invisible to runner | prettytap. Let prettytap
spawn the runner instead:
prettytap -- brittle-node test/all.mjs
prettytap -f json -- bare test/all.tsThe runner's stderr passes through. prettytap exits non-zero when the TAP stream fails or the runner
exits non-zero, whichever happens.
Formats
spec(default)json
cat results.tap | prettytap -f jsonLibrary
const { parse, SpecFormatter, JsonFormatter } = require('prettytap')
const results = parse(`TAP version 13
1..2
ok 1 test 1
not ok 2 test 2
`)
const spec = new SpecFormatter()
console.log(spec.formatToString(results))
console.log(spec.summaryToString())
const json = new JsonFormatter()
console.log(JSON.stringify(json.toJson(results), null, 2))API
const results = parse(input)
Parse a complete TAP string (or array of lines) into a results object.
const parser = new Parser()
Incremental parser for a TAP stream.
parser.write(chunk)— feed a chunk, returns an array of eventsparser.end()— flush the trailing line, returns any remaining eventsparser.results— theresultsobject, updated in place
Events are { type: 'test', test }, { type: 'yaml', test }, { type: 'comment', text }
and { type: 'bail', reason }.
isPassing(results)
Whether every expected test passed. Also available as results.isPassing().
resultsToString(results)
Plain-text summary of a results object. Also available as results.toString().
const formatter = new SpecFormatter()
formatter.formatToString(results)— the spec bodyformatter.summaryToString()— the totals, afterformatToStringformatter.format(results)/formatter.summary()— the same, written to stdout
Streaming, for use with Parser events:
formatter.streamStart(results)— reset for a new streamformatter.streamTest(test)/streamYaml(test)/streamBail(reason)— return a stringformatter.streamComment(text)— record the next suite heading
const formatter = new JsonFormatter()
formatter.toJson(results)— a plain objectformatter.formatToString(results)— the same, stringifiedformatter.format(results)— the same, written to stdout
formatSpec(results) / formatJson(results)
One-shot helpers that construct a formatter, print, and return it.
Colors
bold, faint, dim, italic, underline, red, green, yellow, blue, magenta,
cyan, brightRed, brightMagenta, plus stripAnsi(str), isColorEnabled() and
setColorEnabled(enabled). Color is off when stdout is not a TTY, or with NO_COLOR /
--no-color, and forced on with FORCE_COLOR / --color.
Why
TAP is a cross-language protocol. Formatters usually are not — they ship tied to one runtime. prettytap is a CLI and a library you can pipe any TAP stream into.
node examples/demo.js | prettytap
npm test | prettytap
cat results.tap | prettytapLicense
MIT
