index.js 525 B

12345678910111213141516171819202122232425262728293031
  1. var through = require("through")
  2. var test = require("tape")
  3. var duplex = require("../index")
  4. var readable = through()
  5. var writable = through(write)
  6. var written = 0
  7. var data = 0
  8. var stream = duplex(writable, readable)
  9. function write() {
  10. written++
  11. }
  12. stream.on("data", ondata)
  13. function ondata() {
  14. data++
  15. }
  16. test("emit and write", function(t) {
  17. t.plan(2)
  18. stream.write()
  19. readable.emit("data")
  20. t.equal(written, 1, "should have written once")
  21. t.equal(data, 1, "should have received once")
  22. })