Files
bun.sh/test/js/bun/resolve/resolve-error.test.ts
2025-07-16 23:07:23 -07:00

56 lines
1.5 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");
});
});