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

fix(jest-environment-node): make performance writable #13467

Merged
merged 2 commits into from
Oct 18, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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