Skip to content

Commit

Permalink
Add "onFinish" listener to test harness.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhenry committed Nov 15, 2017
1 parent 0e68b2d commit 00aa133
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
8 changes: 8 additions & 0 deletions index.js
Expand Up @@ -39,6 +39,10 @@ exports = module.exports = (function () {
lazyLoad.onFinish = function () {
return getHarness().onFinish.apply(this, arguments);
};

lazyLoad.onFailure = function() {
return getHarness().onFailure.apply(this, arguments);
};

lazyLoad.getHarness = getHarness

Expand Down Expand Up @@ -134,6 +138,10 @@ function createHarness (conf_) {
test.onFinish = function (cb) {
results.on('done', cb);
};

test.onFailure = function (cb) {
results.on('fail', cb);
};

var only = false;
test.only = function () {
Expand Down
5 changes: 4 additions & 1 deletion lib/results.js
Expand Up @@ -104,7 +104,10 @@ Results.prototype._watch = function (t) {
self.count ++;

if (res.ok) self.pass ++
else self.fail ++
else {
self.fail ++;
self.emit('fail');
}
});

t.on('test', function (st) { self._watch(st) });
Expand Down
4 changes: 4 additions & 0 deletions readme.markdown
Expand Up @@ -162,6 +162,10 @@ Generate a new test that will be skipped over.
The onFinish hook will get invoked when ALL tape tests have finished
right before tape is about to print the test summary.

## test.onFailure(fn)

The onFailure hook will get invoked whenever any tape tests has failed.

## t.plan(n)

Declare that `n` assertions should be run. `t.end()` will be called
Expand Down
21 changes: 21 additions & 0 deletions test/onFailure.js
@@ -0,0 +1,21 @@
var tap = require("tap");
var tape = require("../").createHarness();

//Because this test passing depends on a failure,
//we must direct the failing output of the inner test
var noop = function(){}
var mockSink = {on:noop, removeListener:noop, emit:noop, end:noop}
tape.createStream().pipe(mockSink);

tap.test("on failure", { timeout: 1000 }, function(tt) {
tt.plan(1);

tape("dummy test", function(t) {
t.fail();
t.end();
});

tape.onFailure(function() {
tt.pass("tape ended");
});
});

0 comments on commit 00aa133

Please sign in to comment.