-
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?
[FEATURE] - Remove the need for testGoldenScene
#72
Conversation
|
I don't think you "need" to use But now you've just moved that responsibility onto yourself for every test.
There are some tests that you only want to run on iOS. That runner is a convenience to configure the platform to iOS. If you want a gallery with multiple platforms, you don't need to use that runner. |
matthew-carroll
left a comment
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 did some review. Can't tell how much of this is actually intentional because it looks like you auto-reformatted the files you opened so it's mostly noise. Please try to revert and apply just the changes you intend to make.
| as golden_toolkit; | ||
|
|
||
| /// Remember if fonts have already been loaded in this isolate. | ||
| bool _fontsLoaded = false; |
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.
Is this actually needed? What's the current behavior that you're trying to fix with this?
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.
Seems to me like right now if I have multiple testGoldenScene tests in the same suite, they will all read the font manifest, even though the fonts have already been loaded. The same thing would happen with my change, but even if we don't move font loading somewhere else it seems like wasted work?
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'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).
| // 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(); |
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.
We don't want to force this on everyone. If people want standard Ahem goldens, they need to be able to get them.
| FtgLog.pipeline.finer("Done comparing goldens."); | ||
| await TestFonts.loadAppFonts(); | ||
|
|
||
| tester.view |
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.
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.
Sorry for that, I didn't notice. I did this quickly at the end of my workday so we can discuss the idea, hence the draft status. Thank you for taking the time to go through it anyway!
I think I see where you are coming from, but then – at least to me – the current API isn't really intuitive. You are saying that we don't need Before this change, users would wrap their galleries in I think on the flip side, it is more confusing to have the test function set up a different view for the entirety of its run, since it affects all other test code as well. For font loading, I understand why moving it to the gallery and timeline Expected behavior for me would be to set up Let me know what you think. |
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
I suppose another way to deal with this is for the gallery layouts to actually work with different DPRs. Then setting up the view correctly wouldn't be as essential for using them. |
Unless I'm missing something, I don't think this is true. I don't think the core functionality is broken - it looked like you just didn't account for the standard behavior of Is there actually something broken in there, or are you just dealing with the consequences of Flutter setting up 3.0 DPI, etc?
@isGoldenScene
@isTest
void testGoldenScene(
String description,
WidgetTesterCallback test, {
bool? skip,
Timeout? timeout,
bool semanticsEnabled = true,
TestVariant<Object?> variant = const DefaultTestVariant(),
dynamic tags,
int? retry,
}) {
testWidgets(
description,
(tester) async {
await TestFonts.loadAppFonts();
tester.view
..devicePixelRatio = 1.0
..platformDispatcher.textScaleFactorTestValue = 1.0;
try {
await test(tester);
} finally {
tester.view.reset();
}
},
skip: skip,
variant: variant,
timeout: timeout,
semanticsEnabled: semanticsEnabled,
tags: tags,
retry: retry,
);
}
Please see the implementation above. We call
I'm not sure there's any situation here that isn't a problem, because Flutter has made working with fonts in a test a problem. The question is, what's the least bad option we can provide? I'm open to options, but I think it's critical that we not put developers in a position where they can't make a choice about when/if a non-undoable thing is done.
Why do you want to control |
As you could see from #70, I expected to be able to just use this package from my normal
testWidgetstests, just like I would withmatchesGoldenFile.As a POC, I would propose something like this to make usage of this package as frictionless as possible. Things that are still TBD:
testGoldenSceneOnIOS)? I personally would've expected them to be part of the Gallery functionality itself, so that I can just create the same gallery on different platforms.