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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 5, 2023
1 parent 15c7b94 commit b6ae20d
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/async/deserializeAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ test("stringify async iterable + promise", async () => {
async function* iterable() {
await new Promise((resolve) => setTimeout(resolve, 1));
yield 1n;
await new Promise((resolve) => setTimeout(resolve, 1));
yield 2n;
await new Promise((resolve) => setTimeout(resolve, 30));
yield 3n;

await new Promise((resolve) => setTimeout(resolve, 1));
yield 4n;
}

const input = {
Expand All @@ -81,10 +87,10 @@ test("stringify async iterable + promise", async () => {
result.push(value);
}

expect(result).toEqual([1n, 2n]);
expect(result).toEqual([1n, 2n, 3n, 4n]);
});

test("e2e: stringify and parse promise with a promise over a network connection", async () => {
test.only("e2e: stringify and parse promise with a promise over a network connection", async () => {
function createMockObj() {
async function* generator() {
await new Promise((resolve) => setTimeout(resolve, 1));
Expand Down Expand Up @@ -115,6 +121,9 @@ test("e2e: stringify and parse promise with a promise over a network connection"
const obj = createMockObj();
const strIterarable = tson.stringify(obj, 4);

// set proper header for chunked responses
// res.setHeader("Transfer-Encoding", "chunked");

for await (const value of strIterarable) {
res.write(value);
}
Expand Down Expand Up @@ -155,22 +164,7 @@ test("e2e: stringify and parse promise with a promise over a network connection"
results.push(value);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
expect(spy.mock.calls.map((it) => it[0])).toMatchInlineSnapshot(`
[
"[
{\\"json\\":{\\"foo\\":\\"bar\\",\\"iterable\\":[\\"AsyncIterator\\",0,\\"__tson\\"],\\"promise\\":[\\"Promise\\",1,\\"__tson\\"]},\\"nonce\\":\\"__tson\\"}
,
[
[1,[0,42]]",
" ,[0,[0,[\\"bigint\\",\\"1\\",\\"__tson\\"]]]",
" ,[0,[0,[\\"bigint\\",\\"2\\",\\"__tson\\"]]]
,[0,[2]]
]
]",
]
`);

expect(results).toEqual([1n, 2n]);

server.close();
});

0 comments on commit b6ae20d

Please sign in to comment.