|
1 | 1 | import assert from "assert";
|
2 | 2 | import util from "util";
|
3 |
| -import { encode, decode, ExtensionCodec, EXT_TIMESTAMP } from "../src"; |
| 3 | +import { encode, decode, ExtensionCodec, EXT_TIMESTAMP, decodeAsync } from "../src"; |
4 | 4 |
|
5 | 5 | /* eslint-disable @typescript-eslint/no-non-null-assertion */
|
6 | 6 |
|
@@ -74,11 +74,21 @@ describe("ExtensionCodec", () => {
|
74 | 74 | },
|
75 | 75 | });
|
76 | 76 |
|
77 |
| - it("encodes and decodes custom data types", () => { |
| 77 | + it("encodes and decodes custom data types (synchronously)", () => { |
78 | 78 | const set = new Set([1, 2, 3]);
|
79 | 79 | const map = new Map([["foo", "bar"], ["bar", "baz"]]);
|
80 | 80 | const encoded = encode([set, map], { extensionCodec });
|
81 | 81 | assert.deepStrictEqual(decode(encoded, { extensionCodec }), [set, map]);
|
82 | 82 | });
|
| 83 | + |
| 84 | + it("encodes and decodes custom data types (asynchronously)", async () => { |
| 85 | + const set = new Set([1, 2, 3]); |
| 86 | + const map = new Map([["foo", "bar"], ["bar", "baz"]]); |
| 87 | + const encoded = encode([set, map], { extensionCodec }); |
| 88 | + const createStream = async function*() { |
| 89 | + yield encoded; |
| 90 | + }; |
| 91 | + assert.deepStrictEqual(await decodeAsync(createStream(), { extensionCodec }), [set, map]); |
| 92 | + }); |
83 | 93 | });
|
84 | 94 | });
|
0 commit comments