Skip to content

feat(test): add --dart-define #492

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

Merged
merged 10 commits into from
Sep 14, 2022

Conversation

Giuspepe
Copy link
Contributor

@Giuspepe Giuspepe commented Sep 12, 2022

Description

This PR adds the --dart-define parameter to the test command.

--dart-define is used to define compile-time constants which are then available through the String.fromEnvironment, bool.fromEnvironment, int.fromEnvironment, and double.fromEnvironment constructors.
Tests relying on such compile-time constants can currently not be run with very_good test, because the command doesn't yet accept the --dart-define parameter.

An example where one would use a --dart-define compile-time constant is to switch between different environments or flavors of an app. E.g. --dart-define=APP_ENVIRONMENT=dev.
This is useful because code as the following is automatically deleted in an optimization step when building an app:

const environment = String.fromEnvironment('APP_ENVIRONMENT');
const isEnvironmentDev = environment == 'dev';

...

// the whole if-block is automatically deleted during optimization when APP_FLAVOR != dev
// because `isEnvironmentDev` is a compile-time constant
if(isEnvironmentDev) {
  final secretDataOnlyForDev = 42;
}

Type of Change

  • ✨ 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

@Giuspepe
Copy link
Contributor Author

Giuspepe commented Sep 12, 2022

FYI: It seems that the CI test task is a bit flaky. I got the following error on my first CI run. When I reran the CI task with the same code, it succeeded without any errors.
The errors don't look like they're caused by my changes though.

https://github.com/VeryGoodOpenSource/very_good_cli/runs/8308620438?check_suite_focus=true
image

@felangel felangel added the feature A new feature or request label Sep 14, 2022
Copy link
Contributor

@felangel felangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks so much for the contribution!

@felangel felangel changed the title feat: add --dart-define parameter to very_good test command feat(test): add --dart-define Sep 14, 2022
@felangel felangel merged commit 1efa5aa into VeryGoodOpenSource:main Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants