~james/core

core/web/src/lib/images.test.ts -rw-r--r-- 620 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { describe, expect, it } from "vitest";
import { ImageError, MAX_IMAGE_BYTES, prepareImage } from "#lib/images.ts";

const file = (type: string, bytes: number, name = "seal") =>
	new File([new Uint8Array(bytes)], name, { type });

describe("prepareImage", () => {
	it("keeps a supported image under the limit untouched", async () => {
		const png = file("image/png", 10);
		expect(await prepareImage(png)).toBe(png);
	});

	it("refuses a gif over the limit rather than flattening it", async () => {
		await expect(prepareImage(file("image/gif", MAX_IMAGE_BYTES + 1))).rejects.toThrow(
			ImageError
		);
	});
});