()
| 13 | const fs = require('fs'); |
| 14 | |
| 15 | async function tests() { |
| 16 | { |
| 17 | // v1 stream |
| 18 | |
| 19 | const stream = new Stream(); |
| 20 | stream.destroy = common.mustCall(); |
| 21 | process.nextTick(() => { |
| 22 | stream.emit('data', 'hello'); |
| 23 | stream.emit('data', 'world'); |
| 24 | stream.emit('end'); |
| 25 | }); |
| 26 | |
| 27 | let res = ''; |
| 28 | stream[Symbol.asyncIterator] = Readable.prototype[Symbol.asyncIterator]; |
| 29 | for await (const d of stream) { |
| 30 | res += d; |
| 31 | } |
| 32 | assert.strictEqual(res, 'helloworld'); |
| 33 | } |
| 34 | |
| 35 | { |
| 36 | // v1 stream error |
| 37 | |
| 38 | const stream = new Stream(); |
| 39 | stream.close = common.mustCall(); |
| 40 | process.nextTick(() => { |
| 41 | stream.emit('data', 0); |
| 42 | stream.emit('data', 1); |
| 43 | stream.emit('error', new Error('asd')); |
| 44 | }); |
| 45 | |
| 46 | const iter = Readable.prototype[Symbol.asyncIterator].call(stream); |
| 47 | await iter.next() |
| 48 | .then(common.mustNotCall()) |
| 49 | .catch(common.mustCall((err) => { |
| 50 | assert.strictEqual(err.message, 'asd'); |
| 51 | })); |
| 52 | } |
| 53 | |
| 54 | { |
| 55 | // Non standard stream cleanup |
| 56 | |
| 57 | const readable = new Readable({ autoDestroy: false, read() {} }); |
| 58 | readable.push('asd'); |
| 59 | readable.push('asd'); |
| 60 | readable.destroy = null; |
| 61 | readable.close = common.mustCall(() => { |
| 62 | readable.emit('close'); |
| 63 | }); |
| 64 | |
| 65 | await (async () => { |
| 66 | for await (const d of readable) { |
| 67 | return; |
| 68 | } |
| 69 | })(); |
| 70 | } |
| 71 | |
| 72 | { |
no test coverage detected
searching dependent graphs…