-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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]: jest isolation conflicts with better-sqlite3 native modules #15024
Labels
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. |
This issue is still relevant, please have a look... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version
29.7.0
Steps to reproduce
Node modules like better-sqlite3 use native modules. Those native modules can create JavaScript error objects. The error class is set to the native module via:
https://github.com/WiseLibs/better-sqlite3/blob/67d69e5b3dc67539d42a2b3a06492246ff0b68fa/lib/database.js#L59
The Jest isolation does not work on native modules, but only on the JS environment. That's why the first Test sets the Error Constructor. The second test uses the same native module, and therefore uses the error constructor of the first test.
As the global error changed from test1 to test2, errors thrown in test2 are checked against the global error of node env of test 1, which always fails.
I've added a minimal sample to reproduce the issue. It includes two identical tests which only pass once.
bs-jest-issue.zip
Expected behavior
All tests run successfully. Native modules shall also be isolated, so that each jest test run gets it's own native module, to be able to store the current global error object of the current node env.
Actual behavior
The second test fails, because the error object of second test node env is not an instance of global error object of the first test node env. The isolation between node envs of test 1 and test 2 are violated, as native modules are shared between the two node envs in Jest setup.
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: