diff options
author | 2023-02-14 23:58:05 -0800 | |
---|---|---|
committer | 2023-02-14 23:58:05 -0800 | |
commit | d91052516e876d9938a4dd2d9bdd25a0739f8eba (patch) | |
tree | 9aa57e7ddfd3e3d94a22cf975e5d1963bd27fff8 /test/bun.js/disabled-module.test.js | |
parent | c6ee401bf42f305470150d5a7769d857482c9067 (diff) | |
download | bun-d91052516e876d9938a4dd2d9bdd25a0739f8eba.tar.gz bun-d91052516e876d9938a4dd2d9bdd25a0739f8eba.tar.zst bun-d91052516e876d9938a4dd2d9bdd25a0739f8eba.zip |
Fix up async_hooks polyfill
Diffstat (limited to '')
-rw-r--r-- | test/bun.js/disabled-module.test.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/bun.js/disabled-module.test.js b/test/bun.js/disabled-module.test.js index 43b08731d..c12676959 100644 --- a/test/bun.js/disabled-module.test.js +++ b/test/bun.js/disabled-module.test.js @@ -6,3 +6,33 @@ test("not implemented yet module masquerades as undefined and throws an error", expect(typeof worker_threads).toBe("undefined"); expect(typeof worker_threads.getEnvironmentData).toBe("undefined"); }); + +test("AsyncLocalStorage polyfill", () => { + const { AsyncLocalStorage } = import.meta.require("async_hooks"); + + const store = new AsyncLocalStorage(); + var called = false; + expect(store.getStore()).toBe(null); + store.run({ foo: "bar" }, () => { + expect(store.getStore()).toEqual({ foo: "bar" }); + called = true; + }); + expect(store.getStore()).toBe(null); + expect(called).toBe(true); +}); + +test("AsyncResource polyfill", () => { + const { AsyncResource } = import.meta.require("async_hooks"); + + const resource = new AsyncResource("test"); + var called = false; + resource.runInAsyncScope( + () => { + called = true; + }, + null, + "foo", + "bar", + ); + expect(called).toBe(true); +}); |