Closed just-jeb closed 2 years ago
The error is about the AST transformers are not applied. Not sure why this happens while it doesn't happen to https://github.com/thymikee/jest-preset-angular/tree/main/examples/example-app-v14
I'd guess it has something to do with monorepo setup and Yarn workspaces, but you're the expert ๐
When I compare between master
and reproduce branch, I saw a slight change in package.json
with jest
configuration. The change isnโt in master
, could it be the case?
We have example for yarn workspace at https://github.com/thymikee/jest-preset-angular/tree/main/examples/example-app-yarn-workspace which donโt have the issue. Maybe you can take a look to see.
I believe this is something with workspace configuration which is sort of out of scope to handle.
The change in package.json
was in order to use jest-preset-angular
directly, without the builder, to eliminate the possibility of a bug in the builder.
Other than that it's just a regular Yarn workspace.
I'll try to figure out what happens, but my fear is that the issue is wider than just my particular monorepo. Let's wait and see if there are more complaints before closing it here.
We have example for yarn workspace at https://github.com/thymikee/jest-preset-angular/tree/main/examples/example-app-yarn-workspace which donโt have the issue. Maybe you can take a look to see.
@ahnpnl The example app in the monorepo uses Angular 13 so I can't fairly compare this setup to mine.
Update:
Issue is solved on my side, the problem was some mysterious relations between peerDeps
and devDeps
causing Yarn to not hoist some dependencies that should have been hoisted.
I see that currently I'm the only one who experienced this issue so I'm closing it.
Thanks for the help and sorry for the mess ๐
Thanks for the updating!
@just-jeb you're not the only one with this problem. Can you share what exactly were your steps to resolve this issue? I'm using
"@angular-builders/jest": "14.0.1",
"jest": "28.1.3",
"jest-preset-angular": "12.2.0",
As I mentioned, it was a dependency hell, try to make sure that you don't have some weird hierarchy or non-hoisted modules in case of monorepo.
Also, you don't need an explicit dependency on the preset, the builder brings it for you.
tl;dr Use Typescript < 4.8
@GeorgeTailor I had the same issue as you with exactly the same deps.
"@angular-builders/jest": "14.0.1"
"jest": "28.1.3"
"jest-preset-angular": "12.2.0" via "@angular-builders/jest": "14.0.1"
Turns out the issue was ng upgrade
upped my typescript
from 4.5.4
to 4.8.4
and there is a breaking change in 4.8
as @ahnpnl mentions here that causes the same error message.
Weird thing is that if you ng new
an Angular 14 project you get "typescript": "~4.7.2"
so I downgraded to that and all is well.
tl;dr Use Typescript < 4.8
@GeorgeTailor I had the same issue as you with exactly the same deps.
"@angular-builders/jest": "14.0.1" "jest": "28.1.3" "jest-preset-angular": "12.2.0" via "@angular-builders/jest": "14.0.1"
Turns out the issue was
ng upgrade
upped mytypescript
from4.5.4
to4.8.4
and there is a breaking change in4.8
as @ahnpnl mentions here that causes the same error message.Weird thing is that if you
ng new
an Angular 14 project you get"typescript": "~4.7.2"
so I downgraded to that and all is well.
I had the exact same issue, and the root cause is the same what you have mentioned. I downgraded the typescript version from 4.8.4 to 4.7.2 and it worked.
I had the same issue after updating to Angular 15, which supports TypeScript 4.8 or higher. Because I didn't want to downgrade my TypeScript to 4.7 (which is mentioned as workaround in the comment above) just so I could test Components in Jest (in fact, I've updated my TS 4.8 it to 4.9.5 instead), I've tried to see if anything else was causing an issue.
The version combinations I was using that gave me the same error:
Updating Jest itself to 29.4.1 (current latest) fixed the issue for me. Not sure what changed since 28.1.1 that caused the issue, but this did the trick for me. I'm just leaving this here in case anyone else is experiencing the same issue.
It seems juggling with the versions of jest, jest-preset-angular, and typescript is required when encountering this issue. Hopefully a minor/major version update of any of these three dependencies won't cause the same issue again in the future, but I'm glad it's at least working for me now with the current latest versions for all three.
Version
12.1.0
Steps to reproduce
git@github.com:just-jeb/angular-builders.git
14.x.x-update-jest
yarn --forzen-lockfile
cd examples/jest/simple-app
yarn jest
Expected behavior
The tests pass
Actual behavior
The tests fail
Additional context
I'm facing this issue while trying to update
@angular-builders/jest
to the latestJest
andjest-preset-angular
versions.At first I was convinced something is wrong with the builder, so I did multiple attempts to try and fix it.
However, after creating a simple jest.config just as described in the docs of
jest-preset-angular
I realized that even without the builder it fails with the same error.So either the docs are missing an important piece of information or the preset is not working properly with Angular 14.
Environment