After upgrading Angular version of my app to 12, I decided to upgrade other libraries like jest
as well:
"jest": "^27.4.6", (from 24.1.0)
"jest-canvas-mock": "^2.2.0",
"jest-junit": "^13.0.0", (from ^9.0.0)
"jest-preset-angular": "11.0.1",
"jest-resolve": "^27.4.6", (added this one)
"ts-jest": "27.1.2" (from 24.0.0)
This is how my jest.config.js
looks like:
const jestPresetAngularSerializers = require('jest-preset-angular/build/serializers');
module.exports = {
name: 'sam-web',
preset: '../../jest.config.js',
coverageDirectory: '../../coverage/apps/sam-web',
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: 'reports',
outputName: 'junit-sam-web.xml',
},
],
],
snapshotSerializers: [jestPresetAngularSerializers, 'jest-preset-angular/build/serializers/html-comment'],
transformIgnorePatterns: ['/node_modules/(?!lodash-es).+\\.js$'],
collectCoverageFrom: ['src/app/**/*.ts', '!src/app/**/*.module.ts'],
cacheDirectory: '../../.jest-cache',
};
I'm also using import 'jest-preset-angular/setup-jest';
instead of import 'jest-preset-angular';
This is my app things and their versions:
Angular CLI: 12.2.14
Node: 14.15.0
Package Manager: yarn 1.22.17
OS: win32 x64
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.801.1
@angular-devkit/build-angular 12.2.14
@angular-devkit/core 8.1.1
@angular-devkit/schematics 8.1.1
@angular/cdk 12.2.13
@angular/cli 12.2.14
@angular/material 12.2.13
@angular/material-moment-adapter 12.2.13
@schematics/angular 12.2.14
rxjs 7.4.0
typescript 4.3.5
And this is the error what I get when I'm trying to run the tests:
An unhandled exception occurred: Package subpath './build/defaultResolver' is not defined by "exports" in C:\Users\Dominik\Desktop\Work\web_gui\node_modules\jest-resolve\package.json
See "C:\Users\Dominik\AppData\Local\Temp\ng-9Gl1h1\angular-errors.log" for further details.
error Command failed with exit code 127.
I have tried to remove node_module
and yarn.lock
, clean cache, install everything one more time but every time is the same. I found a similar issue on some page where the solution was to run npm update
but similar command for yarn doesn't help me. Maybe someone of you can help me?