-
Notifications
You must be signed in to change notification settings - Fork 195
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
bug(transloco): error when running tests after updating to v5.0.9 #704
Comments
@dzhavat My guess is that it's related to the flat upgrade, it's now ESM. |
Hey @shaharkazaz |
Hi,
jest.config.ts export default {
preset: '../../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {},
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
isolatedModules: true,
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!**/*.stories.ts',
'!**/index.ts',
],
}; jest.preset.js const nxPreset = require('@nx/jest/preset').default;
module.exports = {
...nxPreset
}; I hope it could help. |
If this is the case it should be an major release, because this would be a breakting change as much as a change can be breaking. |
I'm also facing this issue. If you're in an nx workspace you're probably using jest-preset-angular for the jest configuration. They point out how to adjust the configuration to make jest work with esm modules. You can find the documentation here: https://thymikee.github.io/jest-preset-angular/docs/guides/esm-support In theory this should work, but I'm still struggling with it. |
Thanks for the fast reaction and clarification :) |
In case anyone else has this issue, I think |
I do have the same issue with the current version "6.0.0". Downgrading to 5.0.7 fixed the issue without any further changes. |
I had the same issue in my tests but finally succeeded in solving the issue. Here is how I did workaround it:
I hope this solution will help people which have the same issue. |
Thanks @FabienDehopre for your tip but for us not work. There is a plan to fix this issue? |
the
|
Thanks @Piiiiiiiiiiiim for your solution but, in our case, it makes the tests horribly slow (more than 90 secs and still no test ran). So, I'll stick to my solution for now |
NX uses
Before:
after:
|
Using jest in ESM mode is experimental, and had too many other side effects for my project. I tried overriding flat in package.json, as suggested by @elmarbeckmann, but somehow it didn't work. So I did a mix with the mock solution from @FabienDehopre. Installed flat 5.02 under an alias, just for jest:
|
wow I didn't even know you could use aliases. awesome. |
@elmarbeckmann Would you like to add this important information to the docs? 🙂 |
@shaharkazaz uhm can I do that? How? You mean by forking the docs and adding it? |
@elmarbeckmann I mean opening a PR to Transloco and add the workaround to the unit tests section/FAQ |
sure, will do! |
Easier solution: |
For me the only working solutions was the one mentioned by @elmarbeckmann |
Just leaving this here in case it helps anyone: Instead, we can use the // we need to let Jest know which files are ESM so they can be transformed to CommonJS
const esModules = [
'.*\\.mjs$', // .mjs files are always ESM so they need to be transformed always
'flat/', // npm package "flat" is ESM-only from version 6
].join('|');
...
// in jest config:
transformIgnorePatterns: [`node_modules/(?!\\.pnpm|${esModules})`], NOTE 1: we are using pnpm in our repo. If you don't use pnpm then you can remove NOTE 2: even better (ideal) scenario would be to go full 100% ESM. Then we would not have to transform esm modules to commonjs anymore. However, achieving this on a large existing repo is not trivial. If you are interested to try it, I recommend reading this article: https://angularexperts.io/blog/total-guide-to-jest-esm-and-angular |
Using the transformIgnorePatterns: ['node_modules/(?!(date-fns/|flat|lodash-es/|mime|.*\\.mjs$))'], didn't work for me either, I still got the I managed to get it work with:
solution similar to the one of @elmarbeckmann, but with the use of Going 100% ESM and the article of @kfrederix look promising 💡, I'll dig into it soon |
It seems as the "slowness comes from the regex with the negative lookahead. For me the issue with flax 6.0.0 was fixed by using:
|
Is there an existing issue for this?
Which Transloco package(s) are the source of the bug?
Transloco
Is this a regression?
No
Current behavior
After updating Transloco to version
5.0.9
, I'm getting the following error in my tests:The
transloco/fesm2022/ngneat-transloco.mjs:4:64
points toExpected behavior
Tests can start without issues.
Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.
Don't have :(
Transloco Config
Please provide the environment you discovered this bug in
Browser
No response
Additional context
No response
I would like to make a pull request for this bug
No
The text was updated successfully, but these errors were encountered: