nx: jest-preset-angular v8 has breaking changes

Please make sure you have read the submission guidelines before posting an issue

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • I’m reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)

Expected Behavior

Running jest tests does not fail

Current Behavior

Jest tests fail with the following error message:

Module jest-preset-angular/AngularSnapshotSerializer.js in the snapshotSerializers option was not found.

Steps to Reproduce

  1. update jest-preset-angular to 8.0.0
  2. run jest tests

Other

I looked into jest-preset-angular and it seems that they introduced a build folder with v8 thus the path is not correct anymore.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 18
  • Comments: 19 (2 by maintainers)

Commits related to this issue

Most upvoted comments

in your module, you may have the file jest.config.js with the following content.

module.exports = {
    name: 'name',
    preset: '../../jest.config.js',
    coverageDirectory: '../../coverage/libs/common',
    snapshotSerializers: [
        'jest-preset-angular/AngularSnapshotSerializer.js',
        'jest-preset-angular/HTMLCommentSerializer.js'
    ],
    setupFilesAfterEnv: ["./src/test-setup.ts"]
};

comment or remove the member “snapshotSerializers”. It is not needed. Worked for me, The resulting should be

module.exports = {
    name: 'name',
    preset: '../../jest.config.js',
    coverageDirectory: '../../coverage/libs/common',
   
    setupFilesAfterEnv: ["./src/test-setup.ts"]
};

@leon I managed to fix it by changing jest-preset-angular/AngularSnapshotSerializer.js to jest-preset-angular/build/AngularSnapshotSerializer.js and jest-preset-angular/HTMLCommentSerializer.js to jest-preset-angular/build/HTMLCommentSerializer.js.

Since in latest version of jest they have been moved under /build directory. REF: https://github.com/thymikee/jest-preset-angular/releases/tag/v8.0.0

Any updates on this? I updated my nx repo to jest 25 and now it’s complaining about jest-preset-angular not supporting jest 25

What is needed to get this merged into the next release?

Nice, I feel like upgrade to jest-angular-preset will help with problems I have. Cant wait until this is there

How does it look guys? Any plans?

i literally checked node_modules/jest-preset-angular/build folder and the files, InlineFilesTransformer, StripStylesTransformer, HTMLCommentSerializer and AngularSnapshotSerializer are nowhere to be foung. any idea what’s causing this issue? I’m running my test on my Angular 10 app. here are some of my project details:

    "@angular-builders/jest": "^12.1.0",
    "@types/jest": "^26.0.24",
    "jest": "^27.0.6",
    "jest-preset-angular": "^9.0.4",
}```
node version: 12.22.1
most of my configurations are based on this documentation: https://www.npmjs.com/package/jest-preset-angular/v/9.0.0-next.1

node_modules\@nrwl\jest\src\builders\jest\jest.impl.js If you update astTransformers from: ['jest-preset-angular/InlineHtmlStripStylesTransformer'] TO ['jest-preset-angular/build/InlineFilesTransformer', 'jest-preset-angular/build/StripStylesTransformer'] The File not found error is gone, but there is a new problem:

Uncaught (in promise): Failed to load app.component.html plus few more.

It looks, NX is not compatible with the "jest-preset-angular": "8.0.0".

@ashokshetty1970 didn’t work for me.

File not found: jest-preset-angular/InlineHtmlStripStylesTransformer (resolved as: D:\dev\web\apps\aha\jest-preset-angular\InlineHtmlStripStylesTransformer)

      at ConfigSet.resolvePath (../../node_modules/ts-jest/dist/config/config-set.js:712:19)
      at ../../node_modules/ts-jest/dist/config/config-set.js:225:98
          at Array.map (<anonymous>)
      at ConfigSet.get (../../node_modules/ts-jest/dist/config/config-set.js:225:64)
      at ConfigSet.tsJest (../../node_modules/ts-jest/dist/util/memoize.js:43:24)
      at ConfigSet.get (../../node_modules/ts-jest/dist/config/config-set.js:297:41)
      at ConfigSet.versions (../../node_modules/ts-jest/dist/util/memoize.js:43:24)
      at ConfigSet.get (../../node_modules/ts-jest/dist/config/config-set.js:583:32)
      at ConfigSet.jsonValue (../../node_modules/ts-jest/dist/util/memoize.js:43:24)
      at ConfigSet.get [as cacheKey] (../../node_modules/ts-jest/dist/config/config-set.js:598:25)