Improve test fixtures
This commit is contained in:
4
tests/fixtures/events.fixtures.ts
vendored
4
tests/fixtures/events.fixtures.ts
vendored
@@ -2,14 +2,14 @@ import type { SSEvent } from '../../src/types.js';
|
|||||||
|
|
||||||
type EventFixture = {
|
type EventFixture = {
|
||||||
raw: string;
|
raw: string;
|
||||||
parsed?: SSEvent[];
|
parsed: SSEvent[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Combines all the raw strings into a single chunk and flattens the parsed arrays into a single array to simulate multi-event chunks. */
|
/** Combines all the raw strings into a single chunk and flattens the parsed arrays into a single array to simulate multi-event chunks. */
|
||||||
const withCombinedChunk = (fixtures: EventFixture[]): EventFixture => {
|
const withCombinedChunk = (fixtures: EventFixture[]): EventFixture => {
|
||||||
return {
|
return {
|
||||||
raw: fixtures.map(({ raw }) => raw).join(''),
|
raw: fixtures.map(({ raw }) => raw).join(''),
|
||||||
parsed: fixtures.flatMap(({ parsed }) => parsed ?? []),
|
parsed: fixtures.flatMap(({ parsed }) => parsed),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ export class SseTestStream {
|
|||||||
await new Promise((resolve) => setTimeout(resolve, chunkDelayMs));
|
await new Promise((resolve) => setTimeout(resolve, chunkDelayMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.closed) return;
|
|
||||||
|
|
||||||
controller.enqueue(encoder.encode(chunks[i]!));
|
controller.enqueue(encoder.encode(chunks[i]!));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +55,6 @@ export class SseTestStream {
|
|||||||
* Ends the HTTP body the way a server closing the SSE connection would.
|
* Ends the HTTP body the way a server closing the SSE connection would.
|
||||||
*/
|
*/
|
||||||
close(): void {
|
close(): void {
|
||||||
if (this.closed) return;
|
|
||||||
|
|
||||||
this.closed = true;
|
this.closed = true;
|
||||||
this.controller?.close();
|
this.controller?.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user