1 |
|
2 |
|
3 | var fs = require ('fs')
|
4 | , join = require('path').join
|
5 | , file = join(__dirname, 'fixtures','all_npm.json')
|
6 | , JSONStream = require('../')
|
7 | , it = require('it-is')
|
8 |
|
9 | function fn (s) {
|
10 | return !isNaN(parseInt(s, 10))
|
11 | }
|
12 |
|
13 | var expected = JSON.parse(fs.readFileSync(file))
|
14 | , parser = JSONStream.parse(['rows', fn])
|
15 | , called = 0
|
16 | , ended = false
|
17 | , parsed = []
|
18 |
|
19 | fs.createReadStream(file).pipe(parser)
|
20 |
|
21 | parser.on('data', function (data) {
|
22 | called ++
|
23 | it.has({
|
24 | id: it.typeof('string'),
|
25 | value: {rev: it.typeof('string')},
|
26 | key:it.typeof('string')
|
27 | })
|
28 | parsed.push(data)
|
29 | })
|
30 |
|
31 | parser.on('end', function () {
|
32 | ended = true
|
33 | })
|
34 |
|
35 | process.on('exit', function () {
|
36 | it(called).equal(expected.rows.length)
|
37 | it(parsed).deepEqual(expected.rows)
|
38 | console.error('PASSED')
|
39 | })
|