website 1.0.1: thumbnails from the site, Calendar dates
- The messages' YouTube thumbnails are served from the site (/api/thumbnails/<id>.jpg): the backend fetches a message's thumbnail once and keeps it in uploads/.thumbnails (only the site's own videos, only a JPEG), so visitors ask nothing of YouTube before pressing play. The messages page preloads the first one (its LCP: Heritage 89 -> 95). - Calendar events' dates read "Sun · November", not "Sun (month: November)". - e2e: no request to YouTube or Spotify before play; the variant screenshots round section heights to whole pixels (a one-pixel flake); the e2e thumbnail is one of the demo's illustrations. - crosscode script: a Website's export leaves out uploads/.thumbnails. - docs: release checks on 1.0.1, VERSIONS, handover. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,12 +13,13 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import express from 'express';
|
||||
import pg from 'pg';
|
||||
import sharp from 'sharp';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { websiteTemplateSchema } from '@crosscode/contracts';
|
||||
import { PrismaClient } from '../backend/src/generated/prisma/client.js';
|
||||
import { createApp } from '../backend/src/app.js';
|
||||
import { createCtx } from '../backend/src/context.js';
|
||||
import { loadDemo } from '../backend/src/demo/demoChurch.js';
|
||||
import { illustration, loadDemo } from '../backend/src/demo/demoChurch.js';
|
||||
import { loadConfig } from '../backend/src/lib/config.js';
|
||||
import { hashToken } from '../backend/src/lib/crypto.js';
|
||||
import { publish } from '../backend/src/site/snapshot.js';
|
||||
@@ -55,7 +56,13 @@ async function freshPostgres(url: string) {
|
||||
// A frozen clock (a Monday morning), so the demo's dates, and so the screenshots, are the same every
|
||||
// run (variants.spec.ts). E2E_NOW changes it.
|
||||
const frozen = new Date(process.env.E2E_NOW ?? '2026-11-23T06:00:00Z');
|
||||
const ctx = createCtx(loadConfig({ WEBSITE_URL: 'http://localhost:3310', NODE_ENV: 'test', JOBS_ENABLED: 'false', HUB_URL: 'http://127.0.0.1:1', UPLOAD_DIR: uploads, TRUST_PROXY: 'true' }), db as never, { now: () => new Date(frozen) });
|
||||
// YouTube's thumbnails (site/thumbnails.ts) without the network: one of the demo's illustrations,
|
||||
// as a JPEG the size of YouTube's, for every video.
|
||||
const thumb = await sharp(Buffer.from(illustration(4, 480, 360))).jpeg().toBuffer();
|
||||
const fakeYoutube = async (url: string) => url.startsWith('https://i.ytimg.com/')
|
||||
? new Response(new Uint8Array(thumb), { headers: { 'content-type': 'image/jpeg' } })
|
||||
: new Response('not here', { status: 404 });
|
||||
const ctx = createCtx(loadConfig({ WEBSITE_URL: 'http://localhost:3310', NODE_ENV: 'test', JOBS_ENABLED: 'false', HUB_URL: 'http://127.0.0.1:1', UPLOAD_DIR: uploads, TRUST_PROXY: 'true' }), db as never, { now: () => new Date(frozen), fetch: fakeYoutube });
|
||||
await loadDemo(ctx, websiteTemplateSchema.parse(process.env.DEMO_TEMPLATE ?? 'heritage'), { uploadDir: uploads });
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -64,6 +64,19 @@ test("the home page has the church's JSON-LD; unknown pages are a real 404", asy
|
||||
expect((await page.goto("/no-such-page"))?.status()).toBe(404);
|
||||
});
|
||||
|
||||
test("the messages ask nothing of YouTube until play is clicked; their thumbnails come from the site", async ({ page }) => {
|
||||
await useTemplate(page, "heritage");
|
||||
const outside: string[] = [];
|
||||
page.on("request", (r) => { if (/youtube|ytimg|spotify/.test(new URL(r.url()).hostname)) outside.push(r.url()); });
|
||||
await page.goto("/messages");
|
||||
const thumb = page.locator("main img").first();
|
||||
await expect(thumb).toHaveAttribute("src", /^\/api\/thumbnails\/[\w-]+\.jpg$/);
|
||||
await expect.poll(() => thumb.evaluate((i: HTMLImageElement) => i.naturalWidth)).toBeGreaterThan(0);
|
||||
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
|
||||
await page.waitForLoadState("networkidle");
|
||||
expect(outside).toEqual([]);
|
||||
});
|
||||
|
||||
test("robots.txt keeps the admin out; the sitemap lists the pages", async ({ page }) => {
|
||||
const robots = await (await page.request.get("/robots.txt")).text();
|
||||
expect(robots).toContain("Disallow: /admin");
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* (`npx playwright test variants --update-snapshots`, then look through them), and the next
|
||||
* release's run shows every section that changed. The e2e server freezes the clock (E2E_NOW), so
|
||||
* the demo's dates never change between runs. What comes from outside is masked: the video, the
|
||||
* map (OpenStreetMap) and YouTube's thumbnails.
|
||||
* map (OpenStreetMap) and the messages' thumbnails.
|
||||
*/
|
||||
import AxeBuilder from "@axe-core/playwright";
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
@@ -43,6 +43,23 @@ async function loadImages(page: Page) {
|
||||
expect(broken, "images that didn't load").toEqual([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A section's screenshot is as big as its box, rounded where it starts and ends on the page. With
|
||||
* fractional heights above it (text, aspect ratios), the same section came out a pixel taller or
|
||||
* shorter from run to run, which fails `toHaveScreenshot` however small the difference. So the
|
||||
* header and every section get their own height rounded up first: each section then starts on a
|
||||
* whole pixel and is the same size every run.
|
||||
*/
|
||||
async function wholePixels(page: Page) {
|
||||
await page.evaluate(() => {
|
||||
// The header and the sections, not what holds them (main grows to fit).
|
||||
const blocks = Array.from(document.querySelectorAll<HTMLElement>("header:not(main header), main > section"));
|
||||
for (const b of blocks) b.style.height = "";
|
||||
const heights = blocks.map((b) => b.getBoundingClientRect().height);
|
||||
blocks.forEach((b, n) => { if (getComputedStyle(b).position !== "fixed") b.style.height = `${Math.ceil(heights[n]!)}px`; });
|
||||
});
|
||||
}
|
||||
|
||||
for (const template of TEMPLATES) {
|
||||
test.describe(`${template} variants`, () => {
|
||||
test.beforeAll(async ({ request }) => {
|
||||
@@ -67,8 +84,9 @@ for (const template of TEMPLATES) {
|
||||
for (const [name, size] of WIDTHS) {
|
||||
await page.setViewportSize(size);
|
||||
await loadImages(page);
|
||||
await wholePixels(page);
|
||||
await expect(section).toHaveScreenshot(`${template}-${type}-${variant}-${name}.png`, {
|
||||
mask: [page.locator("main video"), page.locator("main [data-map]"), page.locator('main img[src*="ytimg.com"]')],
|
||||
mask: [page.locator("main video"), page.locator("main [data-map]"), page.locator('main img[src*="/api/thumbnails/"]')],
|
||||
animations: "disabled",
|
||||
maxDiffPixelRatio: 0.01,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user