Skip to content

Commit 7092104

Browse files
author
James Halliday
committed
remove .bind(), formatting
1 parent dad32ff commit 7092104

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

lib/test.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ function Test (name_, opts_, cb_) {
4242
this._cb = cb;
4343
this._progeny = [];
4444
this._ok = true;
45+
this.end = function () {
46+
return Test.prototype.end.apply(self, arguments);
47+
};
4548
}
4649

4750
Test.prototype.run = function () {
@@ -92,9 +95,12 @@ Test.prototype.plan = function (n) {
9295
this.emit('plan', n);
9396
};
9497

95-
Test.prototype.end = function () {
98+
Test.prototype.end = function (err) {
9699
var self = this;
97-
100+
if (arguments.length === 1) {
101+
this.ifError(err);
102+
}
103+
98104
if (this._progeny.length) {
99105
var t = this._progeny.shift();
100106
t.on('end', function () {
@@ -136,11 +142,11 @@ Test.prototype._exit = function () {
136142
Test.prototype._pendingAsserts = function () {
137143
if (this._plan === undefined) {
138144
return 1;
139-
} else {
140-
return this._plan -
141-
(this._progeny.length + this.assertCount);
142145
}
143-
}
146+
else {
147+
return this._plan - (this._progeny.length + this.assertCount);
148+
}
149+
};
144150

145151
Test.prototype._assert = function assert (ok, opts) {
146152
var self = this;

test/end-as-callback.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
var tap = require("tap");
2+
var tape = require("../");
3+
4+
tap.test("tape assert.end as callback", function (tt) {
5+
var test = tape.createHarness({ exit: false })
6+
var tc = tap.createConsumer()
7+
8+
var rows = []
9+
tc.on("data", function (r) { rows.push(r) })
10+
tc.on("end", function () {
11+
var rs = rows.map(function (r) {
12+
return r && typeof r === "object" ?
13+
{ id: r.id, ok: r.ok, name: r.name.trim() } :
14+
r
15+
})
16+
17+
tt.deepEqual(rs, [
18+
"TAP version 13",
19+
"do a task and write",
20+
{ id: 1, ok: true, name: "null" },
21+
{ id: 2, ok: true, name: "should be equal" },
22+
{ id: 3, ok: true, name: "null" },
23+
"do a task and write fail",
24+
{ id: 4, ok: true, name: "null" },
25+
{ id: 5, ok: true, name: "should be equal" },
26+
{ id: 6, ok: false, name: "Error: fail" },
27+
"tests 6",
28+
"pass 5",
29+
"fail 1"
30+
])
31+
32+
tt.end()
33+
})
34+
35+
test.createStream().pipe(tc)
36+
37+
test("do a task and write", function (assert) {
38+
fakeAsyncTask("foo", function (err, value) {
39+
assert.ifError(err)
40+
assert.equal(value, "taskfoo")
41+
42+
fakeAsyncWrite("bar", assert.end)
43+
})
44+
})
45+
46+
test("do a task and write fail", function (assert) {
47+
fakeAsyncTask("bar", function (err, value) {
48+
assert.ifError(err)
49+
assert.equal(value, "taskbar")
50+
51+
fakeAsyncWriteFail("baz", assert.end)
52+
})
53+
})
54+
})
55+
56+
function fakeAsyncTask(name, cb) {
57+
cb(null, "task" + name)
58+
}
59+
60+
function fakeAsyncWrite(name, cb) {
61+
cb(null)
62+
}
63+
64+
function fakeAsyncWriteFail(name, cb) {
65+
cb(new Error("fail"))
66+
}

0 commit comments

Comments
 (0)