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]: jest isolation conflicts with better-sqlite3 native modules #15024

Open
oklemenz2 opened this issue Apr 10, 2024 · 0 comments
Open

[Bug]: jest isolation conflicts with better-sqlite3 native modules #15024

oklemenz2 opened this issue Apr 10, 2024 · 0 comments

Comments

@oklemenz2
Copy link

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

addon.setErrorConstructor(SqliteError);

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.

Additional context

No response

Environment

System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M3 Pro
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant