test: dedupe and optimize test suites

This commit is contained in:
Peter Steinberger
2026-02-19 15:18:50 +00:00
parent b0e55283d5
commit a1cb700a05
80 changed files with 2627 additions and 2962 deletions

View File

@@ -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: {