test(opentelemetry-configuration): simplify management of environment variables#6004
Merged
maryliag merged 1 commit intoopen-telemetry:mainfrom Oct 11, 2025
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6004 +/- ##
=======================================
Coverage 95.22% 95.22%
=======================================
Files 311 311
Lines 8603 8603
Branches 1801 1801
=======================================
Hits 8192 8192
Misses 411 411 🚀 New features to boost your workflow:
|
maryliag
requested changes
Oct 10, 2025
Contributor
maryliag
left a comment
There was a problem hiding this comment.
Thanks for the improvement, it's a great idea so we don't forget any variables 😄
I added a suggestion, because we might evolve those tests and need some pre determined variables. This way you save the original values (doesn't need to be inside a before), and restore after every test
Comment on lines
+356
to
+362
| before(function () { | ||
| process.env = {}; | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| process.env = {}; | ||
| }); |
Contributor
There was a problem hiding this comment.
Suggested change
| before(function () { | |
| process.env = {}; | |
| }); | |
| afterEach(function () { | |
| process.env = {}; | |
| }); | |
| const _origEnvVariables = process.env | |
| afterEach(function () { | |
| process.env = _origEnvVariables; | |
| }); |
… variables The ConfigProvider tests were deleting a number of environment variables after every test, and this logic was duplicated in a few places. This is a bit error prone. The tests seem to pass with a clean process.env provided to each test, and Mocha's afterEach() hook is inherited, so the logic can be simplified a good bit while maintaining semantics.
Contributor
Author
|
I've made the suggested changes, with a few notes:
|
maryliag
reviewed
Oct 11, 2025
maryliag
approved these changes
Oct 11, 2025
Contributor
cjihrig
added a commit
to cjihrig/opentelemetry-js
that referenced
this pull request
Oct 13, 2025
PR open-telemetry#6004 simplified the environment restoration logic after each test. However, process.env is a special object that converts all of its values to strings automatically. That behavior was lost in open-telemetry#6004, which could potentially lead to surprising behavior. This commit changes the process.env restoration logic to maintain the original special object.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which problem is this PR solving?
The
ConfigProvidertests were deleting a number of environment variables after every test, and this logic was duplicated in a few places. This is a bit error prone.Fixes # N/A
Short description of the changes
The tests seem to pass with a clean
process.envprovided to each test, and Mocha'safterEach()hook is inherited, so the logic can be simplified a good bit while maintaining semantics.Type of change
How Has This Been Tested?
Checklist: