Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/techjacker/tap-wrapper
Get node-tap results returned in JSON rather than printing to STDOUT
https://github.com/techjacker/tap-wrapper
Last synced: 12 days ago
JSON representation
Get node-tap results returned in JSON rather than printing to STDOUT
- Host: GitHub
- URL: https://github.com/techjacker/tap-wrapper
- Owner: techjacker
- License: mit
- Created: 2013-06-17T16:55:43.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-06-18T18:20:41.000Z (over 11 years ago)
- Last Synced: 2024-12-17T04:43:17.566Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 156 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tap-wrapper
[](http://travis-ci.org/techjacker/tap-wrapper)
## Description
- utility to prevent [node-tap](https://github.com/isaacs/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](https://npmjs.org/package/tap-test-helpers) module## Install
```Shell
npm install tap-wrapper
```### Docs
[Yuidocs documentation here](docs/index.html)
- 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));``````JavaScript
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:```JavaScript
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```JavaScript
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
```JavaScript
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);
```