-
Notifications
You must be signed in to change notification settings - Fork 3
test(goldens): render goldens with the real app theme #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Fonts | ||
|
|
||
| The app pairs **Playfair Display** (headings, app bar title) with **Nunito Sans** | ||
| (body, labels). Both are declared in `lib/app_theme.dart` via `buildAppTextTheme` | ||
| and resolved through the `google_fonts` package. | ||
|
|
||
| ## The font files are bundled, not fetched | ||
|
|
||
| `assets/fonts/` ships the exact `.ttf` files `google_fonts` would otherwise | ||
| download from `fonts.gstatic.com` at runtime. `google_fonts` checks the asset | ||
| bundle before it checks the network, so bundling means the typefaces resolve | ||
| locally on every platform. | ||
|
|
||
| Two things this buys us: | ||
|
|
||
| - **First paint has no network dependency.** Previously the app rendered in a | ||
| fallback face until the font download finished — over festival wifi, or on a | ||
| phone with no signal, that could be the whole session. | ||
| - **Golden tests are deterministic.** `test/flutter_test_config.dart` sets | ||
| `GoogleFonts.config.allowRuntimeFetching = false` for the whole test suite, | ||
| so goldens render the real faces identically on any machine, online or not. | ||
|
|
||
| Before this, golden tests rendered every glyph as the blocky `FlutterTest` | ||
| placeholder box, which meant no golden could catch a typography or text-layout | ||
| regression (issue #520). | ||
|
|
||
| ## Which variants are bundled | ||
|
|
||
| Only the weights `buildAppTextTheme` actually requests: | ||
|
|
||
| | File | Used by | | ||
| |---|---| | ||
| | `NunitoSans-Regular.ttf` (w400) | `bodyLarge`, `bodyMedium`, `bodySmall`, and the `nunitoSansTextTheme()` base | | ||
| | `NunitoSans-Medium.ttf` (w500) | `labelSmall`, base theme label styles | | ||
| | `NunitoSans-SemiBold.ttf` (w600) | `titleSmall`, `labelLarge`, `labelMedium` | | ||
| | `NunitoSans-Bold.ttf` (w700) | `titleMedium` | | ||
| | `PlayfairDisplay-SemiBold.ttf` (w600) | `displaySmall`, `headlineLarge/Medium/Small`, `titleLarge` | | ||
| | `PlayfairDisplay-Bold.ttf` (w700) | `displayLarge`, `displayMedium`, `appBarTheme.titleTextStyle` | | ||
|
|
||
| Roughly 674 KB in total. | ||
|
|
||
| ## Adding a weight | ||
|
|
||
| If you add a style to `buildAppTextTheme` that needs a weight not in the table | ||
| above, **the test suite will fail loudly** with: | ||
|
|
||
| ``` | ||
| GoogleFonts.config.allowRuntimeFetching is false but font X was not found in | ||
| the application assets. | ||
| ``` | ||
|
|
||
| That failure is the feature — it stops a new weight from silently depending on a | ||
| network fetch that only works on a connected machine. To fix it, add the variant: | ||
|
|
||
| 1. Find the file hash for the family/weight in the `google_fonts` package | ||
| manifest (`lib/src/google_fonts_parts/part_<letter>.g.dart` in the pub cache); | ||
| each entry is `GoogleFontsFile('<sha256>', <length>)`. | ||
| 2. Download it and verify both the hash and the length match: | ||
|
|
||
| ```bash | ||
| curl -sSL -o assets/fonts/<Family>-<Variant>.ttf \ | ||
| "https://fonts.gstatic.com/s/a/<sha256>.ttf" | ||
| sha256sum assets/fonts/<Family>-<Variant>.ttf # must equal <sha256> | ||
| stat -c%s assets/fonts/<Family>-<Variant>.ttf # must equal <length> | ||
| ``` | ||
|
|
||
| 3. The filename must be `<FamilyWithoutSpaces>-<Variant>.ttf` — that is exactly | ||
| the name quoted in the failure message. `assets/fonts/` is already listed in | ||
| `pubspec.yaml`, so no manifest edit is needed. | ||
| 4. Regenerate the affected goldens and review them by eye: | ||
| `./bin/mise run goldens:update <test_file>`. | ||
|
|
||
| Do **not** fix this by re-enabling runtime fetching in tests. | ||
|
|
||
| ## Known gap | ||
|
|
||
| Material icon glyphs still render as hollow boxes in goldens — `MaterialIcons` | ||
| is not loaded by `flutter_test`. That is unrelated to this setup and unchanged by | ||
| it; goldens cover icon *position and size*, not the glyph itself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:google_fonts/google_fonts.dart'; | ||
|
|
||
| /// Runs once before every test under `test/`, discovered automatically by | ||
| /// `flutter test`. | ||
|
richardthe3rd marked this conversation as resolved.
Outdated
|
||
| /// | ||
| /// Turning off runtime fetching forces `google_fonts` to resolve the app's | ||
| /// typefaces from the bundled assets in `assets/fonts/` instead of downloading | ||
| /// them from fonts.gstatic.com. That matters for two reasons: | ||
| /// | ||
| /// * **Determinism.** Goldens render the real Playfair/Nunito faces on every | ||
| /// machine, online or not, instead of depending on whether the runner | ||
| /// happened to reach Google's CDN. | ||
| /// * **It fails loudly.** If `buildAppTextTheme` gains a weight that has no | ||
| /// matching file in `assets/fonts/`, `google_fonts` throws and the test | ||
| /// fails, rather than silently papering over it with a network fetch that | ||
| /// only works on a connected machine. | ||
| /// | ||
| /// If a test starts failing with "allowRuntimeFetching is false but font | ||
| /// X was not found", the fix is to add that variant to `assets/fonts/` — not to | ||
| /// re-enable fetching. See docs/code/fonts.md. | ||
| Future<void> testExecutable(FutureOr<void> Function() testMain) async { | ||
| GoogleFonts.config.allowRuntimeFetching = false; | ||
| await testMain(); | ||
| } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.