mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:50:44 +00:00
test: share plugin root alias diagnostics harness
This commit is contained in:
@@ -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<typeof loadRootAliasWithStubs>) {
|
||||
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"),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user