-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Readable, pipeline, PassThrough } from 'stream'; | ||
|
||
import { asyncReadable, AsyncReadable } from '../lib/async-readable'; | ||
import { reader } from '../lib/utils'; | ||
|
||
|
||
|
||
|
||
|
||
describe('reader', () => { | ||
|
||
const source = Buffer.from([ 1, 2, 3, 4, 5 ]); | ||
|
||
const readable = new Readable({ | ||
|
||
highWaterMark: 1, | ||
|
||
read () { | ||
this.push(source); | ||
this.push(null); | ||
}, | ||
|
||
}); | ||
|
||
class Oops extends Error {} | ||
|
||
const gen = async function* ({ read }: AsyncReadable) { | ||
yield* await Promise.all([ read(1), read(1), read(1) ]); | ||
yield read(1); | ||
throw new Oops(); | ||
yield read(1); | ||
}; | ||
|
||
|
||
test('error w/ destroy', done => { | ||
|
||
const fn = jest.fn(); | ||
|
||
const stream = new Readable({ | ||
objectMode: false, | ||
read: reader(gen(asyncReadable(readable)), fn), | ||
}); | ||
|
||
pipeline(stream, new PassThrough(), error => { | ||
|
||
expect(fn).toHaveBeenCalled(); | ||
expect(error).toBeInstanceOf(Oops); | ||
|
||
done(); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|