Skip to content

Commit

Permalink
fix(jest-environment-node): make performance writable (jestjs#13467)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 18, 2022
1 parent c53bdbc commit e61ea77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@

### Fixes

- `[jest-environment-node]` make `globalThis.performance` writable for Node 19 and fake timers ([#13467](https://github.com/facebook/jest/pull/13467))

### Chore & Maintenance

### Performance
Expand Down
14 changes: 8 additions & 6 deletions packages/jest-config/src/__tests__/normalize.test.ts
Expand Up @@ -1082,6 +1082,10 @@ describe('preset', () => {
jest.requireActual('./jest-preset.json'),
);

const errorMessage = semver.satisfies(process.versions.node, '<19.0.0')
? /Unexpected token } in JSON at position (104|110)[\s\S]* at /
: 'SyntaxError: Expected double-quoted property name in JSON at position 104';

await expect(
normalize(
{
Expand All @@ -1090,9 +1094,7 @@ describe('preset', () => {
},
{} as Config.Argv,
),
).rejects.toThrow(
/Unexpected token } in JSON at position (104|110)[\s\S]* at /,
);
).rejects.toThrow(errorMessage);
});

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

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

await expect(
normalize(
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-environment-node/src/index.ts
Expand Up @@ -90,7 +90,10 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
configurable: descriptor.configurable,
enumerable: descriptor.enumerable,
value: val,
writable: descriptor.writable,
writable:
descriptor.writable === true ||
// Node 19 makes performance non-readable. This is probably not the correct solution.
nodeGlobalsKey === 'performance',
});
return val;
},
Expand Down

0 comments on commit e61ea77

Please sign in to comment.