mirror of https://github.com/openclaw/openclaw.git
test: trim more extension importOriginal usage
This commit is contained in:
parent
d8458a1481
commit
8e8f8d0745
|
|
@ -3,8 +3,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||
|
||||
const loadConfigMock = vi.hoisted(() => 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: () => loadConfigMock(),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||
const ensureConfiguredBindingRouteReadyMock = vi.hoisted(() => vi.fn());
|
||||
const resolveConfiguredBindingRouteMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("../../../../src/channels/plugins/binding-routing.js", async (importOriginal) => {
|
||||
vi.mock("../../../../src/channels/plugins/binding-routing.js", async () => {
|
||||
const { createConfiguredBindingConversationRuntimeModuleMock } =
|
||||
await import("../test-support/configured-binding-runtime.js");
|
||||
return await createConfiguredBindingConversationRuntimeModuleMock(
|
||||
|
|
@ -12,7 +12,10 @@ vi.mock("../../../../src/channels/plugins/binding-routing.js", async (importOrig
|
|||
ensureConfiguredBindingRouteReadyMock,
|
||||
resolveConfiguredBindingRouteMock,
|
||||
},
|
||||
importOriginal,
|
||||
() =>
|
||||
vi.importActual<typeof import("../../../../src/channels/plugins/binding-routing.js")>(
|
||||
"../../../../src/channels/plugins/binding-routing.js",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ const hoisted = vi.hoisted(() => {
|
|||
};
|
||||
});
|
||||
|
||||
vi.mock("../send.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../send.js")>();
|
||||
vi.mock("../send.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../send.js")>("../send.js");
|
||||
return {
|
||||
...actual,
|
||||
addRoleDiscord: vi.fn(),
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ const hoisted = vi.hoisted(() => {
|
|||
return { updateSessionStore, resolveStorePath };
|
||||
});
|
||||
|
||||
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,
|
||||
updateSessionStore: hoisted.updateSessionStore,
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ const { createEmbeddingProviderMock } = vi.hoisted(() => ({
|
|||
createEmbeddingProviderMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./embeddings.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./embeddings.js")>();
|
||||
vi.mock("./embeddings.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./embeddings.js")>("./embeddings.js");
|
||||
return {
|
||||
...actual,
|
||||
createEmbeddingProvider: createEmbeddingProviderMock,
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ vi.mock("openclaw/plugin-sdk/memory-core-host-engine-foundation", async () => {
|
|||
};
|
||||
});
|
||||
|
||||
vi.mock("node:child_process", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("node:child_process")>();
|
||||
vi.mock("node:child_process", async () => {
|
||||
const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
|
||||
return {
|
||||
...actual,
|
||||
spawn: vi.fn(),
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ let registerSlackPinEvents: typeof import("./pins.js").registerSlackPinEvents;
|
|||
let buildPinHarness: typeof import("./system-event-test-harness.js").createSlackSystemEventTestHarness;
|
||||
type PinOverrides = 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: pinEnqueueMock };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ let createSlackSystemEventTestHarness: typeof import("./system-event-test-harnes
|
|||
type SlackSystemEventTestOverrides =
|
||||
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: (...args: unknown[]) => reactionQueueMock(...args),
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ const resolveThreadTsMock = vi.fn(async ({ message }: { message: Record<string,
|
|||
}));
|
||||
let createSlackMessageHandler: typeof import("./message-handler.js").createSlackMessageHandler;
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/channel-inbound", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/channel-inbound")>();
|
||||
vi.mock("openclaw/plugin-sdk/channel-inbound", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/channel-inbound")>(
|
||||
"openclaw/plugin-sdk/channel-inbound",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
createChannelInboundDebouncer: () => ({
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ vi.mock("../../../src/infra/net/fetch-guard.js", () => ({
|
|||
}),
|
||||
}));
|
||||
|
||||
vi.mock("./runtime-api.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./runtime-api.js")>();
|
||||
vi.mock("./runtime-api.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./runtime-api.js")>("./runtime-api.js");
|
||||
const mockedLoadOutboundMediaFromUrl =
|
||||
loadOutboundMediaFromUrlMock as unknown as typeof actual.loadOutboundMediaFromUrl;
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,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,
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ const { defaultRouteConfig } = vi.hoisted(() => ({
|
|||
},
|
||||
}));
|
||||
|
||||
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: vi.fn(() => defaultRouteConfig),
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ let buildMentionConfig: typeof import("./auto-reply/mentions.js").buildMentionCo
|
|||
let createEchoTracker: typeof import("./auto-reply/monitor/echo.js").createEchoTracker;
|
||||
let createWebOnMessageHandler: typeof import("./auto-reply/monitor/on-message.js").createWebOnMessageHandler;
|
||||
|
||||
vi.mock("./auto-reply/monitor/last-route.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./auto-reply/monitor/last-route.js")>();
|
||||
vi.mock("./auto-reply/monitor/last-route.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./auto-reply/monitor/last-route.js")>(
|
||||
"./auto-reply/monitor/last-route.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
updateLastRouteInBackground: (...args: unknown[]) => updateLastRouteInBackgroundMock(...args),
|
||||
|
|
|
|||
|
|
@ -63,8 +63,9 @@ vi.mock("openclaw/plugin-sdk/media-runtime", async () => {
|
|||
const HOME = path.join(os.tmpdir(), `openclaw-inbound-media-${crypto.randomUUID()}`);
|
||||
process.env.HOME = HOME;
|
||||
|
||||
vi.mock("@whiskeysockets/baileys", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@whiskeysockets/baileys")>();
|
||||
vi.mock("@whiskeysockets/baileys", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("@whiskeysockets/baileys")>("@whiskeysockets/baileys");
|
||||
const jpegBuffer = Buffer.from([
|
||||
0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02,
|
||||
0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05,
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ const { normalizeMessageContent, downloadMediaMessage } = vi.hoisted(() => ({
|
|||
downloadMediaMessage: vi.fn().mockResolvedValue(Buffer.from("fake-media-data")),
|
||||
}));
|
||||
|
||||
vi.mock("@whiskeysockets/baileys", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@whiskeysockets/baileys")>();
|
||||
vi.mock("@whiskeysockets/baileys", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("@whiskeysockets/baileys")>("@whiskeysockets/baileys");
|
||||
return {
|
||||
...actual,
|
||||
DisconnectReason: actual.DisconnectReason ?? { loggedOut: 401 },
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||
const recordChannelActivity = vi.hoisted(() => vi.fn());
|
||||
let createWebSendApi: typeof import("./send-api.js").createWebSendApi;
|
||||
|
||||
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,
|
||||
recordChannelActivity: (...args: unknown[]) => recordChannelActivity(...args),
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ import {
|
|||
let monitorWebInbox: typeof import("./inbound.js").monitorWebInbox;
|
||||
const inboundLoggerInfoMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/text-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/text-runtime")>();
|
||||
vi.mock("openclaw/plugin-sdk/text-runtime", async () => {
|
||||
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/text-runtime")>(
|
||||
"openclaw/plugin-sdk/text-runtime",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
getChildLogger: () => ({
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ let setActiveWebListener: typeof import("./active-listener.js").setActiveWebList
|
|||
let resetLogger: typeof import("openclaw/plugin-sdk/runtime-env").resetLogger;
|
||||
let setLoggerOverride: typeof import("openclaw/plugin-sdk/runtime-env").setLoggerOverride;
|
||||
|
||||
vi.mock("./runtime-api.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./runtime-api.js")>();
|
||||
vi.mock("./runtime-api.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./runtime-api.js")>("./runtime-api.js");
|
||||
return {
|
||||
...actual,
|
||||
loadOutboundMediaFromUrl: hoisted.loadOutboundMediaFromUrl,
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ const deleteWebhookMock = vi.fn(async () => ({ ok: true, result: { url: "" } }))
|
|||
const getUpdatesMock = vi.fn(() => new Promise(() => {}));
|
||||
const setWebhookMock = vi.fn(async () => ({ ok: true, result: { url: "" } }));
|
||||
|
||||
vi.mock("./api.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./api.js")>();
|
||||
vi.mock("./api.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./api.js")>("./api.js");
|
||||
return {
|
||||
...actual,
|
||||
deleteWebhook: deleteWebhookMock,
|
||||
|
|
|
|||
Loading…
Reference in New Issue