Skip to content
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

fix: support undefined process #10

Merged
merged 4 commits into from
Aug 5, 2024
Merged

Conversation

cazala
Copy link
Member

@cazala cazala commented Aug 5, 2024

There are builds where process is not defined and is making the library to throw on runtime with the following error:

TypeError: Cannot read properties of undefined (reading 'env')

      120 |  */
      121 | export function getEnv(
    > 122 |   systemEnvVariables: EnvironmentVariables = process.env

This PR adds a test that reproduces the issue, and then applies a fix for it.

@cazala cazala force-pushed the fix/support-undefined-process branch from e5f8142 to 8a4a81f Compare August 5, 2024 14:14
it('should return Env.PRODUCTION', () => {
process = undefined as any
expect(getEnv()).toBe(Env.PRODUCTION)
})
Copy link
Member Author

Choose a reason for hiding this comment

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

This tests reproduces the issue

typeof process === 'object' &&
typeof process.env === 'object'
? process.env
: systemEnvVariables
Copy link
Member Author

Choose a reason for hiding this comment

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

This should keep the same behaviour for projects relying on the process.env and passing no param to the getEnv helper.

If no param is sent to the helper, and process.env exists, it uses that as the envVars, otherwise if something custom is passed as param, it will use the custom param.

All the existing tests are working without having to make any changes on the tests themselves.

).toThrow()
})
})
})
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is not related to this PR, it was just missing and causing the coverage to be less than 100% so I added it.

@@ -269,7 +309,7 @@ describe('when getting env', () => {
})
})

describe('and host is "market.decentraland.org"', () => {
describe('and host is "builder.decentraland.org"', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just a typo in the test name

@cazala cazala merged commit c869aa9 into master Aug 5, 2024
2 checks passed
@cazala cazala deleted the fix/support-undefined-process branch August 5, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants