From df975a25aaf84fce584289a685e7e0856f6738ce Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 22:53:16 +0000 Subject: [PATCH 1/2] docs: explain how to instrument an Angular 17+ app (#893) Angular CLI ignores Babel config files, and the default esbuild-based application builder has no hook for Istanbul, so adding babel-plugin-istanbul to .babelrc leaves window.__coverage__ undefined. Document switching to @angular-builders/custom-webpack with a post babel-loader that runs istanbul, which was verified against an Angular 18 app. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WUv8r5AkgdXypsb5vxyMnQ --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 68b01a6d..679fb18a 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,34 @@ SWC plugins only load in the SWC version they were built for, and a mismatch mak See [test-apps/swc-webpack](test-apps/swc-webpack) for a complete example. +### Instrument an Angular app + +Angular CLI ignores `.babelrc` and `babel.config.json`, so adding `babel-plugin-istanbul` there has no effect. Angular 17 and later build with the esbuild-based `application` builder by default, which has no option to add Istanbul. One way to instrument the app is to switch the `build` and `serve` targets in `angular.json` to the webpack-based builders from [@angular-builders/custom-webpack](https://github.com/just-jeb/angular-builders/tree/master/packages/custom-webpack), then add a loader that instruments your TypeScript source after Angular compiles it: + +```js +// coverage.webpack.js, set as "customWebpackConfig" in angular.json +const path = require('path') + +module.exports = { + module: { + rules: [ + { + test: /\.ts$/, + include: path.join(__dirname, 'src'), + exclude: /\.spec\.ts$/, + enforce: 'post', + use: { + loader: 'babel-loader', + options: { plugins: ['istanbul'] } + } + } + ] + } +} +``` + +The `custom-webpack:browser` builder takes `main` where the `application` builder takes `browser`, so rename that option when you switch. Setting options such as `env.coverage` or `instrument` in your Cypress config doesn't instrument anything. Check for `window.__coverage__` in the app as described above. + ### More information - Read [Cypress Code Coverage: Instrumenting code](https://on.cypress.io/code-coverage#Instrumenting-code) guide From a4669841dbf2683c195f9bce77af6ae62fa29515 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 23:56:16 +0000 Subject: [PATCH 2/2] docs: add install and coverage-only config steps to Angular note (#893) The Angular instrumentation note left out the packages the webpack config needs and wired instrumentation into every build. List the install command, and scope the custom webpack config to a separate coverage configuration on both the build and serve targets, since ng serve --configuration coverage needs a matching serve entry. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WUv8r5AkgdXypsb5vxyMnQ --- README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 679fb18a..95522ce0 100644 --- a/README.md +++ b/README.md @@ -122,10 +122,18 @@ See [test-apps/swc-webpack](test-apps/swc-webpack) for a complete example. ### Instrument an Angular app -Angular CLI ignores `.babelrc` and `babel.config.json`, so adding `babel-plugin-istanbul` there has no effect. Angular 17 and later build with the esbuild-based `application` builder by default, which has no option to add Istanbul. One way to instrument the app is to switch the `build` and `serve` targets in `angular.json` to the webpack-based builders from [@angular-builders/custom-webpack](https://github.com/just-jeb/angular-builders/tree/master/packages/custom-webpack), then add a loader that instruments your TypeScript source after Angular compiles it: +Angular CLI ignores `.babelrc` and `babel.config.json`, so adding `babel-plugin-istanbul` there has no effect. Angular 17 and later build with the esbuild-based `application` builder by default, which has no option to add Istanbul. One way to instrument the app is to switch the `build` and `serve` targets in `angular.json` to the webpack-based builders from [@angular-builders/custom-webpack](https://github.com/just-jeb/angular-builders/tree/master/packages/custom-webpack), then add a loader that instruments your TypeScript source after Angular compiles it. + +Install the builder with the same major version as your Angular release (18 in this example), plus the loader and the Istanbul plugin: + +```shell +npm i -D @angular-builders/custom-webpack@18 babel-loader babel-plugin-istanbul +``` + +Then create the webpack config: ```js -// coverage.webpack.js, set as "customWebpackConfig" in angular.json +// coverage.webpack.js const path = require('path') module.exports = { @@ -146,6 +154,27 @@ module.exports = { } ``` +Instrumented code is slower and larger, so point to it from a separate `coverage` configuration instead of the default `options`. Add it to both the `build` and `serve` targets in `angular.json`, replacing `my-app` with your project name: + +```json +"build": { + "configurations": { + "coverage": { + "optimization": false, + "sourceMap": true, + "customWebpackConfig": { "path": "./coverage.webpack.js" } + } + } +}, +"serve": { + "configurations": { + "coverage": { "buildTarget": "my-app:build:coverage" } + } +} +``` + +Then start the app with `ng serve --configuration coverage` before running Cypress. + The `custom-webpack:browser` builder takes `main` where the `application` builder takes `browser`, so rename that option when you switch. Setting options such as `env.coverage` or `instrument` in your Cypress config doesn't instrument anything. Check for `window.__coverage__` in the app as described above. ### More information