mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:40:43 +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");
|
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"),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user