summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/tar/node_modules/minipass/test/empty-end.js
blob: 42387d51af7732815d85c9e2f29f3cd7b3291d10 (plain)
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
const t = require('tap')
const MP = require('../')

t.test('emit end on resume', async t => {
  const list = []
  const mp = new MP()
  mp.on('end', _ => list.push('end'))
  mp.end()
  t.notOk(mp.emittedEnd)
  list.push('called end')
  mp.resume()
  t.ok(mp.emittedEnd)
  list.push('called resume')
  t.same(list, ['called end', 'end', 'called resume'])
})

t.test('emit end on read()', async t => {
  const list = []
  const mp = new MP()
  mp.on('end', _ => list.push('end'))
  mp.end()
  list.push('called end')

  mp.read()
  list.push('called read()')
  t.same(list, ['called end', 'end', 'called read()'])
})

t.test('emit end on data handler', async t => {
  const list = []
  const mp = new MP()
  mp.on('end', _ => list.push('end'))
  mp.end()
  list.push('called end')
  mp.on('data', _=>_)
  list.push('added data handler')
  t.same(list, ['called end', 'end', 'added data handler'])
})