• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 var fs = require ('fs')
2   , join = require('path').join
3   , file = join(__dirname, 'fixtures','depth.json')
4   , JSONStream = require('../')
5   , it = require('it-is')
6
7 var expected = JSON.parse(fs.readFileSync(file))
8   , parser = JSONStream.parse(['docs', {recurse: true}, 'value'])
9   , called = 0
10   , ended = false
11   , parsed = []
12
13 fs.createReadStream(file).pipe(parser)
14
15 parser.on('data', function (data) {
16   called ++
17   parsed.push(data)
18 })
19
20 parser.on('end', function () {
21   ended = true
22 })
23
24 process.on('exit', function () {
25   var expectedValues = [0, [1], {"a": 2}, "3", 4]
26   it(called).equal(expectedValues.length)
27   for (var i = 0 ; i < 5 ; i++)
28     it(parsed[i]).deepEqual(expectedValues[i])
29   console.error('PASSED')
30 })
31