mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:08:25 +00:00
test: dedupe and optimize test suites
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const fetchWithSsrFGuardMock = vi.fn();
|
||||
|
||||
@@ -10,6 +10,15 @@ async function waitForMicrotaskTurn(): Promise<void> {
|
||||
await new Promise<void>((resolve) => queueMicrotask(resolve));
|
||||
}
|
||||
|
||||
let fetchWithGuard: typeof import("./input-files.js").fetchWithGuard;
|
||||
let extractImageContentFromSource: typeof import("./input-files.js").extractImageContentFromSource;
|
||||
let extractFileContentFromSource: typeof import("./input-files.js").extractFileContentFromSource;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ fetchWithGuard, extractImageContentFromSource, extractFileContentFromSource } =
|
||||
await import("./input-files.js"));
|
||||
});
|
||||
|
||||
describe("fetchWithGuard", () => {
|
||||
it("rejects oversized streamed payloads and cancels the stream", async () => {
|
||||
let canceled = false;
|
||||
@@ -40,7 +49,6 @@ describe("fetchWithGuard", () => {
|
||||
finalUrl: "https://example.com/file.bin",
|
||||
});
|
||||
|
||||
const { fetchWithGuard } = await import("./input-files.js");
|
||||
await expect(
|
||||
fetchWithGuard({
|
||||
url: "https://example.com/file.bin",
|
||||
@@ -64,7 +72,6 @@ describe("base64 size guards", () => {
|
||||
kind: "images",
|
||||
expectedError: "Image too large",
|
||||
run: async (data: string) => {
|
||||
const { extractImageContentFromSource } = await import("./input-files.js");
|
||||
return await extractImageContentFromSource(
|
||||
{ type: "base64", data, mediaType: "image/png" },
|
||||
{
|
||||
@@ -81,7 +88,6 @@ describe("base64 size guards", () => {
|
||||
kind: "files",
|
||||
expectedError: "File too large",
|
||||
run: async (data: string) => {
|
||||
const { extractFileContentFromSource } = await import("./input-files.js");
|
||||
return await extractFileContentFromSource({
|
||||
source: { type: "base64", data, mediaType: "text/plain", filename: "x.txt" },
|
||||
limits: {
|
||||
|
||||
Reference in New Issue
Block a user