tap-summary

2018-10-13 admin

tap-summary是什么

什么是tap-summary,Summarize TAP

tap-summary使用教程帮助文档

tap-summary

version status dependencies devDependencies

A reporter for TAP.

Example

summary

Usage

package.json

{
  "scripts": {
    "test": "tape test/*.js | tap-summary"
  }
}

CLI Options

  --no-ansi        Disable ANSI formatting
  --no-progress    Disable progress output during tests

API

var summarize = require('tap-summary')

var fs = require('fs')
fs.createReadStream('test.tap')
  .pipe(summarize({
    ansi: true,
    progress: true,
  }))
  .pipe(process.stdout)

Also, the default formatter could be replaced with custom ones.

var reporter = require('tap-summary').reporter()

var fs = require('fs')
fs.createReadStream('test.tap')
  .pipe(customize(reporter))
  .pipe(process.stdout)

The reporter is a Duplex, which consumes the TAP input and output nothing by default. However, it emits the following events during the process, so that customize could listen to them and add something into the output.

  • reporter.on(‘test.start’, test => {}). Fired when a new test detected.
  • reporter.on(‘test.end’, test => {}). Fired when the end of a test reached.
  • reporter.on(‘test.assert’, (assertion, test) => {}). Fired when a new assertion found.
  • reporter.on(‘summary’, (stats, fails, comments) => {}). Fired when all TAP input has been processed.

Details about the test and assertion object could be found here.

The stats object:

var stats = {
  // the total time (ms) it takes
  duration: duration,
  // the total number of assertions planned
  planned: res.plans.reduce(function (p, c) {
    return c.to - c.from + 1 + p;
  }, 0),
  // the actual total number of assertions found
  assertions: res.asserts.length,
  // the number of successful assertions
  pass: res.pass.length,
  // the number of failed assertions
  fail: res.fail.length,
  // the number of comments found
  comments: res.comments.length,
}

fails will be null unless stats.fail > 0:

{ 
  testName: [failedAssertion]
}

comments will be null unless stats.comments > 0:

{ 
  testName: [comment]
}

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-42613.html

文章标题:tap-summary

回到顶部