Skip to content

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

Merged
felangel merged 10 commits intoVeryGoodOpenSource:mainfrom
Giuspepe:dart-define-parameter
Sep 14, 2022
Merged

feat(test): add --dart-define#492
felangel merged 10 commits intoVeryGoodOpenSource:mainfrom
Giuspepe:dart-define-parameter

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
ahsanf pushed a commit to Arkabyte-Teknologi/very_good_cli that referenced this pull request Aug 12, 2025
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