run ngcc when using ng test to run test with ivy
See original GitHub issueDescribe the solution you’d like
When running ng test with
"test": {
"builder": "@angular-builders/jest:run",
"options": {
}
inside angular.json, it should run ngcc beforehand as angular-cli already does (see: https://github.com/angular/angular-cli/pull/15044#issue-296489062). Otherwise, tests are not running with ivy, which should be the default for angular 9.
As this might break existing tests, an options flag like "enableIvy": false could still be added in order to run them the old way. Or just use the configuration that’s already existing in tsconfig.spec.ts which usually points to tsconfig.ts that has "enableIvy": false already defined.
Describe alternatives you’ve considered
The only way I could make it work is by defining a scripts inside package.json.
{
"scripts": {
"test": "ngcc && ng test"
}
}
and then execute it with npm run test.
It would still be great to just run it with ng test
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
Here are my findings:
ngcctransforms libraries, typicallynode_modules(js files and dts), to make them Ivy compatible. It is necessary, especially if you want to have meaningful error messages when your test fails.node_modulesit’s enough to runngcconly once, for example inpostinstallhook to ensure compatibility.ngccon modules other thannode_modules- when you have a monorepo with libraries and you reference the production bundles of these libraries (distfolders) from your app’s tsconfig.build,serve,karma) usengtools/webpackand as part of Webpack compilation they runngcc_processoron each non-relative module, which essentially handles the case of monorepo with libraries. It also eliminates the need to runngccfor the wholenode_modulesand only runs it for the files that are part of the compilation.Conclusion: Running
ngccas apostinstallhook might be a viable workaround for 95% of projects, so we have to include it in the documentation and the migration guide.However, the only solution that will handle all the use cases properly is adding a custom Jest transformer that will apply
ngcc_processorfromngtools/webpackto all the non-relative modules similarly to Angular CLI.I seriously doubt though that this transformer should be implemented here and not in
jest-preset-angular.Unfortunately, currently this is the only way. A few things you can do:
node_moduleson CI workersngccrun and run it on them specifically (instead of the wholenode_modulesfolder).