Skip to content

test(fonts): mock google font files in unit tests - #2412

Merged
james-elicx merged 1 commit into
cloudflare:mainfrom
NathanDrake2406:nathan/fix-font-google-unit-flake
Jun 29, 2026
Merged

test(fonts): mock google font files in unit tests#2412
james-elicx merged 1 commit into
cloudflare:mainfrom
NathanDrake2406:nathan/fix-font-google-unit-flake

Conversation

@NathanDrake2406

Copy link
Copy Markdown
Contributor

Fixes #2411

Overview

The Google font self-hosting unit tests now mock both the CSS request to fonts.googleapis.com and the font binary request to fonts.gstatic.com.

Why

The flaky CI failure was a real test isolation bug. The plugin intentionally treats raw Google Fonts fetch failures as recoverable offline behavior and skips _vinext.font injection, but this unit test expected deterministic self-hosted output while relying on external network availability.

What changed

  • Added an MSW helper for Google font file responses.
  • Mocked Google CSS and .woff2 responses in the self-hosting transform test.
  • Mocked the same responses in the fetch/cache integration test so it still proves downloaded .woff2 cache output without external network.

Validation

  • for i in 1 2 3 4 5; do vp test run tests/font-google.test.ts || exit $?; done
  • vp check tests/font-google.test.ts

Note: local pre-commit was run and its staged file check passed, but its broad repo check failed in this fresh worktree because packages/vinext/node_modules/react-dom was not linked. The targeted checks above passed against the changed file.

The font self-hosting unit tests depended on live Google Fonts CSS and font file requests. When the CSS fetch hit a recoverable network error, the plugin correctly skipped _vinext injection for offline fallback, but the test expected self-hosted output.

Mock both fonts.googleapis.com CSS and fonts.gstatic.com font binaries for the self-hosting assertions. The offline fallback behavior remains covered by the explicit network-error test.
@pkg-pr-new

pkg-pr-new Bot commented Jun 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@2412
npm i https://pkg.pr.new/vinext@2412

commit: 60cbe52

@github-actions

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 60cbe52 against base 25f3d09 using alternating same-runner rounds. Next.js was unchanged and skipped.

0 improved · 0 regressed · 6 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 124.0 KB 124.0 KB ⚫ +0.0%
Client entry size (gzip) vinext 118.8 KB 118.8 KB ⚫ +0.0%
Dev server cold start vinext 2.41 s 2.42 s ⚫ +0.2%
Production build time vinext 2.82 s 2.81 s ⚫ -0.3%
RSC entry closure size (gzip) vinext 95.2 KB 95.2 KB ⚫ +0.0%
Server bundle size (gzip) vinext 161.4 KB 161.5 KB ⚫ +0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

@james-elicx
james-elicx merged commit c8aef02 into cloudflare:main Jun 29, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky font-google unit test depends on live Google Fonts fetches

2 participants