mirror of https://github.com/openclaw/openclaw.git
perf(matrix): isolate probe runtime deps
This commit is contained in:
parent
fac89d403b
commit
045d590542
|
|
@ -0,0 +1,4 @@
|
|||
import { createMatrixClient } from "./client.js";
|
||||
|
||||
// Keep probe's runtime seam narrow so tests can mock it without loading the full client barrel.
|
||||
export { createMatrixClient };
|
||||
|
|
@ -3,8 +3,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||
const createMatrixClientMock = vi.fn();
|
||||
const isBunRuntimeMock = vi.fn(() => false);
|
||||
|
||||
vi.mock("./client.js", () => ({
|
||||
vi.mock("./probe.runtime.js", () => ({
|
||||
createMatrixClient: (...args: unknown[]) => createMatrixClientMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock("./client/runtime.js", () => ({
|
||||
isBunRuntime: () => isBunRuntimeMock(),
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ import type { SsrFPolicy } from "../runtime-api.js";
|
|||
import type { BaseProbeResult } from "../runtime-api.js";
|
||||
import { isBunRuntime } from "./client/runtime.js";
|
||||
|
||||
type MatrixProbeRuntimeDeps = Pick<typeof import("./client.js"), "createMatrixClient">;
|
||||
type MatrixProbeRuntimeDeps = Pick<typeof import("./probe.runtime.js"), "createMatrixClient">;
|
||||
|
||||
let matrixProbeRuntimeDepsPromise: Promise<MatrixProbeRuntimeDeps> | undefined;
|
||||
|
||||
async function loadMatrixProbeRuntimeDeps(): Promise<MatrixProbeRuntimeDeps> {
|
||||
matrixProbeRuntimeDepsPromise ??= import("./client.js").then((clientModule) => ({
|
||||
createMatrixClient: clientModule.createMatrixClient,
|
||||
matrixProbeRuntimeDepsPromise ??= import("./probe.runtime.js").then((runtimeModule) => ({
|
||||
createMatrixClient: runtimeModule.createMatrixClient,
|
||||
}));
|
||||
return await matrixProbeRuntimeDepsPromise;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue