Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "onFailure" listener to test harness. #408

Merged
merged 1 commit into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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");
});
});