git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { afterAll, describe, expect, it, vi } from "vitest";
|
|
|
|
const state = vi.hoisted(() => {
|
|
const originalGetBuiltinModule = Object.getOwnPropertyDescriptor(process, "getBuiltinModule");
|
|
const getBuiltinModule = process.getBuiltinModule.bind(process);
|
|
Object.defineProperty(process, "getBuiltinModule", {
|
|
configurable: true,
|
|
value: (id: string) => (id === "node:sea" ? { isSea: () => true } : getBuiltinModule(id)),
|
|
});
|
|
return {
|
|
originalGetBuiltinModule,
|
|
createJiti: vi.fn((_id: unknown, _options: unknown) => ({
|
|
import: vi.fn(async () => () => {}),
|
|
})),
|
|
};
|
|
});
|
|
|
|
vi.mock("jiti/static", () => ({ createJiti: state.createJiti }));
|
|
|
|
import { loadExtensions } from "../../../src/core/extensions/loader.ts";
|
|
|
|
interface JitiOptionsProbe {
|
|
alias?: unknown;
|
|
tryNative?: boolean;
|
|
virtualModules?: Record<string, unknown>;
|
|
}
|
|
|
|
afterAll(() => {
|
|
if (state.originalGetBuiltinModule) {
|
|
Object.defineProperty(process, "getBuiltinModule", state.originalGetBuiltinModule);
|
|
}
|
|
});
|
|
|
|
describe("Node SEA extension loading", () => {
|
|
it("uses bundled virtual modules instead of filesystem aliases", async () => {
|
|
const result = await loadExtensions(["/extension.ts"], "/");
|
|
|
|
expect(result.errors).toEqual([]);
|
|
expect(result.extensions).toHaveLength(1);
|
|
expect(state.createJiti).toHaveBeenCalledOnce();
|
|
|
|
const options = state.createJiti.mock.calls[0][1] as JitiOptionsProbe;
|
|
// Source TypeScript also uses virtual modules, so tryNative: false is what
|
|
// proves the compiled-binary branch took precedence over the source branch.
|
|
expect(options.tryNative).toBe(false);
|
|
expect(options.alias).toBeUndefined();
|
|
expect(options.virtualModules?.typebox).toBeDefined();
|
|
expect(options.virtualModules?.["@earendil-works/pi-coding-agent"]).toBeDefined();
|
|
});
|
|
});
|