-
Notifications
You must be signed in to change notification settings - Fork 1
[FEATURE] - Remove the need for testGoldenScene
#72
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
base: main
Are you sure you want to change the base?
Changes from all commits
fd3981f
ff785e7
ee6c88c
42ff456
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "dart.lineLength": 120 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,19 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:flutter_test_goldens/src/fonts/golden_toolkit_fonts.dart' as golden_toolkit; | ||
|
|
||
| /// Remember if fonts have already been loaded in this isolate. | ||
| bool _fontsLoaded = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this actually needed? What's the current behavior that you're trying to fix with this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to me like right now if I have multiple
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just looking for clarity as to whether this actually prevents additional execution, or if we're just repeating something that's already tracked inside the font loading behavior. So without this we're re-reading the manifest on every call even if fonts are already loaded? (I haven't looked at that in a while). |
||
|
|
||
| /// Tools for working with fonts in tests. | ||
| abstract class TestFonts { | ||
| /// Load all fonts registered with the app and make them available | ||
| /// to widget tests. | ||
| static Future<void> loadAppFonts() async { | ||
| if (_fontsLoaded) { | ||
| return; | ||
| } | ||
| await golden_toolkit.loadAppFonts(); | ||
| _fontsLoaded = true; | ||
| } | ||
|
|
||
| static const openSans = "packages/flutter_test_goldens/OpenSans"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart' hide Image; | |
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:flutter_test_goldens/src/flutter/flutter_camera.dart'; | ||
| import 'package:flutter_test_goldens/src/flutter/flutter_test_extensions.dart'; | ||
| import 'package:flutter_test_goldens/src/fonts/fonts.dart'; | ||
| import 'package:flutter_test_goldens/src/goldens/golden_collections.dart'; | ||
| import 'package:flutter_test_goldens/src/goldens/golden_comparisons.dart'; | ||
| import 'package:flutter_test_goldens/src/goldens/golden_rendering.dart'; | ||
|
|
@@ -296,33 +297,42 @@ class Gallery { | |
| Future<void> run(WidgetTester tester) async { | ||
| FtgLog.pipeline.info("Rendering or comparing golden - $_sceneDescription"); | ||
|
|
||
| // Build each golden tree and take `FlutterScreenshot`s. | ||
| final camera = FlutterCamera(); | ||
| await _takeNewScreenshots(tester, camera); | ||
|
|
||
| // Convert each `FlutterScreenshot` to a golden `GoldenSceneScreenshot`, which includes | ||
| // additional metadata, and multiple image representations. | ||
| final screenshots = await _convertFlutterScreenshotsToSceneScreenshots(tester, camera.photos); | ||
|
|
||
| if (autoUpdateGoldenFiles) { | ||
| // Generate new goldens. | ||
| FtgLog.pipeline.finer("Generating new goldens..."); | ||
| // TODO: Return a success/failure report that we can publish to the test output. | ||
| await _updateGoldenScene( | ||
| tester, | ||
| _fileName, | ||
| screenshots, | ||
| ); | ||
| FtgLog.pipeline.finer("Done generating new goldens."); | ||
| } else { | ||
| // Compare to existing goldens. | ||
| FtgLog.pipeline.finer("Comparing existing goldens..."); | ||
| // TODO: Return a success/failure report that we can publish to the test output. | ||
| await _compareGoldens(tester, _fileName, screenshots); | ||
| FtgLog.pipeline.finer("Done comparing goldens."); | ||
| await TestFonts.loadAppFonts(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to force this on everyone. If people want standard Ahem goldens, they need to be able to get them. |
||
|
|
||
| tester.view | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't wanna force this either. I see that you're trying to merge things together, but that's actually the opposite of what a toolkit should do. Higher level conveniences that add default behaviors is fine. But forcing decisions on everyone at the center of the tool will lead to angry devs who get to a certain point of adoption and then realize they can't control something that they need to control. |
||
| ..devicePixelRatio = 1.0 | ||
| ..platformDispatcher.textScaleFactorTestValue = 1.0; | ||
|
|
||
| try { | ||
| // Build each golden tree and take `FlutterScreenshot`s. | ||
| final camera = FlutterCamera(); | ||
| await _takeNewScreenshots(tester, camera); | ||
|
|
||
| // Convert each `FlutterScreenshot` to a golden `GoldenSceneScreenshot`, which includes | ||
| // additional metadata, and multiple image representations. | ||
| final screenshots = await _convertFlutterScreenshotsToSceneScreenshots(tester, camera.photos); | ||
|
|
||
| if (autoUpdateGoldenFiles) { | ||
| // Generate new goldens. | ||
| FtgLog.pipeline.finer("Generating new goldens..."); | ||
| // TODO: Return a success/failure report that we can publish to the test output. | ||
| await _updateGoldenScene( | ||
| tester, | ||
| _fileName, | ||
| screenshots, | ||
| ); | ||
| FtgLog.pipeline.finer("Done generating new goldens."); | ||
| } else { | ||
| // Compare to existing goldens. | ||
| FtgLog.pipeline.finer("Comparing existing goldens..."); | ||
| // TODO: Return a success/failure report that we can publish to the test output. | ||
| await _compareGoldens(tester, _fileName, screenshots); | ||
| FtgLog.pipeline.finer("Done comparing goldens."); | ||
| } | ||
| FtgLog.pipeline.fine("Done with golden generation/comparison"); | ||
| } finally { | ||
| tester.view.reset(); | ||
| } | ||
|
|
||
| FtgLog.pipeline.fine("Done with golden generation/comparison"); | ||
| } | ||
|
|
||
| /// For each scene screenshot request, pumps its widget tree, and then screenshots it with | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the liberty to commit this, but I understand if you don't want this here. I thought it might help other VS Code users like me, that have the "format on save" setting turned on