File: try_catch.asynct.js

package info (click to toggle)
node-split 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 120 kB
  • sloc: javascript: 260; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var it = require('it-is').style('colour')
  , split = require('..')

exports ['emit mapper exceptions as error events'] = function (test) {
  var s = split(JSON.parse)
    , caughtError = false
    , rows = []
 
  s.on('error', function (err) {
    caughtError = true
  })
 
  s.on('data', function (row) { rows.push(row) })

  s.write('{"a":1}\n{"')
  it(caughtError).equal(false)
  it(rows).deepEqual([ { a: 1 } ])

  s.write('b":2}\n{"c":}\n')
  it(caughtError).equal(true)
  it(rows).deepEqual([ { a: 1 }, { b: 2 } ])

  s.end()
  test.done()
}

exports ['mapper error events on trailing chunks'] = function (test) {
  var s = split(JSON.parse)
    , caughtError = false
    , rows = []
 
  s.on('error', function (err) {
    caughtError = true
  })
 
  s.on('data', function (row) { rows.push(row) })

  s.write('{"a":1}\n{"')
  it(caughtError).equal(false)
  it(rows).deepEqual([ { a: 1 } ])

  s.write('b":2}\n{"c":}')
  it(caughtError).equal(false)
  it(rows).deepEqual([ { a: 1 }, { b: 2 } ])

  s.end()
  it(caughtError).equal(true)
  it(rows).deepEqual([ { a: 1 }, { b: 2 } ])

  test.done()
}