Open blakewest opened 3 months ago
This will need some investigation to solve, a few initial thoughts / pointers:
Writing a library that supports both node and the browser is complex and prone to these issues unfortunately, add in WASM and it gets worse. One day we will all have moved to ESM and the tooling will be perfect.
I'm very keen to find the fix for this as Jest is so widely used.
In vscode I can add the following to settings:
"jest.nodeEnv": {
"NODE_OPTIONS": "--experimental-vm-modules"
}
However now I get:
TypeError: The URL must be of scheme file
at open (node:internal/fs/promises:638:10)
at Module.readFile (node:internal/fs/promises:1254:20)
at ri (/home/firelizzard/src/athletifi/website/node_modules/@electric-sql/pglite/src/utils.ts:73:16)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
presumably in the code that's using import.meta
to locate the WASM binaries.
Having PGLite running in Jest test suites will be wonderful.
The import.meta.url
error was caused in part by @jest-environment: jsdom
. The bundled version of pglite attempts to guess at what import.meta.url
should return, and if document
exists it assumes it's being run in a browser and returns http://localhost/main.js
. By setting the Jest environment to node I was able to get past this. However, I ran into another issue:
Because the explicit .js
, Jest throws an error when release/postgres
is not an ESM module. I fixed this simply by removing .js
. I opened #423 to make this change.
Hi, I was trying to introduce PG into my codebase, and needed a way to run my tests against it. I'm using Prisma, and saw this and thought the adapter looked great. However, it seems there's some compatibility issue with Jest. If I try to import it, I get an error that breaks everything. See below for an example stack trace.
In my investigation, I saw that 1.) Jest seems to have had a similar issue last year with Prettier V3. They said it would be fixed in Jest 30, but I installed the latest (alpha) release of Jest 30, and the same error occurs. , and 2.) If I removed the PG lite adapter, the tests work fine.
I'm not actually 100% if this is a Jest issue or a ElectricSQL issue, but I thought I'd raise it.
Has anyone else been able to use this PG-lite package with Jest 29?