-
Notifications
You must be signed in to change notification settings - Fork 309
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
Support Angular v13 #1090
Comments
I think the solution is to change the following line:
to be something like: path.resolve(require.resolve('@angular/compiler-cli/ngcc'), 'main-ngcc.js'), |
Thanks for the suggestion! Indeed I have
The error about However, The workaround I could think of is copy internal codes from |
I briefly would like to add here, that I ran into a
Thank you for all your hard work! |
It looks like the only deep import that you have is
I think that we could consider adding a field to the |
Thanks for your quick response. In fact that will only solve partially the problem. Another problem is that The 2 main requirements to work with Angular 13 are:
Another concern is that, there might be other NodeJs toolings which rely on CommonJS. They might run into same issue like here if they don’t switch to use ESM mode in NodeJs. Does Angular provide a way to fallback this? |
Regarding CommonJS, you could consider bundling the Angular compiler code in your UMD bundles which would resolve that problem. But it would mean that the plugin is tied tightly to the version of the compiler that you build with. |
It appears that Jest plugins can use ESM if you make them async: https://jestjs.io/docs/next/code-transformation#:~:text=Note%20that%20ECMAScript,on%20the%20differences. |
According to jestjs/jest#11167 so it’s yes to ship |
We just realised that you have made a copy of the Your actual requirement is to have access to |
Hi, yes we need access to that one |
Oh yes, because of line 10 here: https://unpkg.com/browse/@angular/compiler-cli@13.0.0-rc.0/index.d.ts |
I tried the latest build on Must use import to load ES Module: .../ngrx/platform/node_modules/@angular/compiler-cli/bundles/index.js |
Hi, yes we fixed the issue with |
@ahnpnl - are you able to load the import asynchronously? If so then awaiting a dynamic import expression is the best approach to get ESM from CommonJS. |
Yes, it is possible
I don't see any new technical challenges from Angular packages for now. Need to spend time a bit to work on refactoring codes to adapt to this. |
Jest only uses async transformer when running under Node ESM flag. Migrating test suites from CJS to ESM can take lots of time for big repos. This seems to be quite a huge migration for end users. |
Hi @ahnpnl, I think in that case the only viable option would be to bundle the You can do this using https://github.com/developit/microbundle. Let me know if you need any help. |
I managed to make CJS tests passed https://github.com/thymikee/jest-preset-angular/runs/4054772234?check_suite_focus=true . I followed the suggestion from @alan-agius4 but not sure if it can be done better:
|
@ahnpnl, I was going to look into this on Monday. I suspect that to get ride of the module mapper workaround you might need to enable Jests’ |
@ahnpnl, I did a take a look at the CJS tests and it appears that the reason why you need the From the docs, it appears that one needs a custom resolve for this: I did monkey patch the resolver instead of implementing my own and it I was able to get rid of the module mappers if (filteredPkg.main != null) {
return filteredPkg;
}
+ if (filteredPkg.module != null) {
+ filteredPkg.main = filteredPkg.module;
+ } For Jest, it is also important to use
Maybe we can include the resolver as part of this preset? Edit: Sadly, from jestjs/jest#9771 (comment) it also appears that Jest, will never really respect the |
Thanks a lot @alan-agius4 !! I was suspecting that a custom resolver seems to be the only way to solve Indeed I was confused between Does internal Angular CLI use any custom resolvers for webpack to deal with |
No, we don't have any custom resolver. The tools used by the Angular CLI, Webpack, Node.js and Rollup (Which are used in different pipeline and phases) all support For Webpack we only provide the fields and the order that the resolver should consider. I think in your case, the resolver should look like the below module.exports = (request, options) =>
options.defaultResolver(request, {
...options,
packageFilter: (pkg) => ({
...pkg,
main: pkg.main || pkg.es2015 || pkg.module,
}),
}); |
that's simpler than I expected. Thanks again. I will test out this resolver. A quick test I could see that e2e test passed 👍 |
Feel free to ping me if you need any help or have any questions. You can also reach me on Twitter. |
Firebase recommended this resolver. Upgrade to 9.2.0 gives error in jest unit tests: // my-module-resolve.js
module.exports = (request, options) => {
// Call the defaultResolver, so we leverage its cache, error handling, etc.
return options.defaultResolver(request, {
...options,
// Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb)
packageFilter: pkg => {
if(pkg.name.startsWith('@firebase')) {
return {
...pkg,
// Alter the value of `main` before resolving the package
main: pkg.esm5 || pkg.module,
};
}
return pkg;
},
});
}; module.exports = {
....
// set the value to the custom resolver created in step 1
resolver: '<rootDir>/my-module-resolve.js',
// browser bundles in firebase are ESM, transform them to CJS to work in Jest
transformIgnorePatterns: [
"<rootDir>/node_modules/(?!(@firebase.*)/)"
]
}; |
Thanks for your input @tja4472, but here we are making a generic resolver for Angular 13, not specific to |
@ahnpnl I'm not sure if this is an issue with the configuration, or with the Angular Material library, but we're seeing failures to import on a few of their components (but oddly not all).
Does this look like something that would be a configuration issue (this project), or something more on their side? |
@michaelfaith That's a bug in Angular's partial compilation output. @petebacondarwin is working on a fix in the Angular compiler. |
@JoostK Excellent! Thank you for the heads up |
@ahnpnl I'm seeing a slightly different issue with testing of a library built with Angular 13. Similar to Material, these errors are popping up in Jest unit tests that involve components from the library, but it runs fine with
and
Comment from @JoostK:
|
You can check this #1149 (comment) |
You closed this issue but the problem remains,
|
@pinich please use |
I think you missed some configuration. You can take a look at our example app https://github.com/thymikee/jest-preset-angular/tree/main/examples/example-app-v13 |
Great! Thanks a lot! The problem was in the configuration |
How did you fix it @KonkypenT? |
@JaapBarnhoorn , I changed the library config, copied from the example that send @ahnpnl. |
Thank you @KonkypenT! 👍 |
Update on support Angular 13 (as of Nov 12, 2021)
The prerelease has been published (11.0.0-rc.3), anybody wanting to use with Angular 13 can run:
Version
10.0.1
Steps to reproduce
examples/example-app-v13
directory and install dependenciescd examples/example-app-v13 yarn
npm run test
Expected behavior
Tests run
Actual behavior
Error is thrown
Additional context
Angular introduced the
exports
property in thepackage.json
to be more strict about reaching into internal source code which may have caused this.Environment
The text was updated successfully, but these errors were encountered: