Skip to content

Commit 00aa133

Browse files
committedNov 15, 2017
Add "onFinish" listener to test harness.
1 parent 0e68b2d commit 00aa133

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed
 

‎index.js

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ exports = module.exports = (function () {
3939
lazyLoad.onFinish = function () {
4040
return getHarness().onFinish.apply(this, arguments);
4141
};
42+
43+
lazyLoad.onFailure = function() {
44+
return getHarness().onFailure.apply(this, arguments);
45+
};
4246

4347
lazyLoad.getHarness = getHarness
4448

@@ -134,6 +138,10 @@ function createHarness (conf_) {
134138
test.onFinish = function (cb) {
135139
results.on('done', cb);
136140
};
141+
142+
test.onFailure = function (cb) {
143+
results.on('fail', cb);
144+
};
137145

138146
var only = false;
139147
test.only = function () {

‎lib/results.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ Results.prototype._watch = function (t) {
104104
self.count ++;
105105

106106
if (res.ok) self.pass ++
107-
else self.fail ++
107+
else {
108+
self.fail ++;
109+
self.emit('fail');
110+
}
108111
});
109112

110113
t.on('test', function (st) { self._watch(st) });

‎readme.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ Generate a new test that will be skipped over.
162162
The onFinish hook will get invoked when ALL tape tests have finished
163163
right before tape is about to print the test summary.
164164

165+
## test.onFailure(fn)
166+
167+
The onFailure hook will get invoked whenever any tape tests has failed.
168+
165169
## t.plan(n)
166170

167171
Declare that `n` assertions should be run. `t.end()` will be called

‎test/onFailure.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var tap = require("tap");
2+
var tape = require("../").createHarness();
3+
4+
//Because this test passing depends on a failure,
5+
//we must direct the failing output of the inner test
6+
var noop = function(){}
7+
var mockSink = {on:noop, removeListener:noop, emit:noop, end:noop}
8+
tape.createStream().pipe(mockSink);
9+
10+
tap.test("on failure", { timeout: 1000 }, function(tt) {
11+
tt.plan(1);
12+
13+
tape("dummy test", function(t) {
14+
t.fail();
15+
t.end();
16+
});
17+
18+
tape.onFailure(function() {
19+
tt.pass("tape ended");
20+
});
21+
});

0 commit comments

Comments
 (0)
Please sign in to comment.