mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-21 11:04:48 +00:00
20 lines
610 B
TypeScript
20 lines
610 B
TypeScript
import * as fs from "node:fs/promises";
|
|
import { vi } from "vitest";
|
|
import { withFetchPreconnect } from "./fetch-mock.js";
|
|
|
|
export function stubFetchResponse(response: Response) {
|
|
vi.stubGlobal("fetch", withFetchPreconnect(vi.fn(async () => response)));
|
|
}
|
|
|
|
export function stubFetchTextResponse(text: string, init?: ResponseInit) {
|
|
stubFetchResponse(new Response(text, { status: 200, ...init }));
|
|
}
|
|
|
|
export async function readFileUtf8AndCleanup(filePath: string): Promise<string> {
|
|
try {
|
|
return await fs.readFile(filePath, "utf8");
|
|
} finally {
|
|
await fs.unlink(filePath).catch(() => {});
|
|
}
|
|
}
|