Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80529 views
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
var expected = JSON.parse(fs.readFileSync(file))
10
, parser = JSONStream.parse(['rows', /\d+/ /*, 'value'*/])
11
, called = 0
12
, ended = false
13
, parsed = []
14
15
fs.createReadStream(file).pipe(parser)
16
17
parser.on('data', function (data) {
18
called ++
19
it.has({
20
id: it.typeof('string'),
21
value: {rev: it.typeof('string')},
22
key:it.typeof('string')
23
})
24
parsed.push(data)
25
})
26
27
parser.on('end', function () {
28
ended = true
29
})
30
31
process.on('exit', function () {
32
it(called).equal(expected.rows.length)
33
it(parsed).deepEqual(expected.rows)
34
console.error('PASSED')
35
})
36
37