-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't run tests with jest 28.0 #10117
Comments
Jest 28 support is still in the works, but probably need to update ts-jest to v28 since transformer return changed a little. I think ts-jest v28 was still prerelease |
@barbados-clemens seem like ts-jest 28 is now available https://www.npmjs.com/package/ts-jest |
Looks like it. there are still @types/jest and jest-preset-angular that need to drop support for jest v28 as well. |
When updated to jest 28 my test ran to this issue: |
@mkhib It's most probably jest-preset-angular. It has to be updated to support jest 28. |
The problem here is that |
you can manually install jest-environment-jsdom v28 and jest v28 without any problems. @nrwl/jest isn't going to stop you from manually updating those. I'm working on getting a PR for jest 28 support. just mainly working through the migrations for the changes. but in my limited testing you can just bump all your jest versions and it should just work with the exception of using |
yep, it works, a hotfix is:
|
with the jest v28 changes (and comming migration) you should explicitly include jest-environment-jsdom in your devDeps. So I would recommend you keep it in your devDeps. |
I think it's an ask for Also, why should I, if it's a known dependency for Angular and jest? |
nx will add it via migration and going forward when jest v28 support is released. Just saying in the meantime it would probably be best to be explicit about the devDep to prevent it from being accidentally removed from others in the project. |
Any tentative release date for jest v28 support? |
it's in progress. the migrations are a bit tricky for this one. |
If anyone needs an example of an nx workspace that uses jest 28, check this one. There are two frameworks: NestJS, Angular. Changes that have to be made:
If @angular/fire if used, one will have to mock the package depending on what's used like ...
jest.mock('@angular/fire/app', () => firebaseAppMockValue);
jest.mock('@angular/fire/auth', () => firebaseAuthMockValue);
jest.mock('@angular/fire/database', () => firebaseDatabaseMockValue);
... |
Just curious, if I manually migrate now, will it affect NX's ability to do migrations in the future? I'd like NX to maintain control, but I've never been sure what kinds of changes I can make without affecting those migrations. |
@eglove my guess is that Nx will override your manual changes, if applicable, when you apply migrations. |
@eglove @rfprod it shouldn't break anything once the nx migration is ran. the only thing that would get overridden I think would get overridden would be the jest version if they don't match. Any breaking changes from jest 28 the migration would update would presumably already be fixed in your code base. I'm going to try to finish the jest 28 migration this week. Just putting the final touches on the Cypress 10 support. |
I've just about finished my manual migration and other cleanup. The biggest thing I was running into is documented here. thymikee/jest-preset-angular#1625 I had to work on setting up my resolver to remove object properties from the parsed package.json so it would target main instead of the module/exports fields for importing. |
@barbados-clemens something to keep on your radar when you're implementing this:
However, since Nx uses its own custom resolver, it's not possible to implement this workaround whilst using Nx I tested adding this extra |
@Ezard I've been running my own resolver for a while with Nx.
|
try { | |
// Try to use the defaultResolver with default options | |
return options.defaultResolver(path, options); | |
} catch { | |
// Try to use the defaultResolver with a packageFilter | |
return options.defaultResolver(path, { | |
...options, | |
packageFilter: (pkg) => ({ | |
...pkg, | |
main: pkg.main || pkg.es2015 || pkg.module, | |
}), | |
pathFilter: (pkg) => { | |
if (!pkg.exports) { | |
return path; | |
} | |
return resolveExports(pkg, path) || path; | |
}, | |
}); | |
} |
Edit:
I will add that all configuration settings for tooling should be extendable/composable. A lot of Nx is, but there are some pain points like Next's config and this resolver.
As another heads up, the Aside from adding a big list of affected packages to the NX resolver, it's going to be challenging to make sure everyone's environment stays working after the migration. You will probably want to make the resolver exposed or configurable enough to add packages to, at the very least. |
This is tricky as providing a resolver to jest is just a path to the resolver. So there isn't really a jest built-in way to extend a resolver without manually extending as demoed above. I am very hesitant to handle all the various projects that need custom logic internally in the resolver. I'll look more into this. |
@barbados-clemens the Currently, any Nx project that uses Nest with Jest 28 will need to use the above workaround (maybe the above patch could only be automatically applied when Nx is setup to contain Nest projects?) |
Talking with other on this issue I think we'll go with maintaining the list internally inside the nrwl resolver and if there is a reason you need to extend our resolver then following @Brian-McBride example on how to do it is a good way to do it. While maintaining that list isn't ideal, it does prevent
Right now I know of the packages mentioned via
|
Don't forget the The whole ESM migration is poorly thought out it seems now that we are in it all. While there is a lot of focus on Angular within the Nx team, please don't forget React! lol :) |
While waiting for this issue to be resolved, I modified the react transformer so it works with jest 28
Then in
|
In my case (a @nrwl/next app), changing the
to
did the trick. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
I tried updating
jest
to the latest version (28) and started experiencing the classic TypeScript errors that you get when there are Babel / compiling TypeScript issues.For example:
SyntaxError: Unexpected token 'export'
orSyntaxError: Cannot use import statement outside a module
I'm using
babel-jest
as the transform for my TypeScript tests.Expected Behavior
I should be able to use jest 28 to run my tests.
Steps to Reproduce
Here is a repo reproduction.
https://github.com/Tirke/jest-28
If you switch back to jest 27 it will work.
They did communicate on some changes with Babel here
Failure Logs
Environment
The text was updated successfully, but these errors were encountered: