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
I am using vitest (node environment) for testing in an App that I am writing.
Whenever I was executing tests (node 22), I got the use setEngine before getEngine error.
After some digging, I found out that the check performed here fails when running code with vitest.
Specifically, the "webcrypto" in crypto check returns false.
I am not really sure why this happens. I tried to research potential differences between the way vitest handles these global modules, but did not find anything that would point towards differences in the global crypto module.
The current workaround is to use setEngine explicitly in a beforeAll block.
import{webcrypto}from"crypto";
...
beforeAll(()=>{// This is required for some reason, as the automatic check for the engine fails when running inside vitestconstname="NodeJS ^15";constnodeCrypto=webcryptoasCrypto;setEngine(name,newCryptoEngine({ name,crypto: nodeCrypto}));});
I am not sure if this is a vitest issue, or something that should be addressed in the env check performed by pki.js. But maybe this is something that can be documented somewhere
The text was updated successfully, but these errors were encountered:
I am using vitest (node environment) for testing in an App that I am writing.
Whenever I was executing tests (node 22), I got the
use setEngine before getEngine
error.After some digging, I found out that the check performed here fails when running code with vitest.
Specifically, the
"webcrypto" in crypto
check returns false.I am not really sure why this happens. I tried to research potential differences between the way vitest handles these global modules, but did not find anything that would point towards differences in the global
crypto
module.The current workaround is to use
setEngine
explicitly in abeforeAll
block.I am not sure if this is a vitest issue, or something that should be addressed in the env check performed by pki.js. But maybe this is something that can be documented somewhere
The text was updated successfully, but these errors were encountered: