Skip to content

Commit e61ea77

Browse files
authoredOct 18, 2022
fix(jest-environment-node): make performance writable (#13467)
1 parent c53bdbc commit e61ea77

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Fixes
88

9+
- `[jest-environment-node]` make `globalThis.performance` writable for Node 19 and fake timers ([#13467](https://github.com/facebook/jest/pull/13467))
10+
911
### Chore & Maintenance
1012

1113
### Performance

‎packages/jest-config/src/__tests__/normalize.test.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,10 @@ describe('preset', () => {
10821082
jest.requireActual('./jest-preset.json'),
10831083
);
10841084

1085+
const errorMessage = semver.satisfies(process.versions.node, '<19.0.0')
1086+
? /Unexpected token } in JSON at position (104|110)[\s\S]* at /
1087+
: 'SyntaxError: Expected double-quoted property name in JSON at position 104';
1088+
10851089
await expect(
10861090
normalize(
10871091
{
@@ -1090,9 +1094,7 @@ describe('preset', () => {
10901094
},
10911095
{} as Config.Argv,
10921096
),
1093-
).rejects.toThrow(
1094-
/Unexpected token } in JSON at position (104|110)[\s\S]* at /,
1095-
);
1097+
).rejects.toThrow(errorMessage);
10961098
});
10971099

10981100
test('throws when preset evaluation throws type error', async () => {
@@ -1105,9 +1107,9 @@ describe('preset', () => {
11051107
{virtual: true},
11061108
);
11071109

1108-
const errorMessage = semver.satisfies(process.versions.node, '>=16.9.1')
1109-
? "TypeError: Cannot read properties of undefined (reading 'call')"
1110-
: /TypeError: Cannot read property 'call' of undefined[\s\S]* at /;
1110+
const errorMessage = semver.satisfies(process.versions.node, '<16.9.1')
1111+
? /TypeError: Cannot read property 'call' of undefined[\s\S]* at /
1112+
: "TypeError: Cannot read properties of undefined (reading 'call')";
11111113

11121114
await expect(
11131115
normalize(

‎packages/jest-environment-node/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
9090
configurable: descriptor.configurable,
9191
enumerable: descriptor.enumerable,
9292
value: val,
93-
writable: descriptor.writable,
93+
writable:
94+
descriptor.writable === true ||
95+
// Node 19 makes performance non-readable. This is probably not the correct solution.
96+
nodeGlobalsKey === 'performance',
9497
});
9598
return val;
9699
},

0 commit comments

Comments
 (0)
Please sign in to comment.