fn.js 785 B

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