Public: anyone can read this; the crew can change it.

A weight budget test caps the JavaScript and CSS a page ships and requires sizes on every image #282

opened this

Merged 26d 12h ago, live in production

This adds src/weight.test.ts, a weight budget test for the JavaScript and CSS the app serves. It also removes one unused script link the test found. The new test file and the other test files I ran (tour, design, speed, cache, a11y, live, sheets) all pass.

Notes

opened this

This adds src/weight.test.ts, a weight budget test for the JavaScript and CSS the app serves. It also removes one unused script link the test found. The new test file and the other test files I ran (tour, design, speed, cache, a11y, live, sheets) all pass. I did not run the full suite; the forge runs it on the push.

What changed

  • Weight cap: src/weight.test.ts fetches app.css, live.js, sheets.js and print.js from /static/ as served and sums their bytes. The total is 27,529 bytes, and the cap is 30,300 (about 10% above). A comment in the test records the measurement.
  • Unused scripts: Each page the tour visits is checked, and a page fails if it links a script it has nothing for. The checked pages are /, /week, /people, /profile, and each sample deal's page, timeline and sheets. Each script has a rule for what counts as using it:
    • live.js needs a data-live region or the live-status element.
    • sheets.js needs an a[data-sheet] link.
    • print.js needs a data-print button.
  • Image sizes: The same pages are checked for any <img> or <svg> tag that has no width and height (or an inline size). No page has any image or inline SVG today, so this guards future changes. The test file also has a small check of the size rule itself; it is weak, because it only exercises the same regex logic on a made-up tag.
  • Cache header: Every /static/…?v= asset linked from / must come back with public, max-age=31536000, immutable.
  • Fix the test found: Deal pages linked sheets.js, but they show their sheets inline and have no sheet links, so the script did nothing there. layout() in src/pages/layout.ts now takes sheets?: boolean, and src/pages/deal.ts passes sheets: false. The other pages are unchanged.

What I left alone

  • The new-deal page isn't in the visited set, so its script links aren't checked.
  • I made no changes under static/, since nothing there was oversized.

Checks

  • The repository has no tsconfig.json and no scripts/gate.ts or scripts/fast.ts, so bun x tsc --noEmit just prints its help text and I ran no type check or gate.
  • I ran bun scripts/lint-design.ts; it printed nothing.
  • I did not run docs/VISION.md; the file doesn't exist in this clone.

To try it, run bun test src/weight.test.ts.

🤖 Generated with Claude Code

Closes #271

2 earlier comments
commented

This adds src/weight.test.ts, a weight budget test for the JavaScript and CSS the app serves. It also removes one unused script link the test found. The new test file and the other test files I ran (tour, design, speed, cache, a11y, live, sheets) all pass. I did not run the full suite; the forge runs it on the push.

What changed

  • Weight cap: src/weight.test.ts fetches app.css, live.js, sheets.js and print.js from /static/ as served and sums their bytes. The total is 27,529 bytes, and the cap is 30,300 (about 10% above). A comment in the test records the measurement.
  • Unused scripts: Each page the tour visits is checked, and a page fails if it links a script it has nothing for. The checked pages are /, /week, /people, /profile, and each sample deal's page, timeline and sheets. Each script has a rule for what counts as using it:
    • live.js needs a data-live region or the live-status element.
    • sheets.js needs an a[data-sheet] link.
    • print.js needs a data-print button.
  • Image sizes: The same pages are checked for any <img> or <svg> tag that has no width and height (or an inline size). No page has any image or inline SVG today, so this guards future changes. The test file also has a small check of the size rule itself; it is weak, because it only exercises the same regex logic on a made-up tag.
  • Cache header: Every /static/…?v= asset linked from / must come back with public, max-age=31536000, immutable.
  • Fix the test found: Deal pages linked sheets.js, but they show their sheets inline and have no sheet links, so the script did nothing there. layout() in src/pages/layout.ts now takes sheets?: boolean, and src/pages/deal.ts passes sheets: false. The other pages are unchanged.

What I left alone

  • The new-deal page isn't in the visited set, so its script links aren't checked.
  • I made no changes under static/, since nothing there was oversized.

Checks

  • The repository has no tsconfig.json and no scripts/gate.ts or scripts/fast.ts, so bun x tsc --noEmit just prints its help text and I ran no type check or gate.
  • I ran bun scripts/lint-design.ts; it printed nothing.
  • I did not run docs/VISION.md; the file doesn't exist in this clone.

To try it, run bun test src/weight.test.ts.

🤖 Generated with Claude Code

commented

I pushed a fix to the pull. The three failing tests were not caused by my change, but I only re-ran the tests that cover this change and the three that failed, not the full suite, so the forge's check on this push is the full confirmation.

  • The failures: sample.test.ts, anniversary.test.ts and week.appointment.test.ts failed because my branch was behind main. They failed on the branch before the merge and passed on a clean copy of main.
  • What fixed them: main already had the fix (#280, which changed src/sample.ts), so I merged main into the branch.
  • New script on main: That merge added static/review.js, which the weight test didn't know about. It now:
    • counts review.js in the byte total, which is now 28,196, and raises the cap to 31,000 (the earlier 30,300 cap would no longer have held);
    • checks that the /review page actually uses review.js (it needs a data-keys element);
    • adds /review to the pages whose script links are checked.

The weight test, those three tests and review.test.ts pass locally.

commented

I addressed both points from the review on the same branch and pushed. src/weight.test.ts now passes with four tests. I ran only that file, not the full suite.

  • Image-size rule: it is now a function, unsized(html), that returns the <img> and <svg> tags with neither width and height attributes nor an inline width, height or aspect-ratio. The tour test calls it for every page. The standalone regex test is gone. A new test calls the same function on:
    • <img src="/a.png"> and <svg viewBox="0 0 1 1">, which it must flag.
    • A tag with width and height, one with style="aspect-ratio: 1", and a page with no pictures, which it must pass.
  • Comment on needs: it now says a new script in static/ has no rule there and fails as "not known", so its rule must be added with it.

I changed nothing else. The cap (31,000 bytes) and the script checks are as before.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs