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 | "do a task and write fail",
|
23 | { id: 3, ok: true, name: "null" },
|
24 | { id: 4, ok: true, name: "should be equal" },
|
25 | { id: 5, ok: false, name: "Error: fail" },
|
26 | "tests 5",
|
27 | "pass 4",
|
28 | "fail 1"
|
29 | ])
|
30 |
|
31 | tt.end()
|
32 | })
|
33 |
|
34 | test.createStream().pipe(tc)
|
35 |
|
36 | test("do a task and write", function (assert) {
|
37 | fakeAsyncTask("foo", function (err, value) {
|
38 | assert.ifError(err)
|
39 | assert.equal(value, "taskfoo")
|
40 |
|
41 | fakeAsyncWrite("bar", assert.end)
|
42 | })
|
43 | })
|
44 |
|
45 | test("do a task and write fail", function (assert) {
|
46 | fakeAsyncTask("bar", function (err, value) {
|
47 | assert.ifError(err)
|
48 | assert.equal(value, "taskbar")
|
49 |
|
50 | fakeAsyncWriteFail("baz", assert.end)
|
51 | })
|
52 | })
|
53 | })
|
54 |
|
55 | function fakeAsyncTask(name, cb) {
|
56 | cb(null, "task" + name)
|
57 | }
|
58 |
|
59 | function fakeAsyncWrite(name, cb) {
|
60 | cb(null)
|
61 | }
|
62 |
|
63 | function fakeAsyncWriteFail(name, cb) {
|
64 | cb(new Error("fail"))
|
65 | }
|