-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
SqliteErrors have wrong constructor in Jest environment #162
Comments
Jest causes all sorts of problems with native addons, because they mess with things like v8 contexts and other wizardry that can easily cause bugs with C++ code that would otherwise be perfectly valid. I would not consider this an issue with |
For clarity, the reason Jest causes an issue is because it loads the |
Thanks for the info. Let me make sure I’m understanding correctly the
Which did you mean? If case (1), then this definitely sounds like a problem with Jest. In |
Case 2 is what I meant to convey. You see, Case 1 is not even true for Node.js core. Although Node.js exposes APIs for dealing with V8 contexts, objects provided by Node.js itself do no cooperate with V8 contexts besides the main context. Therefore I think it's acceptable for In all practical ways,
|
I'm having the issues described in #195 as well. I understand that this may not be solvable, but could you elaborate why even when using the I worked around the problem by setting The code in question: https://github.com/apifytech/apify-storage-local-js/tree/request-queues Thanks. |
@mnmkng I could be wrong, but I believe that even with |
@JoshuaWise Is there any way around this? I need to integrate with a library that uses Jest for its tests and there's nothing I can do about it (at least not in a foreseeable future). I switched to I'd be happy to contribute. I'm not really capable of changing anything on the native module side, but maybe the JS part could be refactored to overcome the problem? |
Probably the best way around this is to never check |
@JoshuaWise Oh, sorry, I don't actually have an issue with the error instance but rather the one from the related issue I linked above: #195. My pragma calls fail: |
I don't know why it did not occur to me before, but the fix was actually quite easy. Replaced the pragma calls with this.db.exec('PRAGMA journal_mode = WAL');
this.db.exec('PRAGMA foreign_keys = ON'); |
This is fixed in v7.0.0. |
Summary: Notably, this includes a Jest compatibility improvement: <WiseLibs/better-sqlite3#162 (comment)> Test Plan: Existing unit tests pass. wchargin-branch: better-sqlite3-v7.0.0
Summary: Notably, this includes a Jest compatibility improvement: <WiseLibs/better-sqlite3#162 (comment)> Test Plan: Existing unit tests pass. wchargin-branch: better-sqlite3-v7.0.0
Summary: Notably, this includes a Jest compatibility improvement: <WiseLibs/better-sqlite3#162 (comment)> Test Plan: Existing unit tests pass. wchargin-branch: better-sqlite3-v7.0.0
An error thrown from
Statement#run
can, under some invocations, nothave constructor
SqliteError
. The behavior is as expected under Node,but fails when run in a Jest test case.
Here is a repro with two files (
package.json
andtest.js
):package.json
test.js
When run with
node ./test.js
, this prints:When run with
node ./node_modules/.bin/jest ./test.js
, this prints:Using
require("better-sqlite3/lib/sqlite-error")
instead ofDatabase.SqliteError
results in the same behavior in both cases.I suspect that this has something to do with the fact that the errors in
question are instantiated from a native addon—
—but I certainly don’t know exactly what’s going on.
This is Node v9.7.1 (currently on macOS 10.13.3).
The text was updated successfully, but these errors were encountered: