mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 01:13:29 +00:00
test: annotate harness mocks to avoid TS2742 in CI
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import type { Mock } from "vitest";
|
||||||
import { afterEach, beforeEach, vi } from "vitest";
|
import { afterEach, beforeEach, vi } from "vitest";
|
||||||
|
|
||||||
export function resolveBlueBubblesAccountFromConfig(params: {
|
export function resolveBlueBubblesAccountFromConfig(params: {
|
||||||
@@ -19,7 +20,11 @@ export function createBlueBubblesAccountsMockModule() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createBlueBubblesProbeMockModule() {
|
type BlueBubblesProbeMockModule = {
|
||||||
|
getCachedBlueBubblesPrivateApiStatus: Mock<() => boolean | null>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createBlueBubblesProbeMockModule(): BlueBubblesProbeMockModule {
|
||||||
return {
|
return {
|
||||||
getCachedBlueBubblesPrivateApiStatus: vi.fn().mockReturnValue(null),
|
getCachedBlueBubblesPrivateApiStatus: vi.fn().mockReturnValue(null),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { afterEach, beforeEach, vi } from "vitest";
|
import { afterEach, beforeEach, vi } from "vitest";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
|
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
|
||||||
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
|
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
|
||||||
|
|
||||||
export async function withModelsTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
|
export async function withModelsTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
|
||||||
@@ -57,7 +58,7 @@ export async function withUnsetCopilotTokenEnv<T>(fn: () => Promise<T>): Promise
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockCopilotTokenExchangeSuccess() {
|
export function mockCopilotTokenExchangeSuccess(): MockFn {
|
||||||
const fetchMock = vi.fn().mockResolvedValue({
|
const fetchMock = vi.fn().mockResolvedValue({
|
||||||
ok: true,
|
ok: true,
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
|
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
|
||||||
|
|
||||||
export type LoadedConfig = ReturnType<(typeof import("../config/config.js"))["loadConfig"]>;
|
export type LoadedConfig = ReturnType<(typeof import("../config/config.js"))["loadConfig"]>;
|
||||||
|
|
||||||
export const callGatewayMock = vi.fn();
|
export const callGatewayMock: MockFn = vi.fn();
|
||||||
|
|
||||||
const defaultConfig: LoadedConfig = {
|
const defaultConfig: LoadedConfig = {
|
||||||
session: {
|
session: {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
|
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
|
||||||
|
|
||||||
export const baseConfigSnapshot = {
|
export const baseConfigSnapshot = {
|
||||||
path: "/tmp/openclaw.json",
|
path: "/tmp/openclaw.json",
|
||||||
@@ -11,7 +12,13 @@ export const baseConfigSnapshot = {
|
|||||||
legacyIssues: [],
|
legacyIssues: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createTestRuntime() {
|
export type TestRuntime = {
|
||||||
|
log: MockFn;
|
||||||
|
error: MockFn;
|
||||||
|
exit: MockFn;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createTestRuntime(): TestRuntime {
|
||||||
return {
|
return {
|
||||||
log: vi.fn(),
|
log: vi.fn(),
|
||||||
error: vi.fn(),
|
error: vi.fn(),
|
||||||
|
|||||||
@@ -91,7 +91,12 @@ export function createFinishedBarrier() {
|
|||||||
export function createStartedCronServiceWithFinishedBarrier(params: {
|
export function createStartedCronServiceWithFinishedBarrier(params: {
|
||||||
storePath: string;
|
storePath: string;
|
||||||
logger: ReturnType<typeof createNoopLogger>;
|
logger: ReturnType<typeof createNoopLogger>;
|
||||||
}) {
|
}): {
|
||||||
|
cron: CronService;
|
||||||
|
enqueueSystemEvent: MockFn;
|
||||||
|
requestHeartbeatNow: MockFn;
|
||||||
|
finished: ReturnType<typeof createFinishedBarrier>;
|
||||||
|
} {
|
||||||
const enqueueSystemEvent = vi.fn();
|
const enqueueSystemEvent = vi.fn();
|
||||||
const requestHeartbeatNow = vi.fn();
|
const requestHeartbeatNow = vi.fn();
|
||||||
const finished = createFinishedBarrier();
|
const finished = createFinishedBarrier();
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
|
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
|
||||||
|
|
||||||
export const sendMock = vi.fn();
|
export const sendMock: MockFn = vi.fn();
|
||||||
export const reactMock = vi.fn();
|
export const reactMock: MockFn = vi.fn();
|
||||||
export const updateLastRouteMock = vi.fn();
|
export const updateLastRouteMock: MockFn = vi.fn();
|
||||||
export const dispatchMock = vi.fn();
|
export const dispatchMock: MockFn = vi.fn();
|
||||||
export const readAllowFromStoreMock = vi.fn();
|
export const readAllowFromStoreMock: MockFn = vi.fn();
|
||||||
export const upsertPairingRequestMock = vi.fn();
|
export const upsertPairingRequestMock: MockFn = vi.fn();
|
||||||
|
|
||||||
vi.mock("./send.js", () => ({
|
vi.mock("./send.js", () => ({
|
||||||
sendMessageDiscord: (...args: unknown[]) => sendMock(...args),
|
sendMessageDiscord: (...args: unknown[]) => sendMock(...args),
|
||||||
|
|||||||
Reference in New Issue
Block a user