You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
npm i
npm t
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.
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: