Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
As discovered in #199 the Node dotenv package does not support dotenv file hierarchy out-of-the-box like dotenv-rails does. Since test commands are run as a child process of the percy command, the
.env
file has already been loaded into the environment via dotenv and will not be overridden by dotenv-rails.Approach
The dotenv-rails readme outlines the order of priority for various supported files. Since dotenv will only set env vars that have not been previously set, we can load the files in priority order to mimic dotenv-rails hierarchy.
In addition to properly setting variables as expected to be set by dotenv-rails, this also makes it so various
PERCY_*
environment variables can be set in environment specific dotenv files as well.The
NODE_ENV
environment variable must be set for environment specific dotenv files. For example,NODE_ENV=production
will load.env.production.local
,.env.local
,.env.production
, and.env
files in that order.Questions
As mentioned in #199, we might be wary of continuously adding support for different dotenv language behaviors. I personally like dotenv-rails approach and think it's fine to add this support so we can capture
PERCY_*
variables defined in those files. As for other languages, what are their approaches (if any) and should we include a way to disable loading.env
files completely in this library?