nx
nx copied to clipboard
Unable to set VirtualConsole in jest via executing with @nx/jest
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
const nxPreset = require('@nx/jest/preset').default;
const jsdom = require('jsdom');
const virtualConsole = new jsdom.VirtualConsole();
virtualConsole.sendTo(console, { omitJSDOMErrors: true });
virtualConsole.on('jsdomError', error => {
if (error.type === 'css parsing') {
console.warn('Ignoring CSS error');
} else {
console.error(error);
}
});
module.exports = {
...nxPreset,
collectCoverage: true,
collectCoverageFrom: ['src/lib/**/*.ts', 'src/app/**/*.ts'],
coverageReporters: ['html-spa', 'lcov', 'text-summary'],
testEnvironmentOptions: {
virtualConsole: virtualConsole,
},
};
It does not make a difference, if i put the configuration into the project's test-setup.ts
.
Nx Report
npx nx report
> NX Falling back to ts-node for local typescript execution. This may be a little slower.
- To fix this, ensure @swc-node/register and @swc/core have been installed
> NX Report complete - copy this into the issue template
Node : 18.16.0
OS : win32-x64
npm : 9.5.1
nx : 16.10.0
@nx/js : 16.10.0
@nx/jest : 16.10.0
@nx/linter : 16.10.0
@nx/workspace : 16.10.0
@nx/angular : 16.10.0
@nx/cypress : 16.10.0
@nx/devkit : 16.10.0
@nx/esbuild : 16.10.0
@nx/eslint-plugin : 16.10.0
@nx/storybook : 16.10.0
@nrwl/tao : 16.10.0
@nx/web : 16.10.0
@nx/webpack : 16.10.0
typescript : 5.1.6
---------------------------------------
Community plugins:
@ngrx/effects : 16.3.0
@ngrx/entity : 16.3.0
@ngrx/schematics : 12.5.1
@ngrx/store : 16.3.0
@ngrx/store-devtools : 16.3.0
eslint-plugin-ngrx : 2.1.4
ng-mocks : 14.12.1
Failure Logs
No response
Package Manager Version
No response
Operating System
- [ ] macOS
- [ ] Linux
- [X] Windows
- [ ] Other (Please specify)
Additional Information
Tried different things and ended up with package.json
with overrides
to force the same jsdom lib all over the project (because of non-peer dependencies of jest-environment-jsdom
). But still no luck.
"overrides": {
"jsdom": "23.2.0"
},