diff options
author | 2023-07-24 19:32:04 -0700 | |
---|---|---|
committer | 2023-07-24 19:32:04 -0700 | |
commit | 8a0152e1290658d8167609cb23a7d19817ad4285 (patch) | |
tree | 3ec808e103ed2c360a038c2a22c6b7161bd4adb7 /test/js | |
parent | 1f1d0bfcfbc839cad76c9bc2d644bfa8bd299a1a (diff) | |
download | bun-8a0152e1290658d8167609cb23a7d19817ad4285.tar.gz bun-8a0152e1290658d8167609cb23a7d19817ad4285.tar.zst bun-8a0152e1290658d8167609cb23a7d19817ad4285.zip |
Merge import.meta.require and require to be the same thing (#3732)
* Merge import.meta.require and require to be the same thing
* support `require` and BunPlugin (runtime plugin)
* plugins
* unused code
* revert launch.json
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/plugin/plugins.d.ts | 2 | ||||
-rw-r--r-- | test/js/bun/plugin/plugins.test.ts | 38 |
2 files changed, 38 insertions, 2 deletions
diff --git a/test/js/bun/plugin/plugins.d.ts b/test/js/bun/plugin/plugins.d.ts index aebfd952b..ba88ef7be 100644 --- a/test/js/bun/plugin/plugins.d.ts +++ b/test/js/bun/plugin/plugins.d.ts @@ -9,3 +9,5 @@ declare module "async-obj:*"; declare module "obj:*"; declare module "delay:*"; declare module "./*.svelte"; +declare module "rejected-promise:*"; +declare module "rejected-promise2:*"; diff --git a/test/js/bun/plugin/plugins.test.ts b/test/js/bun/plugin/plugins.test.ts index f754ffbb3..c2827f600 100644 --- a/test/js/bun/plugin/plugins.test.ts +++ b/test/js/bun/plugin/plugins.test.ts @@ -160,6 +160,29 @@ plugin({ }, }); +plugin({ + name: "instant rejected load promise", + setup(builder) { + builder.onResolve({ filter: /.*/, namespace: "rejected-promise" }, ({ path }) => ({ + namespace: "rejected-promise", + path, + })); + + builder.onLoad({ filter: /.*/, namespace: "rejected-promise" }, async ({ path }) => { + throw new Error("Rejected Promise"); + }); + + builder.onResolve({ filter: /.*/, namespace: "rejected-promise2" }, ({ path }) => ({ + namespace: "rejected-promise2", + path, + })); + + builder.onLoad({ filter: /.*/, namespace: "rejected-promise2" }, ({ path }) => { + return Promise.reject(new Error("Rejected Promise")); + }); + }, +}); + // This is to test that it works when imported from a separate file import "../../third_party/svelte"; @@ -326,12 +349,23 @@ describe("errors", () => { } }); - it.skip("async transpiler errors work", async () => { + it("async transpiler errors work", async () => { expect(async () => { globalThis.asyncOnLoad = `const x: string = -NaNAn../!!;`; await import("async:fail"); throw -1; - }).toThrow('Cannot find package "'); + }).toThrow('4 errors building "async:fail"'); + }); + + it("onLoad returns the rejected promise", async () => { + expect(async () => { + await import("rejected-promise:hi"); + throw -1; + }).toThrow("Rejected Promise"); + expect(async () => { + await import("rejected-promise2:hi"); + throw -1; + }).toThrow("Rejected Promise"); }); it("can work with http urls", async () => { |