mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
fix(test): avoid vitest mock type inference issues
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
export const callGatewayMock = vi.fn();
|
||||
// Avoid exporting inferred vitest mock types (TS2742 under pnpm + d.ts emit).
|
||||
export type CallGatewayMock = ((opts: unknown) => unknown) & ReturnType<typeof vi.fn>;
|
||||
export const callGatewayMock: CallGatewayMock = vi.fn() as unknown as CallGatewayMock;
|
||||
vi.mock("../gateway/call.js", () => ({
|
||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||
}));
|
||||
|
||||
@@ -5,6 +5,14 @@ import { callGateway, installBaseProgramMocks, runTui, runtime } from "./program
|
||||
|
||||
installBaseProgramMocks();
|
||||
|
||||
function getFirstRuntimeLogLine(): string {
|
||||
const first = runtime.log.mock.calls[0]?.[0];
|
||||
if (typeof first !== "string") {
|
||||
throw new Error(`Expected runtime.log first arg to be string, got ${typeof first}`);
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
const IOS_NODE = {
|
||||
nodeId: "ios-node",
|
||||
displayName: "iOS Node",
|
||||
@@ -59,7 +67,7 @@ describe("cli program (nodes media)", () => {
|
||||
.toSorted((a, b) => a.localeCompare(b));
|
||||
expect(facings).toEqual(["back", "front"]);
|
||||
|
||||
const out = String(runtime.log.mock.calls[0]?.[0] ?? "");
|
||||
const out = getFirstRuntimeLogLine();
|
||||
const mediaPaths = out
|
||||
.split("\n")
|
||||
.filter((l) => l.startsWith("MEDIA:"))
|
||||
@@ -132,7 +140,7 @@ describe("cli program (nodes media)", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const out = String(runtime.log.mock.calls[0]?.[0] ?? "");
|
||||
const out = getFirstRuntimeLogLine();
|
||||
const mediaPath = out.replace(/^MEDIA:/, "").trim();
|
||||
expect(mediaPath).toMatch(/openclaw-camera-clip-front-.*\.mp4$/);
|
||||
|
||||
@@ -188,7 +196,7 @@ describe("cli program (nodes media)", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const out = String(runtime.log.mock.calls[0]?.[0] ?? "");
|
||||
const out = getFirstRuntimeLogLine();
|
||||
const mediaPath = out.replace(/^MEDIA:/, "").trim();
|
||||
|
||||
try {
|
||||
@@ -263,7 +271,7 @@ describe("cli program (nodes media)", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const out = String(runtime.log.mock.calls[0]?.[0] ?? "");
|
||||
const out = getFirstRuntimeLogLine();
|
||||
const mediaPath = out.replace(/^MEDIA:/, "").trim();
|
||||
|
||||
try {
|
||||
@@ -356,7 +364,7 @@ describe("cli program (nodes media)", () => {
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const out = String(runtime.log.mock.calls[0]?.[0] ?? "");
|
||||
const out = getFirstRuntimeLogLine();
|
||||
const mediaPath = out.replace(/^MEDIA:/, "").trim();
|
||||
expect(mediaPath).toMatch(/openclaw-canvas-snapshot-.*\.png$/);
|
||||
|
||||
@@ -455,7 +463,7 @@ describe("cli program (nodes media)", () => {
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const out = String(runtime.log.mock.calls[0]?.[0] ?? "");
|
||||
const out = getFirstRuntimeLogLine();
|
||||
const mediaPath = out.replace(/^MEDIA:/, "").trim();
|
||||
expect(mediaPath).toMatch(/openclaw-camera-snap-front-.*\.jpg$/);
|
||||
|
||||
@@ -504,7 +512,7 @@ describe("cli program (nodes media)", () => {
|
||||
{ from: "user" },
|
||||
);
|
||||
|
||||
const out = String(runtime.log.mock.calls[0]?.[0] ?? "");
|
||||
const out = getFirstRuntimeLogLine();
|
||||
const mediaPath = out.replace(/^MEDIA:/, "").trim();
|
||||
expect(mediaPath).toMatch(/openclaw-camera-clip-front-.*\.mp4$/);
|
||||
|
||||
|
||||
@@ -3,7 +3,15 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, vi } from "vitest";
|
||||
|
||||
export function createNoopLogger() {
|
||||
// Avoid exporting inferred vitest mock types (TS2742 under pnpm + d.ts emit).
|
||||
export type NoopLogger = {
|
||||
debug: ReturnType<typeof vi.fn>;
|
||||
info: ReturnType<typeof vi.fn>;
|
||||
warn: ReturnType<typeof vi.fn>;
|
||||
error: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
export function createNoopLogger(): NoopLogger {
|
||||
return {
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
|
||||
Reference in New Issue
Block a user