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-format/parser

v0.2.1

Published

A highly verbose parser for the Test Anything Protocol that exposes an observable and streaming interface

Downloads

1,633

Readme

tap-format parser Travis codecov.io

A highly verbose parser for the Test Anything Protocol that exposes an observable and streaming interface.

This is the parser used to create the following beautiful TAP formatters:

Node Version Support

  • 0.10
  • 0.12
  • iojs
  • = 4.x

Install

npm install @tap-format/parser --save

Usage

Observable Interface

The parser exposes an interface that lets you deal with the parsed TAP with Reactive Extensions. See the API section for a full list of exposed Observables.

var parse = require('@tap-format/parser')

var stream = process.stdin
var tap$ = parser.observeStream(stream)

tap$.tests$
	.forEach(function (test) {
		console.log(test.title)
	})

tap$.asserions$
	.forEach(function (assertion) {
		console.log(assertion.title)
	})

Streaming Interface

The parser will parse streaming data for any source.

var parser = require('@tap-format/parser')
var H = require('highland')

var tapStream = H(process.stdin.pipe(parser.stream()))

var tests = tapStream.filter(function (line) {
	return line.type === 'test'
})

var assertions = tapStream.filter(function (line) {
	return line.type === 'assertion'
})

tests.each(function (test) {
	console.log(test.title)
})

assertions.each(function (assertion) {
	console.log(assertion.title)
})

CLI

$ something-that-produces-tap | tap-format-parser
{
	// Parsed TAP output as JSON here
}

API

Observable Interface

Given a streaming input, the parser will expose and RXjs Observable chunked by new lines. In addition, the parser exposes the following properties as Observables as convenience methods for the parsed TAP.

var parser = requrie('@tap-format/parser')

var stream = process.stdin
var tap$ = parser.observeStream(stream)

tap$

An Observable of all parsed output for the given input TAP stream

// This will console.log every assertion title
tap$
	.filter(function (line) {
		return line.type === 'assertion'
	})
	.forEach(function (assertion) {
		console.log(assertion.title)
	})

tap$.tests$

An Observable of all parsed tests.

// This will console.log all test titles
tap$.tests$
	.map(function (test) {
		return 'TEST: ' + test.title
	})
	.forEach(console.log.bind(console))

The shape of the test object is as follows:

  • raw - the raw test line TAP from the TAP input (i.e. # My Test)
  • type - the type of the line. This will always be test
  • title - the parsed test title. # My Test becomes My Test
  • lineNumber - the line number of the TAP input
  • testNumber - the test number from the TAP input

tap$.assertions$

An Observable of all parsed assertions.

// This will console.log all assertion titles
tap$.assertions$
	.map(function (assertion) {
		return (assertion.ok ? 'OK: ' : 'NOT OK: ') + assertion
	})
	.forEach(console.log.bind(console))

The shape of the assertion object is as follows:

  • raw - the raw test line TAP output, including any diagnostic associated with it
  • type - the type of the line. This will always be assertion
  • title - the parsed test title, excluding any diagnostic associated with it
  • ok - true/false - indicates whether the assertion passed or failed
  • diagnostic - an object of any diagnostic associated with the assertion. If the assertion is not ok, this will be information about the expected and actual values, etc. The TAP input will be YAML, but this value will always be an object
  • rawDiagnostic - the raw diagnostic fromt he TAP input
  • assertionNumber - the assertion number from the TAP input
  • lineNumber - the line number of the TAP input
  • testNumber - the test number that the assertion is within from the TAP input

tap$.comments$

An Observable of all output that is not tap. The parser assumes these are from console.log() and treats them as comments.

// This will console.log all the comment titles
tap$.comments$
	.map(function (comment) {
		return 'COMMENT: ' + comment.title
	})
	.forEach(console.log.bind(console))

The shape of the comment object is as follows:

  • raw - the raw comment line from the TAP input
  • type - the type of the line. This will always be comment
  • title - the parsed comment title
  • lineNumber - the line number of the TAP input

tap$.results$

An Observable of the parsed TAP results. This will only ever be of type tests, pass, or fail.

// This will console.log the names and counts of the results
tap$.results$
	.forEach(function (result) {
		console.log(result.name + ' ' + result.count)
	})

The shape of the result object is as follows:

  • raw - the raw result line from the TAP input (i.e. # pass 3)
  • type - the type of the line. This will always be result
  • name - the name of the result (i.e. pass, fail, assertions, etc.)
  • count - the number of assertions associated with this result

tap$.plans$

An Observable of all parsed plans given from TAP output. This is usually only one item.

// This will console.log the 'from' and 'to' from the plan
tap$.plans$
	.forEach(function (plan) {
		console.log('FROM: ' + plan.from')
		console.log('TO: ' + plan.to')
	})

The shape of the plan object is as follows:

  • raw - the raw plan line TAP output (i.e. 1..7)
  • type - the type of the line. This will always be plan
  • from - this will almost always be 1
  • to - the total number of assertions from the TAP input
  • skip - the number of assertions skipped

tap$.versions$

An Observable of the parsed TAP version

// This will console.log the TAP version
tap$.versions$
	.forEach(function (version) {
		console.log(version.raw)
	})

The shape of the version object is as follows:

  • raw - the raw version line TAP output (i.e. TAP version 13)
  • type - the type of the line. This will always be version

Streaming Interface

Using require('@tap-format/parser').stream() returns a new-line-chunked stream of parsed TAP. It is a normal stream, and therefore exposes the very useful pipe() method.

Run Tests

git clone [email protected]:scottcorgan/tap-out.git .
npm install
npm test