|
| 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