end.js 707 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var test = require('tape')
  2. var through = require('../')
  3. // must emit end before close.
  4. test('end before close', function (assert) {
  5. var ts = through()
  6. var ended = false, closed = false
  7. ts.on('end', function () {
  8. assert.ok(!closed)
  9. ended = true
  10. })
  11. ts.on('close', function () {
  12. assert.ok(ended)
  13. closed = true
  14. })
  15. ts.write(1)
  16. ts.write(2)
  17. ts.write(3)
  18. ts.end()
  19. assert.ok(ended)
  20. assert.ok(closed)
  21. assert.end()
  22. })
  23. test('end only once', function (t) {
  24. var ts = through()
  25. var ended = false, closed = false
  26. ts.on('end', function () {
  27. t.equal(ended, false)
  28. ended = true
  29. })
  30. ts.queue(null)
  31. ts.queue(null)
  32. ts.queue(null)
  33. ts.resume()
  34. t.end()
  35. })