Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

failing test for empty results

  • Loading branch information...
commit 21e76cb7b1b663e712a6e705cb8f74f220ee2ccf 1 parent 707a705
@substack substack authored
Showing with 44 additions and 0 deletions.
  1. +44 −0 test/empty.js
View
44 test/empty.js
@@ -0,0 +1,44 @@
+var JSONStream = require('../')
+ , stream = require('stream')
+ , it = require('it-is')
+
+var output = [ [], [] ]
+
+var parser1 = JSONStream.parse(['docs', /./])
+parser1.on('data', function(data) {
+ output[0].push(data)
+})
+
+var parser2 = JSONStream.parse(['docs', /./])
+parser2.on('data', function(data) {
+ output[1].push(data)
+})
+
+var pending = 2
+function onend () {
+ if (--pending > 0) return
+ it(output).deepEqual([
+ [], [{hello: 'world'}]
+ ])
+ console.error('PASSED')
+}
+parser1.on('end', onend)
+parser2.on('end', onend)
+
+function makeReadableStream() {
+ var readStream = new stream.Stream()
+ readStream.readable = true
+ readStream.write = function (data) { this.emit('data', data) }
+ readStream.end = function (data) { this.emit('end') }
+ return readStream
+}
+
+var emptyArray = makeReadableStream()
+emptyArray.pipe(parser1)
+emptyArray.write('{"docs":[]}')
+emptyArray.end()
+
+var objectArray = makeReadableStream()
+objectArray.pipe(parser2)
+objectArray.write('{"docs":[{"hello":"world"}]}')
+objectArray.end()
Please sign in to comment.
Something went wrong with that request. Please try again.