Repository navigation
docs: explain how to instrument an Angular 17+ app (#893) - #1011
Merged
Merged
Conversation
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUv8r5AkgdXypsb5vxyMnQ
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUv8r5AkgdXypsb5vxyMnQ
|
🎉 This PR is included in version 4.1.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Additional details
#893 isn't a plugin bug. The reporter's Angular app was never instrumented, so
window.__coverage__never existed and the plugin had nothing to collect. Angular CLI ignores.babelrcandbabel.config.json, and since Angular 17 the default esbuild-basedapplicationbuilder has no hook for Istanbul. The issue has picked up a few "any solutions?" replies, so this adds an "Instrument an Angular app" subsection under "Instrument your application" in the README. It covers:babel-plugin-istanbulto a Babel config does nothing in Angular@angular-builders/custom-webpack(matching the Angular major version),babel-loaderandbabel-plugin-istanbulcoverage.webpack.jsthat runsbabel-loaderwithistanbulas a post loader onsrc/**/*.tscoverageconfiguration on both thebuildandservetargets, so production builds stay uninstrumented.ng serve --configuration coveragefails without the matchingserveentry.browser→mainoption rename when switching builders, and a note that Cypress config flags likeenv.coveragedon't instrument anythingThis is a README-only change, with no code changes and no new test app. A full Angular test app in the CI matrix seemed too heavy for a docs fix.
Steps to test
I checked these steps against a fresh Angular 18.2 app (
ng new):applicationbuilder and a.babelrccontainingbabel-plugin-istanbul, runng build. The bundle contains no__coverage__, which reproduces the issue.ng build --configuration coverage.main.jscontains the Istanbul counters. A plaindevelopmentbuild does not.ng serve --configuration coverage. The servedmain.jsis instrumented.window.__coverage__listsmain.tsand thesrc/app/*.tsfiles, andnyc reportmaps results back to the TypeScript source lines, with templates included.I've only tested Angular 18. Builder versions for 19 and later exist, but I haven't run them.
npm run build,npm testandnpm run format:checkpass.npm run check:markdowncouldn't reach github.com from my environment, so CI is the real check for the newjust-jeb/angular-builderslink.How has the user experience changed?
No change to the plugin. The README now has Angular-specific instrumentation steps.
Generated by Claude Code
Note
Low Risk
Documentation-only change with no impact on plugin behavior or build artifacts.
Overview
Adds an Instrument an Angular app subsection to the README (after the SWC section) to address users who see no
window.__coverage__because Angular never runs Istanbul through Babel or the default esbuild builder.The new docs explain why
.babelrc/babel.config.jsonare ignored, recommend switchingbuildandserveto@angular-builders/custom-webpackwith a post-babel-loaderrule incoverage.webpack.js, and show a dedicatedcoverageconfiguration on both targets so onlyng serve --configuration coverageserves instrumented bundles. It also calls out thebrowser→mainrename and that Cypressenvflags do not instrument the app.No plugin or runtime code changes—README only, no new test app in CI.
Reviewed by Cursor Bugbot for commit a466984. Bugbot is set up for automated code reviews on this repo. Configure here.