tap-wrapper

0.0.2 • Public • Published

tap-wrapper

Build Status

Description

  • utility to prevent node-tap test results printing to STDOUT
  • receive test results in JSON format

How does it help you?

  • good for testing tap test helpers
  • used in unit tests for tap-test-helpers module

Install

npm install tap-wrapper

Docs

Yuidocs documentation here

  • link only works when checkout repo and preview README locally

Api

Helper Test Function (helperTestFn) to be wrapped

Must do 2 things:

  1. call this.end(t) instead of t.end()
    • don't forget to pass the t param to this.end
  2. bind tap.Test to this, eg: return require('tap').Test('test banner', function (t) {....}.bind(this));
var helperTestFn = function (paramToPass) {
    return require('tap').Test(testName, function (t) {
        t.equal(paramToPass, testName, 'Integration Test: WrapLoud is called');
        this.end(t);
    }.bind(this));
};

Wrap.WrapSilent(helperTestFn)

  • Wrap a function and and prevent results for going to STDOUT
  • Listen for tap.Producer 'end evt' for results of tests to be delivered in JSON format, eg:
var helperTestFnSilent = require('tap-wrapper').WrapSilent(function () {
    return require('tap').Test('test banner', function (t) {....}.bind(this));
});
 
helperTestFnSilent.Producer.on("end", function (er, total, ok) {
    console.log('JSON representation of tap.test results', this.results);
});
 
// trigger test after bound to Producer end evt
// tap test harness is silenced (does not print to STDOUT)
helperTestFnSilent.test();

Wrap.WrapLoud(helperTestFn)

  • Wrap a function and allow tap tests to print to STDOUT as normal
var helperTestFnLoud = require('tap-wrapper').WrapLoud(function () {
    return require('tap').Test('test banner', function (t) {....}.bind(this));
});
// tap test harness prints to STDOUT as normal (ie not intercepted)
helperTestFnLoud();

Full Example

var test     = require('tap').Test,
    testName           = 'randomTest',
    helperTestFn       = function (paramToPass) {
        return test(testName, function (t) {
            counter += 1;
            t.equal(paramToPass, testName, 'Integration Test: WrapLoud is called');
            this.end(t);
        }.bind(this));
    },
    helperTestFnSilent = main.WrapSilent(helperTestFn),
    helperTestFnLoud   = main.WrapLoud(helperTestFn);
 
helperTestFnSilent.Producer.on("end", function (er, total, ok) {
 
        var results = this.results;
        test('Integration Test: WrapSilent: wrappedFn.Producer end evt triggered', function (t) {
            t.equal(results.testsTotal, 1, '1 test in total');
            t.equal(results.pass, 1, '1 pass in total');
            t.equal(counter, 2, 'both silent and loud tests are called');
            t.end();
        });
 
});
 
// prints to STDOUT as normal
helperTestFnLoud(testName);
 
// silenced > collect results in JSON thru .Producer 'end' evt
helperTestFnSilent.test(testName);

Readme

Keywords

none

Package Sidebar

Install

npm i tap-wrapper

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • techjacker