golden_test 2.2.0
golden_test: ^2.2.0 copied to clipboard
A utility Flutter plugin for writing golden tests that streamlines adding golden tests to your project
2.2.0 #
New features #
- Keyboard:
goldenTesttakes akeyboard, which shows the software keyboard over the bottom of the screen for the whole test, so a golden captures how a screen lays out while someone is typing. The view reports it as a bottomviewInsets, as a device does, so aScaffoldwithresizeToAvoidBottomInsetshrinks its body, one without it is covered, and content that no longer fits overflows. It takes the taps over its area, as on a device.GoldenKeyboardpicks theTextInputType(letters, email, URL, Twitter, web search, number pad, phone pad, and the iOS digits-and-punctuation layer fordatetimeand signed numbers), the style (GoldenKeyboardStyle.iosor.android) and optionally the height. See README § Keyboard. - Keyboard on focus, opt-in: with
goldenTestSimulateKeyboard = trueinflutter_test_config.dart, orsimulateKeyboard: trueon a singlegoldenTest, the keyboard appears by itself when a text field in the widget under test gains focus and hides when it loses focus. It is built from what the field asks the platform for, so its layout follows the field'skeyboardTypeand its style the device's platform. As on a device, a field withTextInputType.noneand a device with a desktopplatformopen no keyboard. While it is on, the harness leavesviewInsetsto the widget under test, so a test that setstester.view.viewInsetsitself is no longer shrunk by the harness. It is off by default, because turning it on changes every golden that focuses a field. Device.platform: devices carry an optionalTargetPlatform, which picks the keyboard drawn whenGoldenKeyboardhas no style of its own.Device.iphone15Pro()andDevice.ipadPro12()are iOS,Device.pixel9ProXL()is Android andDevice.browser()is macOS, which shows no keyboard on focus. It does not change the platform the widget under test is built for.
2.1.1 #
Fixes #
- Failure images no longer overwrite each other across variants — without
goldenTestDifferenceTolerance, Flutter's own comparator was used. It writes every failure to onefailures/folder next to the test file, named after the golden file only. All locales, themes, devices and text scales of a test share that name, so each failing variant overwrote the previous one and only the last one was left.goldenTestnow uses the package comparator with a tolerance of 0 unless the project set its own comparator, so failure images always land next to each variant's golden file, e.g.goldens/en/light/failures/.goldenTestDifferenceTolerancestill sets the tolerance. If your CI uploadstest/failures/or your.gitignoreignores onlytest/failures/, change them to**/goldens/**/failures/. - Diff images are freed after each comparison — the package comparator never disposed the comparison result, so its diff images leaked on every failure and on every pass within the tolerance.
2.1.0 #
New features #
- Navigator builder:
goldenTesttakes anavigatorBuilder, andgoldenTestNavigatorBuildersets one for every test. In the harness the root navigator is the only one, so every route pushed from the widget under test (dialogs, sheets, menus, pages) is built next to it. Providers returned frombuildernever reached those routes, so they failed to build.navigatorBuilderwraps the root navigator, so what it provides is visible to every route. Both are typedGoldenTestNavigatorBuilder, which receives the navigator as a non-nullWidget, for wrappers aroundgoldenTestthat forward it. See README § Navigator Builder.
2.0.1 #
Fixes #
- Goldens no longer fail when the widget under test builds its own app — the screenshot was taken of
find.byType(MaterialApp), which matched both the harness's app and the one under test. The test failed withmatched too many widgetsand no golden was written, including under--update-goldens. Server-driven UI, storybook-style harnesses and nested navigators all hit this. The snapshot is now anchored to a private root widget, so it resolves to a single widget whatever the builder returns. Existing goldens are byte-identical and do not need regenerating.
2.0.0 #
Breaking changes #
- Migrated to
material_ui— Flutter 3.47 decoupled Material (and Cupertino) from the core SDK into standalonematerial_ui/cupertino_uipackages on pub.dev, deprecatingpackage:flutter/material.dart.golden_testnow importspackage:material_ui/material_ui.dartinstead, and the minimum supported Flutter version is now3.47.0(Dart SDK>=3.13.0). Projects on older Flutter versions will need to stay ongolden_test1.x. - Framework localization delegates are now built in —
GlobalMaterialLocalizations,GlobalWidgetsLocalizationsandGlobalCupertinoLocalizationsare appended automatically, sogoldenTestLocalizationsDelegatesonly needs your own app's delegates. Remove the framework ones from your config; you no longer need to import them, or to depend onflutter_localizations/cupertino_uijust for tests. This also sidesteps theambiguous_importthat otherwise occurs becauseflutter_localizationsstill exports deprecated copies of the Material and Cupertino delegates thatmaterial_ui/cupertino_uinow own. Delegates you supply are resolved before the built-in ones, so overriding still works. - Network images are stubbed by default —
goldenTestStubNetworkImagesdefaults totrue, so anyNetworkImagenow resolves to a placeholder instead of failing to load. Goldens that contain network images will change: they previously captured a blank or error state and now show the placeholder, so they need regenerating. If you already stub network images yourself, note that golden_test installs its stub before the test body: adebugNetworkImageHttpClientProviderorHttpOverridesset influtter_test_config.dartis superseded — setgoldenTestStubNetworkImages = falseto keep your own. Stubs installed insideglobalSetupor a test'ssetupstill win, since those run after, and are unaffected.
New features #
- AI agent skills — the package now ships three Agent Skills under
skills/, installable withdart run skills@ get:golden_test-setup(wiringflutter_test_config.dartto your app's themes, locales and fonts),golden_test-widget(component goldens) andgolden_test-route(screen goldens). They cover which test axes are worth their cost, deriving edge cases from branches in your own formatting code, and reading a failing golden — see README § AI Agent Skills. - Built-in network image stub — golden tests no longer time out or produce flaky output when the widget tree loads images from the network. Any
NetworkImageis resolved from a placeholder out of the box, no setup required, wherever it appears —Image.network,FadeInImage, aDecorationImagein aBoxDecoration, or a custom widget. Otherdart:ioHTTP traffic is left alone, so a repository call fired from the widget tree still behaves as it did. Opt out withgoldenTestStubNetworkImages = false, or replace the placeholder viagoldenTestNetworkImageStubPng. - Image loader hook —
goldenTestImageLoaderSetupslets any package register a per-test image-loading stub, for loaders that don't go throughNetworkImage. It's a list, so several packages can register without clobbering one another.CachedNetworkImageis supported this way by the companiongolden_test_cached_network_imagepackage, which keepscached_network_imageandflutter_cache_managerout of the dependency graph of projects that don't use them — see README § CachedNetworkImage support.
Fixes #
Device.copyWithno longer dropsname— omittingnamereset it tonull, which made the golden path fall back todefaultand caused distinct devices in onesupportedDeviceslist to share a single golden file.
1.1.2 #
Released from the 1.x maintenance branch, for projects still on Flutter below 3.47. Same fix as 2.0.1.
Fixes #
- Goldens no longer fail when the widget under test builds its own app — the screenshot was taken of
find.byType(MaterialApp), which matched both the harness's app and the one under test. The test failed withmatched too many widgetsand no golden was written, including under--update-goldens. Server-driven UI, storybook-style harnesses and nested navigators all hit this. The snapshot is now anchored to a private root widget, so it resolves to a single widget whatever the builder returns. Existing goldens are byte-identical and do not need regenerating.
1.1.1 #
Fixes #
- Bundled Roboto font — The package now ships its own Roboto font, so the device frame's status bar time renders correctly in any consuming project regardless of whether it bundles Roboto itself.
1.1.0 #
Fixes #
- Async hooks now awaited —
globalSetup,setup, andtearDowncallbacks are now properly awaited insidegoldenTest, preventing race conditions with font loading,Intl.defaultLocale, and mock wiring.
Improvements #
- Typed
tagsparameter —goldenTest'stagsparameter is nowObject?(matching Flutter's owntestWidgetssignature) instead ofdynamic, with dartdoc clarifying the accepted shapes (String,Tag,Iterable).
New features #
- Text-scale matrix —
supportedTextScalesandgoldenTestSupportedTextScalesadd text scale as a test axis. Optional [AndroidFontScale] / [IosDynamicTypeScale] enums and accessibility preset lists are available.
1.0.1 #
- Fixed README images not rendering on pub.dev by using absolute URLs.
1.0.0 #
First stable release under semantic versioning; the public API is now versioned with breaking changes reserved for major bumps.
Breaking changes #
- Golden frame — Redesigned the status bar and bottom bar UI rendered around the widget under test. All existing golden screenshots will need to be regenerated (
flutter test --update-goldens).
Improvements #
- Example app — Expanded and clearer examples demonstrating real usage patterns.
- Documentation — Reworked and expanded docs so setup and options are easier to follow.
0.1.7 #
- Added
tagsparameter to properly proxy it totestWidgets
0.1.6 #
- New Feature: Added
subdirectoryparameter togoldenTestfor organizing golden files into custom subdirectories- Allows per-test configuration of golden file organization
- Useful for managing multiple apps with different design tokens
- Supports nested subdirectories (e.g.,
'design_system/v2') - Path structure:
goldens/[subdirectory]/locale/theme/[device]/name.png
0.1.5 #
-
Refactor device configuration system to support three distinct configuration levels:
- New: Added
goldenTestDefaultDevicesfor setting global default device(s) - Improved:
goldenTestSupportedDevicesnow exclusively for multi-device testing - Changed:
supportedDevicesparameter is now nullable, enabling proper configuration hierarchy - Enhanced: Device selection logic now follows clear priority: per-test override > multi-device mode > global default
- Fixed: Golden file paths now intelligently include device names only when testing multiple devices
This change makes device configuration more intuitive and eliminates the need to pass
supportMultipleDevices: truejust to use a globally-defined single device. - New: Added
-
Improved formatting
-
Updated dependencies
-
Updated example project
-
Updated documentation
-
Drop deprecated .withOpacity
0.1.4 #
Fix directory for generating failure screenshots.
0.1.3 #
Add option to precache assets.
0.1.2 #
Add option to set difference tolerance at which tests are considered failing.
0.1.1 #
Add read.me to example project.
0.1.0 #
Initial release of goldenTest method which helps writing Golden Tests very easily by pumping Flutter Widgets.
Features:
goldenTest- utility method for generating screenshots- Supporting multiple locales.
- Supporting multiple localizations.
- Supporting light and dark mode.