Tap

Render TAP-formatted output.

Static

Properties

  • style Object — 

    define style prefixes for output elements

  • debug bool — 

    include stack trace in error output if true

  • EOL string — 

    line ending used when rendering output

new Tap(style, debug, EOL)

Creates a new Tap object and sets the this.style, this.debug, and this.EOL properties.

  • style Object — 

    define style prefixes for output elements

    (default: Tap.Styles.None)
  • debug bool — 

    include stack trace in error output if true

    (default: false)
  • EOL string — 

    line ending used when rendering output

    (default: '\n')

Examples

const {Tap} = require('spooning');
const tap = new Tap(Tap.Styles.Unicode);

renderPlan(count)

Render and return a TAP plan string.

  • count number — 

    the number of tests to be run

returns string

Examples

return tap.renderPlan(4); // returns "1..4"

renderResult(ok, idx, name, suffix)

Render and return a TAP result string.

  • ok bool — 

    true if the test passed, otherwise false

  • idx number — 

    test number (determined by order finished)

  • name string — 

    test name

  • suffix string — 

    will be prefixed with this.EOL and added to the end of the result string

returns string

Examples

return tap.renderResult(true, 1); // returns "ok 1"

renderDiagnostic(message, prefix)

Render and return a TAP diagnostic string.

  • message any — 

    message to display

  • prefix string — 

    prefix will be added to each line in rendered message

    (default: '# ')
returns string

Examples

return tap.renderDiagnostic('Test message'); // returns "# Test message"

handleStart(info)

Render and return a TAP plan string.

returns string

Examples

return tap.handleStart({count: 4}); // returns "1..4"

handleEnd(info)

Render and return a TAP diagnostic message containing a footer with final result counts.

returns string

Examples

return tap.handleEnd({total: 4, passed: 4}); // returns "# test: 4\n# pass: 4\n# fail: 0"

handleResult(info)

Render and return a TAP result message that includes any error and/or diagnostic message provided.

returns string

Examples

return tap.handleResult({idx: 1, name: 'expected message'}); // returns "ok 1 - expected message"

prefixLines(text, prefix)

Add a prefix to every line of a string.

returns string

Examples

console.log(tap.prefixLines('Test message\nSecond line\nThird line', '# ! '))

Output

# ! Test message
# ! Second line
# ! Third line

setStyle(style)

Set the this.style property. Changes the style used when rendering output.

setDebug(isEnabled)

Set the this.debug property. Causes Error stack to be included in output if true.

setEOL(eol)

Set the this.EOL property. Changes the line ending character used when rendering output.

Tap.messageToString(val, indent)

This function is used to get the string value of messages passed to renderDiagnostic.

  • val any — 

    value to be stringified (maybe)

  • indent number — 

    number of spaces used to indent the JSON object

    (default: 2)
returns string|undefined

See