(
file: string,
options?: ParserOptions,
)
| 102 | } |
| 103 | |
| 104 | async function testStream( |
| 105 | file: string, |
| 106 | options?: ParserOptions, |
| 107 | ): Promise<void> { |
| 108 | const filePath = new URL(`__fixtures__/Documents/${file}`, import.meta.url); |
| 109 | |
| 110 | const [streamHandler, eventsPromise] = getPromiseEventCollector(); |
| 111 | |
| 112 | const fileContents = await fs.readFile(filePath); |
| 113 | |
| 114 | // Pipe file contents through a ReadableStream into the WebWritableStream |
| 115 | const readable = new ReadableStream<Uint8Array>({ |
| 116 | start(controller) { |
| 117 | controller.enqueue(new Uint8Array(fileContents)); |
| 118 | controller.close(); |
| 119 | }, |
| 120 | }); |
| 121 | |
| 122 | await readable.pipeTo(new WebWritableStream(streamHandler, options)); |
| 123 | |
| 124 | const events = await eventsPromise; |
| 125 | |
| 126 | expect(events).toMatchSnapshot(); |
| 127 | |
| 128 | // Verify single-pass produces identical results |
| 129 | const [singlePassHandler, singlePassPromise] = getPromiseEventCollector(); |
| 130 | |
| 131 | const singlePassReadable = new ReadableStream<string>({ |
| 132 | start(controller) { |
| 133 | controller.enqueue(fileContents.toString()); |
| 134 | controller.close(); |
| 135 | }, |
| 136 | }); |
| 137 | |
| 138 | await singlePassReadable.pipeTo( |
| 139 | new WebWritableStream(singlePassHandler, options), |
| 140 | ); |
| 141 | |
| 142 | expect(await singlePassPromise).toStrictEqual(events); |
| 143 | } |
no test coverage detected
searching dependent graphs…