MCPcopy Index your code
hub / github.com/fb55/htmlparser2 / testStream

Function testStream

src/WebWritableStream.spec.ts:104–143  ·  view source on GitHub ↗
(
    file: string,
    options?: ParserOptions,
)

Source from the content-addressed store, hash-verified

102}
103
104async 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}

Callers 1

Calls 1

getPromiseEventCollectorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…