You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/contributing/testing/Writing-a-golden-file-test-for-package-flutter.md
+99-12Lines changed: 99 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,20 @@ _(This page is referenced by comments in the Flutter codebase.)_
7
7
Golden file tests for `package:flutter` use [Flutter Gold](https://flutter-gold.skia.org/?query=source_type%3Dflutter) for baseline and version management of golden files. This allows for golden file testing on Linux, Windows, MacOS and Web, which accounts for the occasional subtle rendering differences between these platforms.
8
8
9
9
## Index
10
+
10
11
-[Known Issues](#known-issues)
11
12
-[Build Breakage](#build-breakage)
12
13
-[Creating a New Golden File Test](#creating-a-new-golden-file-test)
13
-
-[Adding a new key in the Skia Client](#Adding-a-new-key-in-the-Skia-Client)
14
+
-[Add or configure a `.ci.yaml` task](#add-or-configure-a-ciyaml-task)
15
+
-[Adding a known task name to the `flutter-gold` check](#adding-a-known-task-name-to-the-flutter-gold-check)
16
+
-[Writing and submitting the test](#writing-and-submitting-the-test)
17
+
-[Adding a new key in the Skia Client](#adding-a-new-key-in-the-skia-client)
14
18
-[Updating a Golden File Test](#updating-a-golden-file-test)
15
19
-[Flutter Gold Login](#flutter-gold-login)
16
20
-[`flutter-gold` Check](#flutter-gold-check)
17
21
-[`reduced-test-set` tag](#reduced-test-set-tag)
18
22
-[Troubleshooting](#troubleshooting)
19
23
20
-
21
24
## Known Issues
22
25
23
26
### Negative Images
@@ -31,9 +34,7 @@ If you would like to instantly invalidate all prior renderings, changing the nam
31
34
32
35
If the Flutter build is broken due to a golden file test failure, this typically means an image change has landed without being triaged. Golden file images should be triaged in pre-submit before a change lands (as described in the steps below). If this process is not followed, a test with an unapproved golden file image will fail in post-submit testing. This will present in the following error message:
33
36
34
-
<!-- TODO(Piinks): Update this error message in the framework. -->
35
-
36
-
```
37
+
```txt
37
38
Skia Gold received an unapproved image in post-submit
38
39
testing. Golden file images in flutter/flutter are triaged
39
40
in pre-submit during code review for the given PR.
@@ -50,6 +51,92 @@ Notice, Gold may wrongly attribute blame for image changes on the dashboard. Pos
50
51
51
52
## Creating a New Golden File Test
52
53
54
+
<!--
55
+
Note: These instructions are also referred to in the flutter/engine repository
56
+
ensure that when updating them, the workflow is either consistent or the
57
+
differences are clearly called out.
58
+
-->
59
+
60
+
Writing a _new_ golden file test if the _test suite_ (sometimes called "task"
61
+
or "shard") is not already configured for golden file testing is an involved
62
+
process, and missing a step can result in a broken build or a failing test.
63
+
64
+
The process involves:
65
+
66
+
1.[Adding or configuring a `.ci.yaml` task](#add-or-configure-a-ciyaml-task).
67
+
1.[Writing and submitting the test](#writing-and-submitting-the-test).
68
+
1.[Adding a known task name to the `flutter-gold` check](#adding-a-known-task-name-to-the-flutter-gold-check).
69
+
70
+
### Add or configure a `.ci.yaml` task
71
+
72
+
_If you are editing an existing test or test suite that already includes the
73
+
`goldctl` dependency (as seen below), you can skip this step._
74
+
75
+
Every test suite that runs tests (golden file tests included) needs to be
76
+
configured in the top-level [`.ci.yaml` file](../../../.ci.yaml), which contains
77
+
the configuration for all the CI tasks that run on the Flutter repository. For
78
+
example, the task `Linux framework_tests_widgets` (as of 2024-08-27) looks like
> The exact git revision of `goldctl` should be copied from an existing task.
108
+
109
+
If a new dependency was added, see [adding a known task name to the `flutter-gold` check](#adding-a-known-task-name-to-the-flutter-gold-check).
110
+
111
+
### Adding a known task name to the `flutter-gold` check
112
+
113
+
The `flutter-gold` check is a cron job that is scheduled to run (every 5
114
+
minutes) through every open (non-draft) PR across `flutter/flutter` and
115
+
`flutter/engine`is checked for tasks that are _known_ to run golden file tests,
116
+
and if they are present, the check asks (via a Skia Gold API) if there were any
117
+
untriaged images generated, showing a :question: if so, or a :white_check_mark:
118
+
if not.
119
+
120
+
This list is manually curated in the [`flutter/cocoon` codebase](https://github.com/flutter/cocoon/blob/65e89508cad5b6f9622ee072a1178913fed5001e/app_dart/lib/src/request_handlers/push_gold_status_to_github.dart#L123-L144)
121
+
and needs to be updated when new tasks are added or removed.
122
+
123
+
See [#149544](https://github.com/flutter/flutter/pull/149544) for an example of adding a new task to the list
124
+
and [#143863](https://github.com/flutter/flutter/issues/143863#issuecomment-2310898513) for a discussion on the topic.
125
+
126
+
Failure to add a new task to this list will result in the `flutter-gold` check
127
+
not running on some PRs (and build breakages as a result).
128
+
129
+
### Writing and submitting the test
130
+
131
+
> [!NOTE]
132
+
> These instructions are specific to writing golden file tests for
133
+
> `package:flutter`. If you are writing integration tests, or tests in another
134
+
> repository (such as `flutter/engine`) the specifics will be different; consult
135
+
> relevant documentation and/or team members about the process. Examples:
Write your test as a normal test, using `testWidgets` and `await tester.pumpWidget` and so on.
54
141
55
142
Put a `RepaintBoundary` widget around the part of the subtree that you want to verify. If you don't, the output will be a 2400x1800 image, since the tests by default use an 800x600 viewport with a device pixel ratio of 3.0. If you would like to further control the image size, put a `SizedBox` around your `RepaintBoundary` to set constraints.
@@ -108,10 +195,9 @@ The updated tests can be triaged from these tryjobs, which will cause the pendin
108
195
109
196
And that’s it! Your new golden file(s) will be checked in as the baseline(s) for your new test(s), and your PR will be ready to merge. :tada:
110
197
111
-
112
198
## Flutter Gold Login
113
199
114
-
Triage permission is currently restricted to members of *flutter-hackers*. For more information, see [Contributor Access](../Contributor-access.md).
200
+
Triage permission is currently restricted to members of _flutter-hackers_. For more information, see [Contributor Access](../Contributor-access.md).
115
201
Once you have been added as an authorized user for Flutter Gold, you can log in through the [homepage of the Flutter Gold dashboard](https://flutter-gold.skia.org/) and proceed to triage your image results under [Changelists](https://flutter-gold.skia.org/changelists).
116
202
117
203
## `flutter gold` Check
@@ -134,10 +220,11 @@ For more context, see [flutter.dev/go/reduce-ci-tests](https://flutter.dev/go/re
134
220
135
221
## Troubleshooting
136
222
137
-
* Trouble: the `flutter-gold` is stuck at pending status while all other checks are successful (if they are not, see [flutter-gold check](#flutter-gold-check)).
138
-
* Solution: this may be a side-effect of force-pushed commits (`git push -f`) and a known Skia Gold issue (https://issues.skia.org/issues/40044676), typically after a rebase. If this happens, try rebasing or pushing an empty commit without force pushing. This side-effect is flaky.
139
-
* Trouble: the `flutter-gold` check posted a message saying "Golden file changes have been found..." but the triage page is empty.
140
-
* Solution: this may be another side-effect of force-pushed commits (see above), but may also be a side-effect of untriaged goldens from already submitted PRs. Try rebasing again, or reach out in #hackers-infra on the Discord.
223
+
-Trouble: the `flutter-gold` is stuck at pending status while all other checks are successful (if they are not, see [flutter-gold check](#flutter-gold-check)).
224
+
-Solution: this may be a side-effect of force-pushed commits (`git push -f`) and a known Skia Gold issue (https://issues.skia.org/issues/40044676), typically after a rebase. If this happens, try rebasing or pushing an empty commit without force pushing. This side-effect is flaky.
225
+
-Trouble: the `flutter-gold` check posted a message saying "Golden file changes have been found..." but the triage page is empty.
226
+
-Solution: this may be another side-effect of force-pushed commits (see above), but may also be a side-effect of untriaged goldens from already submitted PRs. Try rebasing again, or reach out in #hackers-infra on the Discord.
141
227
142
228
## Additional Resources
143
-
-[Gold APIs used by the Flutter Framework](https://docs.google.com/document/d/1H3CDqT7zBUt4Je2HPQpleYA-drwj2oy0mdPlSdf2d4A/edit?usp=sharing)
229
+
230
+
- [Gold APIs used by the Flutter Framework](https://docs.google.com/document/d/1H3CDqT7zBUt4Je2HPQpleYA-drwj2oy0mdPlSdf2d4A/edit?usp=sharing)
0 commit comments