Files
emdash-cms--emdash/e2e/tests/image-optimization.spec.ts
wehub-resource-sync b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:23:53 +08:00

40 lines
1.5 KiB
TypeScript

/**
* Image optimization E2E.
*
* The seed creates a published "Post With Image" whose Portable Text body has an
* image block (rendered by EmDashImage at /posts/post-with-image). This asserts
* the image flows through Astro's image pipeline (a `/_image` src) and that the
* wrapped endpoint serves real image bytes from storage -- not a redirect or
* 404. On the Cloudflare target this exercises the storage-backed endpoint that
* makes optimization work without an HTTP fetch of the media URL.
*/
import { test, expect } from "../fixtures";
test.describe("image optimization", () => {
test("renders an optimized image served by the wrapped image endpoint", async ({
page,
request,
}) => {
const img = page.locator("figure.emdash-image img").first();
// The workerd dev runner's Vite dep optimizer can transiently 500 a cold
// route even after warm-up; reload until the page renders. (Dev-only; the
// deployed Worker has no optimizer.)
for (let attempt = 0; attempt < 5; attempt++) {
await page.goto("/posts/post-with-image");
if (await img.isVisible().catch(() => false)) break;
await page.waitForTimeout(1000);
}
await expect(img).toBeVisible();
const src = await img.getAttribute("src");
expect(src, "image src should be optimized via Astro's image endpoint").toContain("/_image");
// The optimized URL must return real image bytes, not an Access redirect or 404.
const res = await request.get(src!);
expect(res.status()).toBe(200);
expect(res.headers()["content-type"]).toMatch(/^image\//);
});
});