npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tap-in

v3.2.1

Published

turn tap test output into JSON

Downloads

243

Readme

this is a grateful fork of scottcorgan/tap-out, which is no-longer maintained ¹ ² this library should be a non-breaking, no-sweat update.

TAP ('Test Anything Protocol') is a text-based format for software testing It looks something like this:

1..4
ok 1 - Input file opened
not ok 2 - First line of the input valid
ok 3 - Read the rest of the file
not ok 4 - Summarized correctly # TODO Not written yet

It's pretty-cool format, and is very-heavily used. This library parses this text into JSON, so test-reporters can do clever things with the output data more easily.

it offers a command-line script, and a javascript API:

CLI

this library exports a CLI command tap-in, that you can use with a pipe

$ something-that-produces-tap | tap-in
{
  tests: [
    { name: 'is true', number: 1, raw: '# is true', type: 'test' }
  ],
  asserts: [
    { name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
    { name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
  ],
  versions: [],
  results: [],
  comments: [],
  plans: [{ type: 'plan', raw: '1..2', from: 1, to: 2, skip: false }],
  pass: [
    { name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
    { name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
  ],
  fail: [],
  errors: []
}

JS API

more often, a test-reporter will want to do something custom with the output:

const tapIn = require('tap-in')

let t = tapIn((err, json) => {
  console.log(json) // callback when finished
})

// or some event-based logic
t.on('pass', assert => {
  console.log('✓')
})
t.on('fail', assert => {
  console.log(`✗ ${assert.name}`)
})

process.stdin.pipe(t)

tapIn returns a stream that emits events with various TAP data. It takes an optional callback which is called when all parsing is done.


Events

t.on('output', function (output) {})

All output after all TAP data is parsed.

Example output

{
  tests: [
    { name: 'is true', number: 1, raw: '# is true', type: 'test' }
  ],
  asserts: [
    { name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
    { name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
  ],
  results: [],
  versions: [],
  comments: [],
  fail: [],
  pass: [
    { name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' },
    { name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' }
  ],
}

t.on('test', function (test) {})

Parsed test object with details.

  • type - value will always be test
  • name - name of the test
  • raw - the raw output before it was parsed
  • number - the number of the test
{
  type: 'test',
  name: 'is true',
  raw: '# is true',
  number: 1
}

t.on('assert', function (assertion) {})

Parsed assert object details.

  • type - this will always be assert
  • name - the name of the assertion
  • raw - the raw output before it was parsed
  • number - the number of the assertion
  • ok - whether the assertion passed or failed
  • test - the number of the test this assertion belongs to
{
  name: 'true value',
  number: 1,
  ok: true,
  raw: 'ok 1 true value',
  test: 1,
  type: 'assert'
}

t.on('version', function (version) {})

Parsed version data.

  • type - this will always be version
  • raw - the raw output before it was parsed
{
  raw: 'TAP version 13',
  type: 'version'
}

t.on('result', function (result) {})

Parsed test result data for tests, pass, fail.

  • type - this will always be result
  • name - the name of the result
  • raw - the raw output before it was parsed
  • count - the number of tests related to this result

Tests

{
  count: '15',
  name: 'tests',
  raw: '# tests 15',
  type: 'result'
}

Pass

{
  count: '13',
  name: 'pass',
  raw: '# pass  13',
  type: 'result'
}

Fail

{
  count: '2',
  name: 'fail',
  raw: '# fail  2',
  type: 'result'
}

t.on('pass', function (assertion) {})

Parsed assertion that has passed with details. The assertion formate is the same as the assert event.

t.on('fail', function (assertion) {})

Failed assertion that has passed with details. The assertion formate is the same as the assert event.

t.on('comment', function (comment) {})

Generic output like console.log() in your tests.

  • type - this will always be comment
  • raw - the raw output before it was parsed
  • test - the number of the test this comment belongs to
{
  type: 'comment',
  raw: 'this is a console log',
  test: 1
}

PRs are welcome! This library is maintained by Spencer Kelly


See Also

Thank you to feross/re-emitter and Scott Corgan

MIT