|
| 1 | +# Contributing |
| 2 | + |
| 3 | +If you run into any problems, please file a [new |
| 4 | +bug](https://github.com/flutter/flutter/issues/new?labels=p:%20rfw,package,P2). |
| 5 | +Rather than waiting for a fix, we encourage you to consider submitting |
| 6 | +a PR yourself. See our [contributing |
| 7 | +guide](https://github.com/flutter/packages/blob/master/CONTRIBUTING.md) |
| 8 | +for details. |
| 9 | + |
| 10 | +Adding more widgets to `lib/flutter/core_widgets.dart` and |
| 11 | +`lib/flutter/material_widgets.dart` is welcome. |
| 12 | + |
| 13 | +When contributing code, ensure that `flutter test --coverage; lcov |
| 14 | +--list coverage/lcov.info` continues to show 100% test coverage, and |
| 15 | +update `test_coverage/bin/test_coverage.dart` with the appropriate |
| 16 | +expectations to prevent future coverage regressions. (That program is |
| 17 | +run by `run_tests.sh`.) |
| 18 | + |
| 19 | +## Tests |
| 20 | + |
| 21 | +To run the tests, use `flutter test`. |
| 22 | + |
| 23 | +To run the web tests, use `flutter test --platform=chrome`. If there |
| 24 | +is code that only runs on the web target, mark each such line by |
| 25 | +ending it with the string `// dead code on VM target`. This will |
| 26 | +exclude that line from the coverage calculation. |
| 27 | + |
| 28 | +Golden tests are only run against the Flutter master channel and only |
| 29 | +run on Linux, since minor rendering differences are expected on |
| 30 | +different platforms and on different versions of Flutter. |
| 31 | + |
| 32 | +## Golden test failures |
| 33 | + |
| 34 | +When golden tests fail, several files will be created in a `test/failures` |
| 35 | +directory. |
| 36 | + |
| 37 | +The suffix of each file briefly describes its contents: |
| 38 | + |
| 39 | +* `_masterImage`: The current golden against which comparisons are being made. |
| 40 | +* `_testImage`: The image generated by this run of the test. |
| 41 | +* `_isolatedDiff`: An image where only the pixels that differ between the |
| 42 | + master and test images are rendered. |
| 43 | +* `_maskedDiff`: An image where the pixels that differ between the master and |
| 44 | + test images are rendered in black (isolatedDiff + maskedDiff = testImage). |
| 45 | + |
| 46 | +Check the `_testImage` and the `Diff`s and see if the changes are valid. From |
| 47 | +time to time, a new dithering or anti-aliasing algorithm will land in Flutter |
| 48 | +that will invalidate a bunch of goldens, but not really break the rendering. |
| 49 | + |
| 50 | +In this case, you may update the golden files. |
| 51 | + |
| 52 | +### Updating golden files |
| 53 | + |
| 54 | +Once you've validated that the new goldens are correct, you may update them by |
| 55 | +calling `run_tests.sh --update-goldens`. |
| 56 | + |
| 57 | +That command updates the reference golden images in the `test/goldens` directory. |
| 58 | + |
| 59 | +Read more about Golden matching [in `package:flutter_test` API docs][package-test]. |
| 60 | + |
| 61 | +[package-test]: https://api.flutter.dev/flutter/flutter_test/matchesGoldenFile.html |
0 commit comments