diff options
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 () => { |