test: share streaming error response helper

This commit is contained in:
Peter Steinberger
2026-04-21 00:25:34 +01:00
parent 7b5527a74e
commit 3b1ef4354f
3 changed files with 24 additions and 46 deletions

View File

@@ -0,0 +1,22 @@
export function createStreamingErrorResponse(params: {
status: number;
chunkCount: number;
chunkSize: number;
byte: number;
}): { response: Response; getReadCount: () => number } {
let reads = 0;
const stream = new ReadableStream<Uint8Array>({
pull(controller) {
if (reads >= params.chunkCount) {
controller.close();
return;
}
reads += 1;
controller.enqueue(new Uint8Array(params.chunkSize).fill(params.byte));
},
});
return {
response: new Response(stream, { status: params.status }),
getReadCount: () => reads,
};
}