Nx: Jest 24 and jest-preset-angular 7 changes

Created on 26 Jan 2019  路  10Comments  路  Source: nrwl/nx

After updating to latest Jest(24.0.0) and jest-angular-preset(7.0.0-alpha.2) which has some breaking changes:
https://github.com/thymikee/jest-preset-angular/blob/release/7/CHANGELOG.md

This is only showing warnings for now but the main problem is that it does not find tsconfig.spec.json anymore.

Debugging jest-builder showed that change in https://github.com/nrwl/nx/blob/7.1.x/packages/builders/src/jest/jest.builder.ts#L47:

tsConfig: path.join('<rootDir>', path.relative(builderConfig.root, options.tsConfig))

fixes tests.

Also its weird that I cannot override globals Jest settings in my jest.config.js which I think would be expected.

Prerequisites

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

Expected Behavior

Running jest unit tests normally as was before an update to latest Jest and jest-preset-angular

Current Behavior

File not found: tsconfig.spec.json (resolved as: .../tsconfig.spec.json)

It resolves always to monorepo root folder, not to lib folder.

third-party enhancement

Most helpful comment

https://github.com/thymikee/jest-preset-angular/pull/224 was merged and I tested it with Nx with the changes that @vitalyiegorov mentioned and it's looking good. I'll write the migrations tonight :)

All 10 comments

I'm excited for the changes in Jest 24 :) I think we'll wait for ts-jest and angular-preset-angular to stabilize before we decide what to do. More than likely, it will have limited impact on the current usage of jest since most things are handled within the builder.

So what can be done in the meantime? My tests don't run now. I have the same issue as #1054.

@YonatanKra If you downgrade jest to v23.6.0 it should work

For some reason it doesn't happen locally - only on circle-ci. I've set the version to just 23.6.0 in package.json (without ~ nor ^) but to no avail.
Actually, locally it works with jest 24.1.0. I guess it must be a circleci issue.

This issue is now relevant to https://www.npmjs.com/advisories/786 , not upgrading to Jest >= 24 will report security issues with a dependency (braces) during installations and npm audits.

https://github.com/thymikee/jest-preset-angular/pull/224 was merged and I tested it with Nx with the changes that @vitalyiegorov mentioned and it's looking good. I'll write the migrations tonight :)

jest-preset-angular v7 was released. So no more a blocker.

@YonatanKra If you downgrade jest to v23.6.0 it should work

downgrading is not working. is there any other alternative?

I still get with version 7.1.1:

File not found: /src/tsconfig.spec.json

For those who are still facing this issue, this solution has helped me.*

https://github.com/thymikee/jest-preset-angular/issues/286

Was this page helpful?
0 / 5 - 0 ratings