-
Notifications
You must be signed in to change notification settings - Fork 16
/
test-writable.js
30 lines (21 loc) · 716 Bytes
/
test-writable.js
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
'use strict'
const test = require('tape-promise').default(require('tape'))
const Stream = require('stream')
const streamToPromise = require('./')
test('writable/success', async function (t) {
const [writable, promise] = Writable()
writable.emit('finish')
t.equal(await promise, undefined, 'returns undefined')
})
test('writable/error', async function (t) {
const [writable, promise] = Writable()
const err = new Error('oh no')
writable.emit('error', err)
return t.rejects(promise, /oh no/, 'rejects with error')
})
function Writable () {
const writable = new Stream.Writable()
writable._read = function noop () {}
const promise = streamToPromise(writable)
return [writable, promise]
}