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

[Bug]: Properties added onto globalThis not accessible in getOwnPropertySymbols starting at Node 18 #13696

Closed
dubzzz opened this issue Dec 26, 2022 · 2 comments

Comments

@dubzzz
Copy link
Contributor

dubzzz commented Dec 26, 2022

Version

29.3.1

Steps to reproduce

test('has toto', () => {
  const totoSymbol = Symbol.for('toto');
  Object.defineProperty(globalThis, totoSymbol, {
    enumerable: true,
    writable: true,
    value: 4,
    configurable: true,
  });
  expect(Object.getOwnPropertySymbols(globalThis).includes(totoSymbol)).toBe(true); // works with node 14, 16 and fails with node 18
});

Expected behavior

The test should pass in both Node 14, Node 16 and Node 18. Actually I initially though the issue came from Node 18 itself but after manual trials, I found this reduced cases highlighted the issue and it passes in Node 18 without Jest and fails as soon as I add Jest.

Actual behavior

Fails on Node 18 (not expected). Passes on Node <18.

Additional context

I detected this issue while working on dubzzz/fast-check#3511. Actually everything went well until Node 18 and suddenly it broke. While investigating I got surprised by the fact that adding new properties to globalThis turns into nothing being added into getOwnPropertySymbols. So I digged a little bit more and arrived on this smaller case in which we can see that keys added to globalThis are not accessible in getOwnPropertySymbols starting at Node 18 with Jest while they are when running Node 18 alone or Node 16 with Jest.

The same test with Node test runner only passes in Node 18:

const test = require('node:test');
const assert = require('assert');

test('has toto', () => {
  const totoSymbol = Symbol.for('toto');
  Object.defineProperty(globalThis, totoSymbol, {
    enumerable: true,
    writable: true,
    value: 4,
    configurable: true,
  });
  assert(Object.getOwnPropertySymbols(globalThis).includes(totoSymbol));
});

Environment

System:
    OS: Linux 5.4 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (2) x64 Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
  Binaries:
    Node: 16.19.0 - /usr/local/nvs/node/16.19.0/x64/bin/node
    Yarn: 3.3.1 - /usr/bin/yarn
    npm: 8.19.3 - /usr/local/nvs/node/16.19.0/x64/bin/npm
@dubzzz dubzzz changed the title [Bug]: [Bug]: Properties added onto globalThis not accessible in getOwnPropertySymbols starting at Node 18 Dec 26, 2022
@dubzzz
Copy link
Contributor Author

dubzzz commented Dec 26, 2022

Duplicates for #13338

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant