Skip to content
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

feat: new optional loadFonts parameter #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EArminjon
Copy link

@EArminjon EArminjon commented Sep 19, 2023

Description

fix memory issue along multiple call to loadFonts.
#76

As a developer, I just need to put loadFonts: false and call the following code before my multiple goldenTest().

setUpAll(() async {
    await loadFonts();
  });

This fix also increase test speed, it's insane.

Type of Change

New optional parameters

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@EArminjon EArminjon changed the title feature/optional-fonts: new optional parameter feat: optional-fonts: new optional parameter Sep 19, 2023
@EArminjon
Copy link
Author

Maybe an other solution can be to check inside loadFonts if the fonts already exist. I didn't know if it's possible.

@EArminjon EArminjon changed the title feat: optional-fonts: new optional parameter feat: new optional loadFonts parameter Sep 19, 2023
@TesteurManiak
Copy link

I find it a bit cumbersome to have to specify goldenTest(loadFonts: false) every time when you might want to disable it globally.
Maybe you could consider injecting the loadFonts value with an environment variable 🤔

For example:

flutter test --dart-define=LOAD_GOLDEN_FONTS=false

The implementation in golden_test.dart could be:

const _loadFontsDefault = bool.fromEnvironment('LOAD_GOLDEN_FONTS', defaultValue: true);

// ...

Future<void> goldenTest({
  // ...
  bool? loadFonts,
}) async {
  // ...

  goldenTestAdapter.setUp(
    () => _setUpGoldenTests(mustLoadFonts: loadFonts ?? _loadFontsDefault),
  );
}

@EArminjon
Copy link
Author

I find it a bit cumbersome to have to specify goldenTest(loadFonts: false) every time when you might want to disable it globally. Maybe you could consider injecting the loadFonts value with an environment variable 🤔

For example:

flutter test --dart-define=LOAD_GOLDEN_FONTS=false

The implementation in golden_test.dart could be:

const _loadFontsDefault = bool.fromEnvironment('LOAD_GOLDEN_FONTS', defaultValue: true);

// ...

Future<void> goldenTest({
  // ...
  bool? loadFonts,
}) async {
  // ...

  goldenTestAdapter.setUp(
    () => _setUpGoldenTests(mustLoadFonts: loadFonts ?? _loadFontsDefault),
  );
}

I think we can find a better solution. I create this PR as a quick fix because i (and my team) couldn't use this package.
Defining env variable is maybe not perfect. If someone forgot it or just run flutter test, he can encounter issues.

@TesteurManiak
Copy link

Defining env variable is maybe not perfect. If someone forgot it or just run flutter test, he can encounter issues.

True, maybe adding a property to AlchemistConfig or PlatformGoldensConfig should be the way to go 🤔

@bmt-github-policybot
Copy link

This pull request has been automatically closed because it has not been updated in the last 3 months. 😪

If you still need this change, please reopen it and update it within the next 3 months.

Thanks for helping keep our house in order!

@EArminjon
Copy link
Author

Don't close please

@EArminjon
Copy link
Author

Should I add the parameter in this config ?

@samandmoore samandmoore reopened this Feb 24, 2024
@samandmoore
Copy link
Member

Sorry about that! We have to make some time to dig into this

Copy link

codecov bot commented Feb 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (cd09414) to head (8040f8a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #101   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          562       563    +1     
=========================================
+ Hits           562       563    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmt-github-policybot
Copy link

This pull request has been automatically closed because it has not been updated in the last month. 😪

If you still need this change, you can reopen it.

Thanks for helping keep our house in order!

@pedromassango
Copy link
Contributor

commenting for visibility

@jeroen-meijer
Copy link
Collaborator

jeroen-meijer commented Sep 27, 2024

What I'm gathering from this is, loadFonts only needs to be called once per group/test/instance (which one is it?). So then shouldn't we move loadFonts into some setup logic that is guaranteed to only be run once per group/test/instance?

This doesn't seem like something users should handle, but instead something that Alchemist needs to keep into account by default. I don't see a use-case for a feature where users can toggle loadFonts on or off per test or group -- it should either happen once or not at all (if a user desires the latter).

@samandmoore @btrautmann @Kirpal @EArminjon Can any of you confirm this thinking?

@pedromassango
Copy link
Contributor

What I'm gathering from this is, loadFonts only needs to be called once per group/test/instance (which one is it?). So then shouldn't we move loadFonts into some setup logic that is guaranteed to only be run once per group/test/instance?

This doesn't seem like something users should handle, but instead something that Alchemist needs to keep into account by default. I don't see a use-case for a feature where users can toggle loadFonts on or off per test or group -- it should either happen once or not at all (if a user desires the latter).

@samandmoore @btrautmann @Kirpal @EArminjon Can any of you confirm this thinking?

That is exactly it. Thank you!
If we could make sure it runs one per every flutter test that would be ideal as devs don't tend to change fonts per test/group.

@btrautmann
Copy link
Contributor

What I'm gathering from this is, loadFonts only needs to be called once per group/test/instance (which one is it?). So then shouldn't we move loadFonts into some setup logic that is guaranteed to only be run once per group/test/instance?

This doesn't seem like something users should handle, but instead something that Alchemist needs to keep into account by default. I don't see a use-case for a feature where users can toggle loadFonts on or off per test or group -- it should either happen once or not at all (if a user desires the latter).

@samandmoore @btrautmann @Kirpal @EArminjon Can any of you confirm this thinking?

I agree with the thinking here and agree with @pedromassango that this makes sense once per "suite run". This actually feels similar in terms of granularity to what I mention here, where we're wanting to detect the architecture once and then resolve the golden paths based on that. I mentioned some sort of "global caching mechanism" that may make sense for this use case as well, so maybe in whatever issue we tackle first we could be sure to support additional use cases (if it makes sense to do so).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants