Closed cluxig closed 1 month ago
Thanks for reporting this!
Could you please provide a repo where the issue can be reproduced?
I only manage to reproduce the issue when there are multiple versions of jsdom
resolved in the workspace. If I override the jsdom
version like you did:
"overrides": {
"jsdom": "23.2.0"
},
The issue goes away for me. Also, if I don't override the jsdom
version, I get the same runtime error running the tests with the @nx/jest:jest
executor or with the Jest CLI directly:
npx nx test app1
> nx run app1:test
FAIL app1 apps/app1/src/app/app.component.spec.ts
● Test suite failed to run
TypeError: virtualConsole must be an instance of VirtualConsole
at transformOptions (../../node_modules/jest-environment-jsdom/node_modules/jsdom/lib/api.js:259:11)
...
node_modules/.bin/jest -c apps/app1/jest.config.ts
FAIL app1 apps/app1/src/app/app.component.spec.ts
● Test suite failed to run
TypeError: virtualConsole must be an instance of VirtualConsole
at transformOptions (../../node_modules/jest-environment-jsdom/node_modules/jsdom/lib/api.js:259:11)
...
For reference, the steps I took to reproduce it (based on the provided info) are:
jest.preset.js
file content with the one you providedjsdom
versionWith that, I can successfully run the tests using the test
target with the @nx/jest:jest
executor. There's no runtime error like the one you mentioned.
Also, note that trying to override the VirtualConsole
like you're doing won't work with Jest. The jsdom
environment doesn't use it and will always create a new instance of VirtualConsole
: https://github.com/jestjs/jest/blob/v29.0.0/packages/jest-environment-jsdom/src/index.ts#L41.
See https://github.com/nrwl/nx/issues/21846#issuecomment-2104580279 for reference on how to stub out console.*
methods.
This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
Setting up the VirtualConsole (to track and omit CSS parsing errors) leads to runtime error in case of execution via @nx/jest executor:
TypeError: virtualConsole must be an instance of VirtualConsole at transformOptions (../../../node_modules/jsdom/lib/api.js:260:11)
Running it with plain CLI mode:
node node_modules/jest/bin/jest.js ...
it works.Expected Behavior
Tests should run with this configuration, where as the
VirtualConsole
is replaced accordingly.GitHub Repo
No response
Steps to Reproduce
I just configed it like this in global
jest.preset.js
It does not make a difference, if i put the configuration into the project's
test-setup.ts
.Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
Tried different things and ended up with
package.json
withoverrides
to force the same jsdom lib all over the project (because of non-peer dependencies ofjest-environment-jsdom
). But still no luck.