| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | var test = require('tape') |
| 2 | var through = require('../') |
| 3 | |
| 4 | // must emit end before close. |
| 5 | |
| 6 | test('end before close', function (assert) { |
| 7 | var ts = through() |
| 8 | var ended = false, closed = false |
| 9 | |
| 10 | ts.on('end', function () { |
| 11 | assert.ok(!closed) |
| 12 | ended = true |
| 13 | }) |
| 14 | ts.on('close', function () { |
| 15 | assert.ok(ended) |
| 16 | closed = true |
| 17 | }) |
| 18 | |
| 19 | ts.write(1) |
| 20 | ts.write(2) |
| 21 | ts.write(3) |
| 22 | ts.end() |
| 23 | assert.ok(ended) |
| 24 | assert.ok(closed) |
| 25 | assert.end() |
| 26 | }) |
| 27 | |
| 28 | test('end only once', function (t) { |
| 29 | |
| 30 | var ts = through() |
| 31 | var ended = false, closed = false |
| 32 | |
| 33 | ts.on('end', function () { |
| 34 | t.equal(ended, false) |
| 35 | ended = true |
| 36 | }) |
| 37 | |
| 38 | ts.queue(null) |
| 39 | ts.queue(null) |
| 40 | ts.queue(null) |
| 41 | |
| 42 | ts.resume() |
| 43 | |
| 44 | t.end() |
| 45 | }) |