Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

test.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var tape = require('tape')
  2. var writer = require('./')
  3. tape('is a write stream', function (t) {
  4. var expected = ['hello', 'world', 'verden']
  5. var ws = writer.obj(write)
  6. ws.write('hello')
  7. ws.write('world')
  8. ws.write('verden')
  9. ws.end(function () {
  10. t.same(expected.length, 0)
  11. t.end()
  12. })
  13. function write (data, enc, cb) {
  14. t.same(data, expected.shift())
  15. cb()
  16. }
  17. })
  18. tape('is flushable', function (t) {
  19. var expected = ['hello', 'world', 'verden']
  20. var flushed = false
  21. var ws = writer.obj(write, flush)
  22. ws.write('hello')
  23. ws.write('world')
  24. ws.write('verden')
  25. ws.end(function () {
  26. t.same(expected.length, 0)
  27. t.ok(flushed, 'was flushed')
  28. t.end()
  29. })
  30. function write (data, enc, cb) {
  31. t.same(data, expected.shift())
  32. cb()
  33. }
  34. function flush (cb) {
  35. flushed = true
  36. process.nextTick(cb)
  37. }
  38. })
  39. tape('can pass options', function (t) {
  40. var expected = ['hello', 'world', 'verden']
  41. var flushed = false
  42. var ws = writer({objectMode: true}, write, flush)
  43. ws.write('hello')
  44. ws.write('world')
  45. ws.write('verden')
  46. ws.end(function () {
  47. t.same(expected.length, 0)
  48. t.ok(flushed, 'was flushed')
  49. t.end()
  50. })
  51. function write (data, enc, cb) {
  52. t.same(data, expected.shift())
  53. cb()
  54. }
  55. function flush (cb) {
  56. flushed = true
  57. process.nextTick(cb)
  58. }
  59. })
  60. tape('emits error on destroy', function (t) {
  61. var expected = new Error()
  62. var ws = writer({objectMode: true}, function () {})
  63. ws.on('error', function (err) {
  64. t.equal(err, expected)
  65. })
  66. ws.on('close', t.end)
  67. ws.destroy(expected)
  68. })