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

Support deletion in process.env too #5466

Merged
merged 1 commit into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

### Features

* `[jest-util]` Add deletion to `process.env` as well
([#5466](https://github.com/facebook/jest/pull/5466))
* `[jest-util]` Add case-insensitive getters/setters to `process.env`
Copy link
Member

Choose a reason for hiding this comment

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

❤️

([#5465](https://github.com/facebook/jest/pull/5465))
* `[jest-mock]` Add util methods to create async functions.
([#5318](https://github.com/facebook/jest/pull/5318))

### Fixes

* `[jest-cli]` Hide interactive mode if there are no failed snapshot tests ([#5450](https://github.com/facebook/jest/pull/5450))
* `[jest-cli]` Add trailing slash when checking root folder
([#5464](https://github.com/facebook/jest/pull/5464))
* `[jest-cli]` Hide interactive mode if there are no failed snapshot tests
([#5450](https://github.com/facebook/jest/pull/5450))
* `[babel-jest]` Remove retainLines from babel-jest
([#5326](https://github.com/facebook/jest/pull/5439))
* `[jest-cli]` Glob patterns ignore non-`require`-able files (e.g. `README.md`)
Expand Down
18 changes: 18 additions & 0 deletions packages/jest-util/src/__tests__/create_process_object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ it('checks that process.env works as expected on Linux platforms', () => {

expect(fake.PROP_ADDED).toBe('new!');
expect(process.env.PROP_ADDED).toBe(undefined);

// You can delete properties, but they are case sensitive!
fake.prop = 'foo';
fake.PROP = 'bar';

expect(fake.prop).toBe('foo');
expect(fake.PROP).toBe('bar');

delete fake.PROP;

expect(fake.prop).toBe('foo');
expect(fake.PROP).toBe(undefined);
});

it('checks that process.env works as expected in Windows platforms', () => {
Expand All @@ -73,4 +85,10 @@ it('checks that process.env works as expected in Windows platforms', () => {

expect(typeof fake.tostring).toBe('undefined');
expect(typeof fake.valueof).toBe('undefined');

// You can delete through case-insensitiveness too.
delete fake.prop_string;

expect(fake.hasOwnProperty('PROP_STRING')).toBe(false);
expect(fake.hasOwnProperty('PROP_string')).toBe(false);
});
22 changes: 21 additions & 1 deletion packages/jest-util/src/create_process_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,28 @@ function createProcessEnv() {
const lookup = {};

const proxy = new Proxy(real, {
deleteProperty(target, key) {
for (const name in real) {
if (real.hasOwnProperty(name)) {
if (typeof key === 'string' && process.platform === 'win32') {
if (name.toLowerCase() === key.toLowerCase()) {
delete real[name];
delete lookup[name.toLowerCase()];
}
} else {
if (key === name) {
delete real[name];
delete lookup[name];
}
}
}
}

return true;
},

get(target, key) {
if ((typeof key === 'string') && (process.platform === 'win32')) {
if (typeof key === 'string' && process.platform === 'win32') {
return lookup[key in proto ? key : key.toLowerCase()];
} else {
return real[key];
Expand Down