-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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]: Object.getOwnPropertySymbols() does not work against global instance with jest+node18 #13338
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
hi Jest team, is it possible for you to take a look of this issue? thank you so much! |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
hi Jest team, is it possible for you to take a look of this issue? thank you so much! |
any chance you could take a look, jest team? Thank you so much! |
I just reported the very same issue on #13696. Definitely something strange going on 🤔 I tried to investigate a bit what can go wrong but so far no clue at all |
If it can help, it passed on some legacy versions of Node 18 and started to fail at Node 18.2.0 (it passed on 18.1.0). On CodeSpace environments all versions of Jest had the issue on my end (I tested from 24 to 29). So it seems the bug appeared due to something in this release of Node: https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V18.md#18.2.0 |
Probably related to the fact that this code started to fail at node 18.2.0: const assert = require('assert');
const vm = require('vm');
const global = vm.runInContext('this', vm.createContext());
const totoSymbol = Symbol.for('toto');
Object.defineProperty(global, totoSymbol, {
enumerable: true,
writable: true,
value: 4,
configurable: true,
});
assert(Object.getOwnPropertySymbols(global).includes(totoSymbol)); Cc @SimenB: I opened this issue on node side: nodejs/node#45983. From my understanding of the code and my manual tests I suspect that the issue comes from the piece of code in https://github.com/facebook/jest/blob/fb2de8a10f8e808b080af67aa771f67b5ea537ce/packages/jest-environment-node/src/index.ts#L72. But issue seems to be on node side if I get well how vm work 🤔 |
The current code performs a work-around required as soon as the the user runs Jest with node 18.2.0 or above (whatever the version of Jest). As the bug does not seem to be inherent to the way fast-check plugs itself into Jest configuration (while it's hacky), we for the moment deactivate the new "timeout handled by fast-check itsefl" in these cases. By the way, it's important to note that bug can also exist if the user does not use default runners, so until we find a more reliable way to access the timeout, we will have kill-switch caces like this one. Hopefully less frequent than the node 18.2.0 one that I hope will be fixed. Related to ticket jestjs/jest#13338
* 🐛(jest) Support failure to get timeout out of Jest The current code performs a work-around required as soon as the the user runs Jest with node 18.2.0 or above (whatever the version of Jest). As the bug does not seem to be inherent to the way fast-check plugs itself into Jest configuration (while it's hacky), we for the moment deactivate the new "timeout handled by fast-check itsefl" in these cases. By the way, it's important to note that bug can also exist if the user does not use default runners, so until we find a more reliable way to access the timeout, we will have kill-switch caces like this one. Hopefully less frequent than the node 18.2.0 one that I hope will be fixed. Related to ticket jestjs/jest#13338 * versions * Comment some worker-based and timeout related tests for now
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Actually while the issue is probably not on Jest's side, the issue is still there as vm based code is somehow not behaving the same way following recent releases of node. |
A fix should land soon in node 19. If no issue occurs, it will possibly be backported in node 18. More at nodejs/node#46458 |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
@SimenB The fix number 1 has been merged on node side. It should be fixed with the next release of node 19. Node 18 still pending at least 2 more weeks after 19 (LTS). I also attempted another fix on node side as there is another pending bug on that part of their code. |
Sweet, thanks for tackling this @dubzzz! Do you think we can close the issue here as it's an upstream bug (that's being fixed)? |
it's great that you've fixed the issue with still the fact that the same code works in node.js only but fails in Jest+node suggests that it's not likely an issue caused by node.js only. |
It works but not when executed within |
So using Reference: #2549 (comment) |
As jest-light-runner does not rely on vm it might work 🤔 I ran this code snippet (jest-free) against node versions 18.x and 19.x and confirmed the issue was linked to vm: // Arrange
const assert = require("assert");
const vm = require("vm");
const global = vm.runInContext("this", vm.createContext());
const totoSymbol = Symbol.for("toto");
const titiSymbol = Symbol.for("titi");
// Act
Object.defineProperty(global, totoSymbol, {
enumerable: true,
writable: true,
value: 4,
configurable: true,
});
global[titiSymbol] = 4;
// Assert
assert(Object.getOwnPropertySymbols(global).includes(totoSymbol)); // fails with: >=18.2.0 <18.16.0, >=19.0.0 <19.7.0
assert(Object.getOwnPropertySymbols(global).includes(titiSymbol)); // fails with: 18.x, 19.x Both assertions pass well in node 17.x! Version 18.x of node corresponds to a bump of v8. It seems that the bumped caused some issues within vm (attempts to patch them have been done on 18.2.0, then 18.16.0, then not yet released 18.17.0 but there are still others). |
This PR is a follow-up of nodejs#46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19.
This PR is a follow-up of nodejs#46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19. I confirmed it would fix node 19 by cherry-picking the commit on v19.x-staging and launching `make -j4 jstest` on it.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
I've been using Object.defineProperty as a workaround so far, it works but hopefully we can have a better solution to solve it perfectly. |
This PR is a follow-up of #46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19. I confirmed it would fix node 19 by cherry-picking the commit on v19.x-staging and launching `make -j4 jstest` on it. PR-URL: #47572 Reviewed-By: James M Snell <[email protected]>
This PR is a follow-up of #46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19. I confirmed it would fix node 19 by cherry-picking the commit on v19.x-staging and launching `make -j4 jstest` on it. PR-URL: #47572 Reviewed-By: James M Snell <[email protected]>
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
not sure the issue is from jest or node |
The issue is definitely from node. But so far I'm waiting for the fix to be back-ported in node 18 and maybe 19 too. |
Hope it will be totally fixed in node 18, now that the last fix landed. Just landed: nodejs/node#46615 (comment) |
This PR is a follow-up of #46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19. I confirmed it would fix node 19 by cherry-picking the commit on v19.x-staging and launching `make -j4 jstest` on it. PR-URL: #47572 Reviewed-By: James M Snell <[email protected]>
This PR is a follow-up of nodejs#46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19. I confirmed it would fix node 19 by cherry-picking the commit on v19.x-staging and launching `make -j4 jstest` on it. PR-URL: nodejs#47572 Reviewed-By: James M Snell <[email protected]>
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Fails on Node v18.16, but works as expected on Node v18.17. @dubzzz, you fixed it! Thanks. |
This PR is a follow-up of nodejs#46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19. I confirmed it would fix node 19 by cherry-picking the commit on v19.x-staging and launching `make -j4 jstest` on it. PR-URL: nodejs#47572 Reviewed-By: James M Snell <[email protected]>
This PR is a follow-up of nodejs#46615. When bumping V8 for node 18, various bugs appeared around vm. Some have been fixed along the flow, but there is at least one remaining and described at: jestjs/jest#13338. The current fix does nothing on node 20: the new bump of v8 done for node 20 seems to fix it. But it would fix the problem in both node 18 and node 19. I confirmed it would fix node 19 by cherry-picking the commit on v19.x-staging and launching `make -j4 jstest` on it. PR-URL: nodejs#47572 Reviewed-By: James M Snell <[email protected]>
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. |
Version
27/28/29
Steps to reproduce
run the following test case:
Expected behavior
the test should pass
Actual behavior
the test passes with Node JS <16, fails starting with Node JS 18
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: