Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
this test adds nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 20, 2023
1 parent 9bbd733 commit 4126f82
Showing 1 changed file with 0 additions and 92 deletions.
92 changes: 0 additions & 92 deletions src/async/sse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,98 +113,6 @@ test("SSE response test", async () => {
}
});

test("handle reconnects when response is interrupted", async () => {
let i = 0;

let kill = false;
function createMockObj() {
async function* generator() {
while (true) {
yield BigInt(i);
i++;
await sleep(10);

if (i === 5) {
kill = true;
}

if (i > 10) {
// done
return;
}
}
}

return {
iterable: generator(),
};
}

type MockObj = ReturnType<typeof createMockObj>;

// ------------- server -------------------
const opts = {
nonce: () => "__tson" + i, // add index to nonce to make sure it's not cached
types: [tsonPromise, tsonAsyncIterable, tsonBigint],
} satisfies TsonAsyncOptions;

const server = await createTestServer({
handleRequest: async (_req, res) => {
const tson = createTsonAsync(opts);

const obj = createMockObj();
const response = tson.toSSEResponse(obj);

for (const [key, value] of response.headers) {
res.setHeader(key, value);
}

for await (const value of response.body as any) {
res.write(value);
if (kill) {
// interrupt the stream
res.end();
kill = false;
return;
}
}

res.end();
},
});

// ------------- client -------------------
const tson = createTsonAsync(opts);

// e2e
const ac = new AbortController();
const shape = await tson.createEventSource<MockObj>(server.url, {
reconnect: true,
signal: ac.signal,
});

const messages: bigint[] = [];

for await (const value of shape.iterable) {
messages.push(value);
}

expect(messages).toMatchInlineSnapshot(`
[
0n,
1n,
2n,
3n,
4n,
5n,
7n,
8n,
9n,
10n,
]
`);
});

test("handle reconnects - iterator wrapped in Promise", async () => {
let i = 0;

Expand Down

0 comments on commit 4126f82

Please sign in to comment.