Reporter

This class establishes the Reporter protocol: an object that implements runStart, runEnd and testResult. An object with this signature may be passed as the first argument to the TestQueue constructor. See Customization for more information.

The default implementation writes TAP-formatted output to the provided stream. All callback functions are passed to the this.stream.write function. If an error is thrown or emitted during a write operation, it is caught and passed to the callback.

Properties

  • tap Tap — 

    TAP-producer object

  • stream Writable — 

    data is written to this stream

new Reporter(tap, stream)

Creates a new Reporter object and sets the this.tap and this.stream properties.

  • tap Tap — 

    TAP-producer object

  • stream Writable — 

    data is written to this stream

Examples

const {Tap, Reporter} = require('spooning');
const reporter = new Reporter(new Tap(), process.stdout);

runStart(info, callback)

Write a TAP plan to this.stream.

  • info RunStartInfo
  • callback function — 

    called when write finishes

    • error Error — 

      write error (or falsy value if none occurred)

See

  • Tap — 

    uses tap.handleStart to render the plan string

  • TestQueue — 

    called by TestQueue before the first test is run (unless testQueue.setAutoRun(true); has been called)

Examples

reporter.runStart({count: 2}, () => {
  //  plan has been written
});

runEnd(info, callback)

Write a footer with final result counts as a TAP diagnostic message to this.stream.

  • info RunEndInfo
  • callback function — 

    called when write finishes

    • error Error — 

      write error (or falsy value if none occurred)

See

  • Tap — 

    uses tap.handleEnd to render the string

  • TestQueue — 

    called by TestQueue after the last test is run

Examples

reporter.runEnd({total: 2, passed: 1}, () => {
  //  footer has been written
});

testResult(info, callback)

Write a TAP result to this.stream.

  • info TestResultInfo
  • callback function — 

    called when write finishes

    • error Error — 

      write error (or falsy value if none occurred)

See

  • Tap — 

    uses tap.handleResult to render the string

  • TestQueue — 

    called by TestQueue when a test completes

Examples

reporter.testResult({idx: 1, name: 'Should pass'}, () => {
  //  result has been written
});