GithubHelp home page GithubHelp logo

isabella232 / tap-console-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from experience-monks/tap-console-parser

0.0 0.0 0.0 164 KB

parses TAP by hijacking console.log

License: MIT License

JavaScript 100.00%

tap-console-parser's Introduction

tap-console-parser

stable

Parses TAP by hijacking console.log, primarily useful for colorizing tests in the browser console.

var parser = require('tap-console-parser')

// start hijacking console.log()
var tap = parser()

// we can print to the real console with log()
tap.on('assert', function (assert) {
  tap.log('Got assert!', assert.name)
})

// get result
tap.on('complete', function (result) {
  // stop hijacking console.log
  tap.detach()
  
  if (result.ok)
    console.log('Ok!')
  else
    console.log('Not ok!')
})

Usage

NPM

parser = tapConsole()

Creates a new TAP parser and hijacks the global console.log function.

parser.attach()

Hijacks the console.log function. Any subsequent logs will be captured by this parser and not printed to the native console.

parser.detach()

Un-hijacks the console.log function. Subsequent logs will not be parsed, and will be passed to the native console as usual.

parser.log(args)

The native console.log() function, can be used while the parser is attached to actually log something to the console.

parser.on('assert', fn)

Called when an assertion is met, see tap-out#assert.

parser.on('test', fn)

Called when a new test block is met, see tap-out#test

parser.on('complete', fn)

Called when tests, fail and pass have been parsed, and we can assume the test is over. The passed parameter looks like:

{
  ok: false,
  total: 3,
  pass: 2,
  fail: 1
}

parser.on('log', fn)

Called whenever console.log() is called with args, an array of the user's arguments. It allows you to pass along logs to the native console like so:

parser.on('log', function(args) {
  parser.log.apply(null, args)
})

License

MIT, see LICENSE.md for details.

tap-console-parser's People

Contributors

mattdesl avatar timoxley avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.