alchemist icon indicating copy to clipboard operation
alchemist copied to clipboard

feat: new optional loadFonts parameter

Open EArminjon opened this issue 2 years ago โ€ข 14 comments

Description

fix memory issue along multiple call to loadFonts. https://github.com/Betterment/alchemist/issues/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

  • [x] โœจ New feature (non-breaking change which adds functionality)
  • [x] ๐Ÿ› ๏ธ 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
  • [x] ๐Ÿ“ Documentation
  • [ ] ๐Ÿ—‘๏ธ Chore

EArminjon avatar Sep 19 '23 14:09 EArminjon

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

EArminjon avatar Sep 19 '23 15:09 EArminjon

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),
  );
}

TesteurManiak avatar Nov 20 '23 15:11 TesteurManiak

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.

EArminjon avatar Nov 20 '23 21:11 EArminjon

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 ๐Ÿค”

TesteurManiak avatar Nov 21 '23 13:11 TesteurManiak

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

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!

bmt-github-policybot avatar Feb 24 '24 09:02 bmt-github-policybot

Don't close please

EArminjon avatar Feb 24 '24 12:02 EArminjon

Should I add the parameter in this config ?

EArminjon avatar Feb 24 '24 12:02 EArminjon

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

samandmoore avatar Feb 24 '24 14:02 samandmoore

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 24 '24 14:02 codecov[bot]

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

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

Thanks for helping keep our house in order!

bmt-github-policybot avatar Apr 16 '24 09:04 bmt-github-policybot