Files
bun.sh/test/js/bun/resolve/resolve-error.test.ts
Zack Radisic 5ca1580427 Fix assertion failure on Windows in resolver (#21510)
### What does this PR do?

We had `bun.strings.assertIsValidWindowsPath(...)` in the resolver, but
we can't do this because the path may come from the user. Instead, let
our error handling code handle it.

Also fixes #21065

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-07-30 23:33:09 -07:00

63 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
describe("ResolveMessage", () => {
it("position object does not segfault", async () => {
try {
await import("./file-importing-nonexistent-file.js");
} catch (e: any) {
expect(Bun.inspect(e.position).length > 0).toBe(true);
expect(e.column).toBeGreaterThanOrEqual(0);
expect(e.line).toBeGreaterThanOrEqual(0);
}
});
it(".message is modifiable", async () => {
try {
await import("./file-importing-nonexistent-file.js");
} catch (e: any) {
const orig = e.message;
expect(() => (e.message = "new message")).not.toThrow();
expect(e.message).toBe("new message");
expect(e.message).not.toBe(orig);
}
});
it("has code for esm", async () => {
try {
await import("./file-importing-nonexistent-file.js");
} catch (e: any) {
expect(e.code).toBe("ERR_MODULE_NOT_FOUND");
}
});
it("has code for require.resolve", () => {
try {
require.resolve("./file-importing-nonexistent-file.js");
} catch (e: any) {
expect(e.code).toBe("MODULE_NOT_FOUND");
}
});
it("has code for require", () => {
try {
require("./file-importing-nonexistent-file.cjs");
} catch (e: any) {
expect(e.code).toBe("MODULE_NOT_FOUND");
}
});
it("invalid data URL import", async () => {
expect(async () => {
// @ts-ignore
await import("data:Hello%2C%20World!");
}).toThrow("Cannot resolve invalid data URL");
});
it("doesn't crash", async () => {
expect(async () => {
// @ts-ignore
await import(":://filesystem");
}).toThrow("Cannot find module");
});
});