test: share plugin root alias diagnostics harness

This commit is contained in:
Peter Steinberger
2026-04-19 00:25:12 +01:00
parent 158ebbb2ed
commit e88a9e5ee4

View File

@@ -133,6 +133,26 @@ function createDistAliasPath() {
return path.join(createPackageRoot(), "dist", "plugin-sdk", "root-alias.cjs"); return path.join(createPackageRoot(), "dist", "plugin-sdk", "root-alias.cjs");
} }
function loadDiagnosticEventsAlias(distEntries: string[]) {
return loadRootAliasWithStubs({
aliasPath: createDistAliasPath(),
distExists: false,
distEntries,
monolithicExports: {
r: (): (() => void) => () => undefined,
slowHelper: (): string => "loaded",
},
});
}
function expectDiagnosticEventAccessor(lazyModule: ReturnType<typeof loadRootAliasWithStubs>) {
expect(
typeof (lazyModule.moduleExports.onDiagnosticEvent as (listener: () => void) => () => void)(
() => undefined,
),
).toBe("function");
}
describe("plugin-sdk root alias", () => { describe("plugin-sdk root alias", () => {
it("exposes the fast empty config schema helper", () => { it("exposes the fast empty config schema helper", () => {
const factory = rootSdk.emptyPluginConfigSchema as (() => EmptySchema) | undefined; const factory = rootSdk.emptyPluginConfigSchema as (() => EmptySchema) | undefined;
@@ -372,22 +392,9 @@ describe("plugin-sdk root alias", () => {
it("prefers hashed dist diagnostic events chunks before falling back to src", () => { it("prefers hashed dist diagnostic events chunks before falling back to src", () => {
const packageRoot = createPackageRoot(); const packageRoot = createPackageRoot();
const distAliasPath = createDistAliasPath(); const lazyModule = loadDiagnosticEventsAlias(["diagnostic-events-W3Hz61fI.js"]);
const lazyModule = loadRootAliasWithStubs({
aliasPath: distAliasPath,
distExists: false,
distEntries: ["diagnostic-events-W3Hz61fI.js"],
monolithicExports: {
r: (): (() => void) => () => undefined,
slowHelper: (): string => "loaded",
},
});
expect( expectDiagnosticEventAccessor(lazyModule);
typeof (lazyModule.moduleExports.onDiagnosticEvent as (listener: () => void) => () => void)(
() => undefined,
),
).toBe("function");
expect(lazyModule.loadedSpecifiers).toContain( expect(lazyModule.loadedSpecifiers).toContain(
path.join(packageRoot, "dist", "diagnostic-events-W3Hz61fI.js"), path.join(packageRoot, "dist", "diagnostic-events-W3Hz61fI.js"),
); );
@@ -398,22 +405,12 @@ describe("plugin-sdk root alias", () => {
it("chooses hashed dist diagnostic events chunks deterministically", () => { it("chooses hashed dist diagnostic events chunks deterministically", () => {
const packageRoot = createPackageRoot(); const packageRoot = createPackageRoot();
const distAliasPath = createDistAliasPath(); const lazyModule = loadDiagnosticEventsAlias([
const lazyModule = loadRootAliasWithStubs({ "diagnostic-events-zeta.js",
aliasPath: distAliasPath, "diagnostic-events-alpha.js",
distExists: false, ]);
distEntries: ["diagnostic-events-zeta.js", "diagnostic-events-alpha.js"],
monolithicExports: {
r: (): (() => void) => () => undefined,
slowHelper: (): string => "loaded",
},
});
expect( expectDiagnosticEventAccessor(lazyModule);
typeof (lazyModule.moduleExports.onDiagnosticEvent as (listener: () => void) => () => void)(
() => undefined,
),
).toBe("function");
expect(lazyModule.loadedSpecifiers).toContain( expect(lazyModule.loadedSpecifiers).toContain(
path.join(packageRoot, "dist", "diagnostic-events-alpha.js"), path.join(packageRoot, "dist", "diagnostic-events-alpha.js"),
); );