forked from ascorbic/unpic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e.test.ts
58 lines (53 loc) · 1.53 KB
/
e2e.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { assert, assertAlmostEquals, assertExists } from "jsr:@std/assert";
import examples from "./demo/src/examples.json" with { type: "json" };
import { getPixels } from "jsr:@unpic/pixels";
import { transformUrl } from "./src/transform.ts";
import type { ImageCdn } from "./src/types.ts";
Deno.test("E2E tests", async (t) => {
for (const [cdn, example] of Object.entries(examples)) {
const [name, url] = example;
// ImageEngine is really flaky, so ignore it, and the supabase example is
// broken
const ignore = ["imageengine", "supabase"].includes(cdn);
const ignoreAspectRatio = [
"imageengine",
"supabase",
"vercel",
"nextjs",
]
.includes(cdn);
await t.step({
name: `${name} resizes an image`,
fn: async () => {
const size = cdn === "vercel" ? 256 : 96;
const image = transformUrl({
url,
width: size,
cdn: cdn as ImageCdn,
format: "jpg",
});
assertExists(image, `Failed to resize ${name} with ${cdn}`);
const { width } = await getPixels(image);
assertAlmostEquals(width, size, 1);
},
ignore,
});
await t.step({
name: `${name} returns requested aspect ratio`,
fn: async () => {
const image = transformUrl({
url,
width: 100,
height: 50,
cdn: cdn as ImageCdn,
format: "jpg",
});
assertExists(image, `Failed to resize ${name} with ${cdn}`);
const { width, height } = await getPixels(image);
assertAlmostEquals(width, 100, 1);
assertAlmostEquals(height, 50, 1);
},
ignore: ignoreAspectRatio,
});
}
});