Skip to content

Commit 88d8fa3

Browse files
lambdalisueclaude
andcommitted
test: add tests for lib/polyfill module
Add tests verifying that DisposableStack and AsyncDisposableStack are properly polyfilled in globalThis and their basic functionality works. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 764371c commit 88d8fa3

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

denops/fall/lib/polyfill_test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { assertEquals, assertInstanceOf } from "jsr:@std/assert@^1.0.0";
2+
import { describe, it } from "jsr:@std/testing@^1.0.0/bdd";
3+
4+
import "./polyfill.ts";
5+
6+
describe("polyfill", () => {
7+
it("should provide DisposableStack in globalThis", () => {
8+
// deno-lint-ignore no-explicit-any
9+
const stack = new (globalThis as any).DisposableStack();
10+
assertInstanceOf(stack, Object);
11+
assertEquals(typeof stack.dispose, "function");
12+
assertEquals(typeof stack.use, "function");
13+
assertEquals(typeof stack.adopt, "function");
14+
assertEquals(typeof stack.defer, "function");
15+
assertEquals(typeof stack.move, "function");
16+
17+
// Clean up
18+
stack.dispose();
19+
});
20+
21+
it("should provide AsyncDisposableStack in globalThis", () => {
22+
// deno-lint-ignore no-explicit-any
23+
const stack = new (globalThis as any).AsyncDisposableStack();
24+
assertInstanceOf(stack, Object);
25+
assertEquals(typeof stack.disposeAsync, "function");
26+
assertEquals(typeof stack.use, "function");
27+
assertEquals(typeof stack.adopt, "function");
28+
assertEquals(typeof stack.defer, "function");
29+
assertEquals(typeof stack.move, "function");
30+
31+
// Clean up
32+
stack.disposeAsync();
33+
});
34+
35+
it("should allow using DisposableStack functionality", () => {
36+
// deno-lint-ignore no-explicit-any
37+
const DisposableStack = (globalThis as any).DisposableStack;
38+
const stack = new DisposableStack();
39+
let disposed = false;
40+
41+
stack.defer(() => {
42+
disposed = true;
43+
});
44+
45+
assertEquals(disposed, false);
46+
stack.dispose();
47+
assertEquals(disposed, true);
48+
});
49+
50+
it("should allow using AsyncDisposableStack functionality", async () => {
51+
// deno-lint-ignore no-explicit-any
52+
const AsyncDisposableStack = (globalThis as any).AsyncDisposableStack;
53+
const stack = new AsyncDisposableStack();
54+
let disposed = false;
55+
56+
stack.defer(async () => {
57+
await Promise.resolve();
58+
disposed = true;
59+
});
60+
61+
assertEquals(disposed, false);
62+
await stack.disposeAsync();
63+
assertEquals(disposed, true);
64+
});
65+
});

0 commit comments

Comments
 (0)