Skip to content

Commit 5229f35

Browse files
authored
Support deletion in process.env too (#5466)
1 parent d6781c3 commit 5229f35

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
### Features
44

5+
* `[jest-util]` Add deletion to `process.env` as well
6+
([#5466](https://github.com/facebook/jest/pull/5466))
7+
* `[jest-util]` Add case-insensitive getters/setters to `process.env`
8+
([#5465](https://github.com/facebook/jest/pull/5465))
59
* `[jest-mock]` Add util methods to create async functions.
610
([#5318](https://github.com/facebook/jest/pull/5318))
711

812
### Fixes
913

10-
* `[jest-cli]` Hide interactive mode if there are no failed snapshot tests ([#5450](https://github.com/facebook/jest/pull/5450))
14+
* `[jest-cli]` Add trailing slash when checking root folder
15+
([#5464](https://github.com/facebook/jest/pull/5464))
16+
* `[jest-cli]` Hide interactive mode if there are no failed snapshot tests
17+
([#5450](https://github.com/facebook/jest/pull/5450))
1118
* `[babel-jest]` Remove retainLines from babel-jest
1219
([#5326](https://github.com/facebook/jest/pull/5439))
1320
* `[jest-cli]` Glob patterns ignore non-`require`-able files (e.g. `README.md`)

packages/jest-util/src/__tests__/create_process_object.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ it('checks that process.env works as expected on Linux platforms', () => {
5454

5555
expect(fake.PROP_ADDED).toBe('new!');
5656
expect(process.env.PROP_ADDED).toBe(undefined);
57+
58+
// You can delete properties, but they are case sensitive!
59+
fake.prop = 'foo';
60+
fake.PROP = 'bar';
61+
62+
expect(fake.prop).toBe('foo');
63+
expect(fake.PROP).toBe('bar');
64+
65+
delete fake.PROP;
66+
67+
expect(fake.prop).toBe('foo');
68+
expect(fake.PROP).toBe(undefined);
5769
});
5870

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

7486
expect(typeof fake.tostring).toBe('undefined');
7587
expect(typeof fake.valueof).toBe('undefined');
88+
89+
// You can delete through case-insensitiveness too.
90+
delete fake.prop_string;
91+
92+
expect(fake.hasOwnProperty('PROP_STRING')).toBe(false);
93+
expect(fake.hasOwnProperty('PROP_string')).toBe(false);
7694
});

packages/jest-util/src/create_process_object.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,28 @@ function createProcessEnv() {
2323
const lookup = {};
2424

2525
const proxy = new Proxy(real, {
26+
deleteProperty(target, key) {
27+
for (const name in real) {
28+
if (real.hasOwnProperty(name)) {
29+
if (typeof key === 'string' && process.platform === 'win32') {
30+
if (name.toLowerCase() === key.toLowerCase()) {
31+
delete real[name];
32+
delete lookup[name.toLowerCase()];
33+
}
34+
} else {
35+
if (key === name) {
36+
delete real[name];
37+
delete lookup[name];
38+
}
39+
}
40+
}
41+
}
42+
43+
return true;
44+
},
45+
2646
get(target, key) {
27-
if ((typeof key === 'string') && (process.platform === 'win32')) {
47+
if (typeof key === 'string' && process.platform === 'win32') {
2848
return lookup[key in proto ? key : key.toLowerCase()];
2949
} else {
3050
return real[key];

0 commit comments

Comments
 (0)