mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-30 19:30:21 +00:00
test: trim more extension importOriginal usage
This commit is contained in:
@@ -205,8 +205,8 @@ vi.mock("../../runtime.js", () => ({
|
||||
setMatrixRuntime: hoisted.setMatrixRuntime,
|
||||
}));
|
||||
|
||||
vi.mock("../accounts.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../accounts.js")>();
|
||||
vi.mock("../accounts.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../accounts.js")>("../accounts.js");
|
||||
return {
|
||||
...actual,
|
||||
resolveConfiguredMatrixBotUserIds: vi.fn(() => new Set<string>()),
|
||||
|
||||
@@ -176,8 +176,10 @@ function createMatrixJsClientStub(): MatrixJsClientStub {
|
||||
let matrixJsClient = createMatrixJsClientStub();
|
||||
let lastCreateClientOpts: Record<string, unknown> | null = null;
|
||||
|
||||
vi.mock("matrix-js-sdk/lib/matrix.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("matrix-js-sdk/lib/matrix.js")>();
|
||||
vi.mock("matrix-js-sdk/lib/matrix.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("matrix-js-sdk/lib/matrix.js")>(
|
||||
"matrix-js-sdk/lib/matrix.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
ClientEvent: { Event: "event", Room: "Room" },
|
||||
|
||||
@@ -15,8 +15,10 @@ const { withFileLockMock } = vi.hoisted(() => ({
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/infra-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/infra-runtime")>();
|
||||
vi.mock("openclaw/plugin-sdk/infra-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/infra-runtime")>(
|
||||
"openclaw/plugin-sdk/infra-runtime",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
withFileLock: withFileLockMock,
|
||||
|
||||
@@ -15,8 +15,8 @@ vi.mock("./runtime-api.js", () => ({
|
||||
parseStrictPositiveInteger,
|
||||
}));
|
||||
|
||||
vi.mock("./client.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./client.js")>();
|
||||
vi.mock("./client.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./client.js")>("./client.js");
|
||||
return {
|
||||
...actual,
|
||||
fetchMattermostUserTeams,
|
||||
|
||||
@@ -14,8 +14,10 @@ function getCapturedCtx() {
|
||||
return capturedCtx as SignalMsgContext;
|
||||
}
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/reply-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/reply-runtime")>();
|
||||
vi.mock("openclaw/plugin-sdk/reply-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/reply-runtime")>(
|
||||
"openclaw/plugin-sdk/reply-runtime",
|
||||
);
|
||||
return buildDispatchInboundCaptureMock(actual, (ctx) => {
|
||||
capturedCtx = ctx as SignalMsgContext;
|
||||
});
|
||||
|
||||
@@ -18,8 +18,10 @@ const internalHookMocks = vi.hoisted(() => ({
|
||||
triggerInternalHook: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/hook-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/hook-runtime")>();
|
||||
vi.mock("openclaw/plugin-sdk/hook-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/hook-runtime")>(
|
||||
"openclaw/plugin-sdk/hook-runtime",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
createInternalHookEvent: internalHookMocks.createInternalHookEvent,
|
||||
|
||||
@@ -2,8 +2,10 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const rpcMock = vi.fn();
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/config-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/config-runtime")>();
|
||||
vi.mock("openclaw/plugin-sdk/config-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-runtime")>(
|
||||
"openclaw/plugin-sdk/config-runtime",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: () => ({}),
|
||||
|
||||
@@ -11,8 +11,8 @@ const { handleSlackActionMock } = vi.hoisted(() => ({
|
||||
handleSlackActionMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./action-runtime.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./action-runtime.js")>();
|
||||
vi.mock("./action-runtime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./action-runtime.js")>("./action-runtime.js");
|
||||
return {
|
||||
...actual,
|
||||
handleSlackAction: handleSlackActionMock,
|
||||
@@ -159,10 +159,12 @@ describe("slackPlugin actions", () => {
|
||||
},
|
||||
};
|
||||
|
||||
expect(slackPlugin.actions?.describeMessageTool?.({ cfg, accountId: "default" })).toMatchObject({
|
||||
actions: ["send"],
|
||||
capabilities: ["blocks"],
|
||||
});
|
||||
expect(slackPlugin.actions?.describeMessageTool?.({ cfg, accountId: "default" })).toMatchObject(
|
||||
{
|
||||
actions: ["send"],
|
||||
capabilities: ["blocks"],
|
||||
},
|
||||
);
|
||||
expect(slackPlugin.actions?.describeMessageTool?.({ cfg, accountId: "work" })).toMatchObject({
|
||||
actions: [
|
||||
"send",
|
||||
|
||||
@@ -5,8 +5,10 @@ const readStoreAllowFromForDmPolicyMock = vi.hoisted(() => vi.fn());
|
||||
let clearSlackAllowFromCacheForTest: typeof import("./auth.js").clearSlackAllowFromCacheForTest;
|
||||
let resolveSlackEffectiveAllowFrom: typeof import("./auth.js").resolveSlackEffectiveAllowFrom;
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/security-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/security-runtime")>();
|
||||
vi.mock("openclaw/plugin-sdk/security-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/security-runtime")>(
|
||||
"openclaw/plugin-sdk/security-runtime",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
readStoreAllowFromForDmPolicy: (...args: unknown[]) =>
|
||||
|
||||
@@ -4,10 +4,10 @@ const enqueueSystemEventMock = vi.hoisted(() => vi.fn());
|
||||
let registerSlackChannelEvents: typeof import("./channels.js").registerSlackChannelEvents;
|
||||
let createSlackSystemEventTestHarness: typeof import("./system-event-test-harness.js").createSlackSystemEventTestHarness;
|
||||
|
||||
async function createChannelRuntimeMock(
|
||||
importOriginal: () => Promise<typeof import("openclaw/plugin-sdk/infra-runtime")>,
|
||||
) {
|
||||
const actual = await importOriginal();
|
||||
async function createChannelRuntimeMock() {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/infra-runtime")>(
|
||||
"openclaw/plugin-sdk/infra-runtime",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args),
|
||||
|
||||
@@ -7,10 +7,10 @@ let registerSlackMemberEvents: typeof import("./members.js").registerSlackMember
|
||||
let initSlackHarness: typeof import("./system-event-test-harness.js").createSlackSystemEventTestHarness;
|
||||
type MemberOverrides = import("./system-event-test-harness.js").SlackSystemEventTestOverrides;
|
||||
|
||||
async function createChannelRuntimeMock(
|
||||
importOriginal: () => Promise<typeof import("openclaw/plugin-sdk/infra-runtime")>,
|
||||
) {
|
||||
const actual = await importOriginal();
|
||||
async function createChannelRuntimeMock() {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/infra-runtime")>(
|
||||
"openclaw/plugin-sdk/infra-runtime",
|
||||
);
|
||||
return { ...actual, enqueueSystemEvent: memberMocks.enqueue };
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,8 @@ function createSingleSettlement<T>(params: {
|
||||
};
|
||||
}
|
||||
|
||||
vi.mock("grammy", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("grammy")>();
|
||||
vi.mock("grammy", async () => {
|
||||
const actual = await vi.importActual<typeof import("grammy")>("grammy");
|
||||
return {
|
||||
...actual,
|
||||
API_CONSTANTS: actual.API_CONSTANTS ?? {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { MAX_IMAGE_BYTES } from "openclaw/plugin-sdk/media-runtime";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/media-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/media-runtime")>();
|
||||
vi.mock("openclaw/plugin-sdk/media-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/media-runtime")>(
|
||||
"openclaw/plugin-sdk/media-runtime",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
fetchRemoteMedia: vi.fn(),
|
||||
|
||||
@@ -5,11 +5,14 @@ const { spawnMock } = vi.hoisted(() => ({
|
||||
spawnMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("node:child_process", async (importOriginal) => {
|
||||
vi.mock("node:child_process", async () => {
|
||||
const { mockNodeBuiltinModule } = await import("../../../../test/helpers/node-builtin-mocks.js");
|
||||
return mockNodeBuiltinModule(importOriginal, {
|
||||
spawn: spawnMock,
|
||||
});
|
||||
return mockNodeBuiltinModule(
|
||||
() => vi.importActual<typeof import("node:child_process")>("node:child_process"),
|
||||
{
|
||||
spawn: spawnMock,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
import {
|
||||
|
||||
@@ -52,8 +52,8 @@ vi.mock("openclaw/plugin-sdk/setup", () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./accounts.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./accounts.js")>();
|
||||
vi.mock("./accounts.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./accounts.js")>("./accounts.js");
|
||||
return {
|
||||
...actual,
|
||||
resolveWhatsAppAuthDir: hoisted.resolveWhatsAppAuthDir,
|
||||
|
||||
Reference in New Issue
Block a user