Skip to content

Make "process.env" case insensitive in Windows#5465

Merged
mjesun merged 1 commit into
jestjs:masterfrom
mjesun:fix-process-env
Feb 5, 2018
Merged

Make "process.env" case insensitive in Windows#5465
mjesun merged 1 commit into
jestjs:masterfrom
mjesun:fix-process-env

Conversation

@mjesun

@mjesun mjesun commented Feb 5, 2018

Copy link
Copy Markdown
Contributor

When we fully sandboxed process, we removed the ability of the env object to perform case-insensitive matches when used in Windows. The proposed solution uses a Proxy instance over a shared prototype object, and emulates the behavior by using a secondary lookup object.

Another behavior that process.env has is that all values are always stored as strings, regardless of their value (numbers, booleans...). This behavior has also been mimicked in the new implementation.

Tests were also added to ensure that both behaviors are well respected in different platforms. Fixes #5322.

const BLACKLIST = new Set(['mainModule', '_events']);
const BLACKLIST = new Set(['env', 'mainModule', '_events']);

function createProcessEnv() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it will be helpful to point to the process.env docs somewhere here (e.g. I wasn't aware of this, TIL): https://nodejs.org/api/process.html#process_process_env

@thymikee

thymikee commented Feb 5, 2018

Copy link
Copy Markdown
Contributor

CI failures are completely unrelated, what the heck CircleCI?

@mjesun

mjesun commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

It's trying to use what it seems to be a corrupted cache layer ("Found a cache from build 13420 at dependencies-pull/5465-ogGKRVLu81JjC2jiSjH1QgvfyezJ8TPaAaAJSg_G0Vk=").

@mjesun

mjesun commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

I'm going to merge this. CircleCI looks corrupted, but tests passed in AppVeyor.

@mjesun mjesun merged commit ae3d55e into jestjs:master Feb 5, 2018
@mjesun mjesun deleted the fix-process-env branch February 5, 2018 14:54
expect(require('process') === process).toBe(true);
});

it('checks that process.env works as expected on Linux platforms', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you add a test for delete process.env.PROP as well?

@SimenB

SimenB commented Feb 5, 2018

Copy link
Copy Markdown
Member

Change looks great 🙂

Missing changelog entry 😱

@mjesun

mjesun commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

@SimenB Good catch on the delete one! Maybe @janpieterz, who originally reported the issue can help us know whether deletion is also case-insensitive. Once I know I will implement that too 🙂

@SimenB

SimenB commented Feb 5, 2018

Copy link
Copy Markdown
Member

@mjesun It is case insensitive:

image

@mjesun

mjesun commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

What about delete process.env.foo? Does it delete FOO?

@SimenB

SimenB commented Feb 5, 2018

Copy link
Copy Markdown
Member

Yup.

image

@mjesun

mjesun commented Feb 5, 2018

Copy link
Copy Markdown
Contributor Author

Thanks! I will implement that behavior as well 🙂

@cpojer

cpojer commented Feb 5, 2018

Copy link
Copy Markdown
Member

And that is the story of how we started using Proxies in production… :D

@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running tests with jest seems to trigger a change in environment variables

5 participants