Title: fix(@angular/build): preserve component initialization in Karma test bundles by nagahara-naoki · Pull Request #34668 · angular/angular-cli · GitHub
Open Graph Title: fix(@angular/build): preserve component initialization in Karma test bundles by nagahara-naoki · Pull Request #34668 · angular/angular-cli
X Title: fix(@angular/build): preserve component initialization in Karma test bundles by nagahara-naoki · Pull Request #34668 · angular/angular-cli
Description: PR Checklist The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines Tests for the changes have been added (for bug fixes / features) Docs have been added / updated (not applicable: internal Karma bundling fix; no new options or public API) PR Type Bugfix What is the current behavior? Fixes #34250. With @angular/build:karma, a component imported through a barrel can be captured as undefined in another component's imports array. This depends on the combination of spec entry points: an async spec importing the component directly can cause lazy module initialization to cross shared-chunk boundaries. The consuming decorator can run before the component is initialized. The regression fixture includes: A standalone layout component re-exported by a barrel. A dialog importing that barrel and used by two specs. A page importing the barrel and used by another spec. An async spec importing the layout directly. Against main (2c6e8b970), the browser reports 2 failed, 2 successful. Both dialog specs throw Cannot read properties of undefined (reading 'ɵcmp'). What is the new behavior? The Karma build routes the discovered spec entry points through a shared virtual module that imports all selected specs. This keeps spec initialization in one module graph, avoiding the problematic partitioning across independent spec entry points. Preserve the existing spec-* entry names, including basename-collision handling. Keep code splitting enabled so Angular and its testing environment remain shared with the setup entry point. Include the original spec files as TypeScript root files, since the build entry points now refer to the virtual module. Preserve include/exclude selection: the virtual module only imports the specs collected by the existing discovery logic. The same four browser specs now all pass. The added integration test exercises real Karma/Chrome execution rather than only checking generated bundle text. Does this PR introduce a breaking change? Yes No Other information Simply setting disableCodeSplitting: true, as suggested by the earlier Vitest fix in #33729, was insufficient for Karma in this reproduction: it produced testing-environment initialization errors. This change retains shared framework chunks instead. Validation on macOS arm64, Node.js 24.22.2, pnpm 12.16.1, and Chrome Headless 159: pnpm bazel test //packages/angular/build:karma_integration_tests --config=no-sharding --test_output=errors: 42 integration specs, 0 failures. ESLint for the changed implementation passes. The repository ESLint configuration excludes builder integration fixtures. Prettier checks for both changed files and git diff --check pass. The full repository and E2E suites were not run. Large-suite build size/performance and dynamic addition of spec files during watch mode were not separately benchmarked or validated.
Open Graph Description: PR Checklist The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines Tests for the changes have been added (for bug...
X Description: PR Checklist The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines Tests for the changes have been added (for bug...
Opengraph URL: https://github.com/angular/angular-cli/pull/34668
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c11d05e4-09e7-eef3-0cb3-08a90e144458 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A9C0:240CD1:361E231:44D38BB:6B01E9A4 |
| html-safe-nonce | 3bfb98fd53f406963d15cc9fdbc958ed9a9008c51569960cf1773d0dcf73ae3a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUMwOjI0MENEMTozNjFFMjMxOjQ0RDM4QkI6NkIwMUU5QTQiLCJ2aXNpdG9yX2lkIjoiMTYyMTM0MjMxMzQyNTAwNDk2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 34cb0c3068eb2dde18f22cb19accfb4385240a2fec9d3e8daffb2aa2a296c426 |
| hovercard-subject-tag | pull_request:5202659777 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angular-cli/pull/34668/files |
| twitter:image | https://avatars.githubusercontent.com/u/118710021?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/118710021?s=400&v=4 |
| og:image:alt | PR Checklist The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines Tests for the changes have been added (for bug... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width