1import { MAX_BLOB_BYTES, MAX_UNIQUE_BLOBS } from "@nzip/shared";2import { buildBundle } from "./bundle.ts";34Deno.test("bundle rejects an oversized file before reading it", async () => {5 const dir = await Deno.makeTempDir();6 const path = `${dir}/oversized.bin`;7 try {8 await Deno.writeFile(path, new Uint8Array());9 await Deno.truncate(path, MAX_BLOB_BYTES + 1);10 try {11 await buildBundle(path);12 throw new Error("expected oversized bundle to be rejected");13 } catch (error) {14 if (15 !(error instanceof Error) ||16 !error.message.includes("file too large (max 50 MiB)")17 ) {18 throw error;19 }20 }21 } finally {22 await Deno.remove(dir, { recursive: true });23 }24});2526Deno.test("bundle rejects the first unique blob above the Worker ceiling", async () => {27 const dir = await Deno.makeTempDir();28 try {29 await Promise.all(30 Array.from(31 { length: MAX_UNIQUE_BLOBS + 1 },32 (_, i) => Deno.writeTextFile(`${dir}/file-${i}.txt`, `unique-${i}`),33 ),34 );35 try {36 await buildBundle(dir);37 throw new Error("expected excessive unique blobs to be rejected");38 } catch (error) {39 if (40 !(error instanceof Error) ||41 !error.message.includes(42 `too many unique blobs (max ${MAX_UNIQUE_BLOBS})`,43 )44 ) {45 throw error;46 }47 }48 } finally {49 await Deno.remove(dir, { recursive: true });50 }51});