test(plugin): harden source loader fallback tests

This commit is contained in:
Vincent Koc
2026-05-03 22:59:10 -07:00
parent da1e1435ad
commit 6e8cdd7d59
2 changed files with 7 additions and 12 deletions

View File

@@ -82,7 +82,7 @@ describe("channel plugin module loader helpers", () => {
expect(createJiti).not.toHaveBeenCalled();
});
it("loads TypeScript channel plugin modules through Jiti when no native hook exists", async () => {
it("loads TypeScript channel plugin modules through Jiti when native loading is unavailable", async () => {
const loadWithJiti = vi.fn((target: string) => ({
loadedBy: "jiti",
target,
@@ -103,7 +103,7 @@ describe("channel plugin module loader helpers", () => {
const rootDir = createTempDir();
const modulePath = path.join(rootDir, "extensions", "demo", "index.ts");
fs.mkdirSync(path.dirname(modulePath), { recursive: true });
fs.writeFileSync(modulePath, "export const ok = true;\n", "utf8");
fs.writeFileSync(modulePath, 'throw new Error("native source load failed");\n', "utf8");
try {
expect(

View File

@@ -285,7 +285,7 @@ describe("loadBundledEntryExportSync", () => {
});
it("keeps Windows dist sidecar loads off source-transform loading", async () => {
const createJiti = vi.fn(() => vi.fn(() => ({ load: 42 })));
const createJiti = vi.fn(() => vi.fn(() => ({ load: 0 })));
stubPluginModuleLoaderJitiFactory(createJiti as unknown as PluginModuleLoaderFactory);
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
@@ -300,22 +300,17 @@ describe("loadBundledEntryExportSync", () => {
fs.mkdirSync(pluginRoot, { recursive: true });
const importerPath = path.join(pluginRoot, "index.js");
const helperPath = path.join(pluginRoot, "helper.ts");
const helperPath = path.join(pluginRoot, "helper.cjs");
fs.writeFileSync(importerPath, "export default {};\n", "utf8");
fs.writeFileSync(helperPath, "export const load = 42;\n", "utf8");
fs.writeFileSync(helperPath, "module.exports = { load: 42 };\n", "utf8");
expect(
channelEntryContract.loadBundledEntryExportSync<number>(pathToFileURL(importerPath).href, {
specifier: "./helper.ts",
specifier: "./helper.cjs",
exportName: "load",
}),
).toBe(42);
expect(createJiti).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
tryNative: false,
}),
);
expect(createJiti).not.toHaveBeenCalled();
} finally {
platformSpy.mockRestore();
}