diff --git a/src/plugins/contracts/plugin-sdk-root-alias.test.ts b/src/plugins/contracts/plugin-sdk-root-alias.test.ts index 3e9647a9fb7..d3e060c3d87 100644 --- a/src/plugins/contracts/plugin-sdk-root-alias.test.ts +++ b/src/plugins/contracts/plugin-sdk-root-alias.test.ts @@ -133,6 +133,26 @@ function createDistAliasPath() { 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) { + expect( + typeof (lazyModule.moduleExports.onDiagnosticEvent as (listener: () => void) => () => void)( + () => undefined, + ), + ).toBe("function"); +} + describe("plugin-sdk root alias", () => { it("exposes the fast empty config schema helper", () => { 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", () => { const packageRoot = createPackageRoot(); - const distAliasPath = createDistAliasPath(); - const lazyModule = loadRootAliasWithStubs({ - aliasPath: distAliasPath, - distExists: false, - distEntries: ["diagnostic-events-W3Hz61fI.js"], - monolithicExports: { - r: (): (() => void) => () => undefined, - slowHelper: (): string => "loaded", - }, - }); + const lazyModule = loadDiagnosticEventsAlias(["diagnostic-events-W3Hz61fI.js"]); - expect( - typeof (lazyModule.moduleExports.onDiagnosticEvent as (listener: () => void) => () => void)( - () => undefined, - ), - ).toBe("function"); + expectDiagnosticEventAccessor(lazyModule); expect(lazyModule.loadedSpecifiers).toContain( 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", () => { const packageRoot = createPackageRoot(); - const distAliasPath = createDistAliasPath(); - const lazyModule = loadRootAliasWithStubs({ - aliasPath: distAliasPath, - distExists: false, - distEntries: ["diagnostic-events-zeta.js", "diagnostic-events-alpha.js"], - monolithicExports: { - r: (): (() => void) => () => undefined, - slowHelper: (): string => "loaded", - }, - }); + const lazyModule = loadDiagnosticEventsAlias([ + "diagnostic-events-zeta.js", + "diagnostic-events-alpha.js", + ]); - expect( - typeof (lazyModule.moduleExports.onDiagnosticEvent as (listener: () => void) => () => void)( - () => undefined, - ), - ).toBe("function"); + expectDiagnosticEventAccessor(lazyModule); expect(lazyModule.loadedSpecifiers).toContain( path.join(packageRoot, "dist", "diagnostic-events-alpha.js"), );