Skip to content

fix(@angular/build): only compile included test files in unit-test builder - #34134

Open
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix-unit-test-include-compilation
Open

alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix-unit-test-include-compilation

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

When running the unit-test builder with --include, TypeScript compilation previously compiled all test files matched by the tsconfig file, causing compilation errors in unrelated test files to fail the test run.

This change introduces a rootFiles option that restricts the TypeScript program's root files to only the test files to be executed (plus setup files and providers), while preserving ambient .d.ts declaration files discovered by readConfiguration.

Fixes #34089

@alan-agius4 alan-agius4 added the target: rc This PR is targeted for the next release-candidate label Sep 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a rootFiles option to the Angular application builder and compiler options, allowing the TypeScript compilation to restrict its root names to only the specified files (such as test, setup, and provider files). This change prevents compilation errors in non-included test files during unit testing. The feedback suggests ensuring that if a custom main file is provided in the Karma options, it is also included in the rootFiles list to avoid compilation warnings or errors.

Comment thread packages/angular/build/src/builders/karma/application_builder.ts Outdated
@alan-agius4
alan-agius4 force-pushed the fix-unit-test-include-compilation branch 2 times, most recently from 5f80743 to 3317656 Compare September 21, 2026 13:18
@alan-agius4
alan-agius4 requested a review from clydin September 21, 2026 17:49
@alan-agius4 alan-agius4 self-assigned this Sep 21, 2026
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer and removed area: @angular/build labels Sep 21, 2026
…ilder

When running the `unit-test` builder with `--include`, TypeScript compilation previously compiled all test files matched by the tsconfig file, causing compilation errors in unrelated test files to fail the test run.

This change introduces an `excludeFiles` option that excludes test files not matched by the include patterns from the TypeScript program's root files, while preserving ambient declarations and application source files.

Fixes angular#34089
@alan-agius4
alan-agius4 force-pushed the fix-unit-test-include-compilation branch from 3317656 to d492fce Compare September 21, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running @angular/build:unit-test with --include= should only compile the included tests

1 participant