Formatting

This commit is contained in:
2026-08-03 03:40:57 +00:00
parent 97d4422b8f
commit c9845d0f28
6 changed files with 214 additions and 246 deletions
+49 -53
View File
@@ -1,62 +1,58 @@
import { describe, expect, it, vi } from "vitest";
import { describe, expect, it, vi } from 'vitest';
import { HonoSSEStream } from "../../../source/services/stream/hono-sse-stream.js";
import { HttpRequestStream } from "../../../source/services/stream/http-request-stream.js";
import { WSStream } from "../../../source/services/stream/ws-stream.js";
import { HonoSSEStream } from '../../../source/services/stream/hono-sse-stream.ts';
import { HttpRequestStream } from '../../../source/services/stream/http-request-stream.ts';
import { WSStream } from '../../../source/services/stream/ws-stream.ts';
describe("stream lifecycle observers", () => {
it("buffers exactly one normal HTTP response", async () => {
const stream = new HttpRequestStream();
describe('stream lifecycle observers', (): void => {
it('buffers exactly one normal HTTP response', async (): Promise<void> => {
const stream = new HttpRequestStream();
await stream.send({
type: "response",
statusCode: 200,
body: { ok: true },
await stream.send({
type: 'response',
statusCode: 200,
body: { ok: true },
});
expect(stream.getResponse()).toEqual({
type: 'response',
statusCode: 200,
body: { ok: true },
});
await expect(stream.send({
type: 'response',
statusCode: 200,
body: { second: true },
})).rejects.toThrow('only send one response');
});
expect(stream.getResponse()).toEqual({
type: "response",
statusCode: 200,
body: { ok: true },
it('notifies WebSocket observers registered after remote closure', (): void => {
const stream = new WSStream({
send: vi.fn(),
close: vi.fn(),
readyState: 1,
});
const onClose = vi.fn();
stream.markClosed();
stream.onClose(onClose);
expect(onClose).toHaveBeenCalledOnce();
});
await expect(
stream.send({
type: "response",
statusCode: 200,
body: { second: true },
}),
).rejects.toThrow("only send one response");
});
it("notifies WebSocket observers registered after remote closure", () => {
const stream = new WSStream({
send: vi.fn(),
close: vi.fn(),
readyState: 1,
it('notifies SSE observers registered after local closure', async (): Promise<void> => {
const streamApi = {
writeSSE: vi.fn(),
close: vi.fn(),
};
const stream = new HonoSSEStream(streamApi as unknown as ConstructorParameters<typeof HonoSSEStream>[0]);
const onClose = vi.fn();
await stream.close();
stream.onClose(onClose);
await stream.close();
expect(streamApi.close).toHaveBeenCalledOnce();
expect(onClose).toHaveBeenCalledOnce();
});
const onClose = vi.fn();
stream.markClosed();
stream.onClose(onClose);
expect(onClose).toHaveBeenCalledOnce();
});
it("notifies SSE observers registered after local closure", () => {
const streamApi = {
writeSSE: vi.fn(),
close: vi.fn(),
};
const stream = new HonoSSEStream(
streamApi as unknown as ConstructorParameters<typeof HonoSSEStream>[0],
);
const onClose = vi.fn();
stream.close();
stream.onClose(onClose);
stream.close();
expect(streamApi.close).toHaveBeenCalledOnce();
expect(onClose).toHaveBeenCalledOnce();
});
});