Rename src to source
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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";
|
||||
|
||||
describe("stream lifecycle observers", () => {
|
||||
it("buffers exactly one normal HTTP response", async () => {
|
||||
const stream = new HttpRequestStream();
|
||||
|
||||
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");
|
||||
});
|
||||
|
||||
it("notifies WebSocket observers registered after remote closure", () => {
|
||||
const stream = new WSStream({
|
||||
send: vi.fn(),
|
||||
close: vi.fn(),
|
||||
readyState: 1,
|
||||
});
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user