• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2var fs = require ('fs')
3  , join = require('path').join
4  , file = join(__dirname, 'fixtures','all_npm.json')
5  , JSONStream = require('../')
6  , it = require('it-is').style('colour')
7  , es = require('event-stream')
8  , pending = 10
9  , passed = true
10
11  function randomObj () {
12    return (
13      Math.random () < 0.4
14      ? {hello: 'eonuhckmqjk',
15          whatever: 236515,
16          lies: true,
17          nothing: [null],
18          stuff: [Math.random(),Math.random(),Math.random()]
19        }
20      : ['AOREC', 'reoubaor', {ouec: 62642}, [[[], {}, 53]]]
21    )
22  }
23
24for (var ix = 0; ix < pending; ix++) (function (count) {
25  var expected =  {}
26    , stringify = JSONStream.stringifyObject()
27
28  es.connect(
29    stringify,
30    es.writeArray(function (err, lines) {
31      it(JSON.parse(lines.join(''))).deepEqual(expected)
32      if (--pending === 0) {
33        console.error('PASSED')
34      }
35    })
36  )
37
38  while (count --) {
39    var key = Math.random().toString(16).slice(2)
40    expected[key] = randomObj()
41    stringify.write([ key, expected[key] ])
42  }
43
44  process.nextTick(function () {
45    stringify.end()
46  })
47})(ix)
48