diff options
| author | 2023-03-04 17:38:44 -0800 | |
|---|---|---|
| committer | 2023-03-04 17:38:44 -0800 | |
| commit | 1843a37ebbf6aad4ae91255b3665e649aa52aa74 (patch) | |
| tree | 42ac7c396597d72913a3e5f856218ec8a1a64212 /test/bun.js/disabled-module.test.js | |
| parent | f333a0c24326ed0ca5e4bb109be541feefa9be44 (diff) | |
| download | bun-1843a37ebbf6aad4ae91255b3665e649aa52aa74.tar.gz bun-1843a37ebbf6aad4ae91255b3665e649aa52aa74.tar.zst bun-1843a37ebbf6aad4ae91255b3665e649aa52aa74.zip | |
oops
Diffstat (limited to '')
| -rw-r--r-- | test/bun.js/disabled-module.test.js | 94 |
1 files changed, 30 insertions, 64 deletions
diff --git a/test/bun.js/disabled-module.test.js b/test/bun.js/disabled-module.test.js index 61411aa44..c12676959 100644 --- a/test/bun.js/disabled-module.test.js +++ b/test/bun.js/disabled-module.test.js @@ -1,72 +1,38 @@ import { expect, test } from "bun:test"; -// test("not implemented yet module masquerades as undefined and throws an error", () => { -// const worker_threads = import.meta.require("worker_threads"); +test("not implemented yet module masquerades as undefined and throws an error", () => { + const worker_threads = import.meta.require("worker_threads"); -// expect(typeof worker_threads).toBe("undefined"); -// expect(typeof worker_threads.getEnvironmentData).toBe("undefined"); -// }); - -test("AsyncContext", async done => { - const { AsyncContext } = import.meta.require("async_hooks"); - console.log("here"); - const ctx = new AsyncContext(); - ctx - .run(1234, async () => { - expect(ctx.get()).toBe(1234); - console.log("here"); - await 1; - console.log("ctx", ctx.get()); - const setTimeoutResult = await ctx.run( - 2345, - () => - new Promise(resolve => { - queueMicrotask(() => { - console.log("queueMicrotask", ctx.get()); - resolve(ctx.get()); - }); - }), - ); - expect(setTimeoutResult).toBe(2345); - expect(ctx.get()).toBe(1234); - return "final result"; - }) - .then(result => { - expect(result).toBe("final result"); - // The code that generated the Promise has access to the 1234 - // value provided to ctx.run above, but consumers of the Promise - // do not automatically inherit it. - expect(ctx.get()).toBeUndefined(); - done(); - }); + expect(typeof worker_threads).toBe("undefined"); + expect(typeof worker_threads.getEnvironmentData).toBe("undefined"); }); -// test("AsyncLocalStorage polyfill", () => { -// const { AsyncLocalStorage } = import.meta.require("async_hooks"); +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); -// }); + 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"); +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); -// }); + const resource = new AsyncResource("test"); + var called = false; + resource.runInAsyncScope( + () => { + called = true; + }, + null, + "foo", + "bar", + ); + expect(called).toBe(true); +}); |
