Skip to content

Conversation

clydin
Copy link
Member

@clydin clydin commented Sep 16, 2025

Debugging test file discovery patterns (include and exclude) can be difficult. When glob patterns are misconfigured, the builder may not find the intended test files, and the only feedback is a "No tests found" message after a potentially long build.

This commit introduces a new --list-tests flag to the unit-test builder. When this flag is used, the builder will discover all test files according to the project's configuration, print the list of files to the console, and then exit without initiating a build or running the tests. This provides immediate feedback for developers to verify their test discovery configuration.

As part of this change, the test discovery logic was centralized from the Karma builder into the unit-test builder's directory, fulfilling a TODO and improving the overall code structure.

@clydin clydin added the target: major This PR is targeted for the next major release label Sep 16, 2025
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: @angular/build labels Sep 16, 2025
@clydin clydin force-pushed the unit-test/list-test-files branch 2 times, most recently from 3c39520 to e1aa9a1 Compare September 16, 2025 17:11
Debugging test file discovery patterns (`include` and `exclude`) can be difficult. When glob patterns are misconfigured, the builder may not find the intended test files, and the only feedback is a "No tests found" message after a potentially long build.

This commit introduces a new `--list-tests` flag to the `unit-test` builder. When this flag is used, the builder will discover all test files according to the project's configuration, print the list of files to the console, and then exit without initiating a build or running the tests. This provides immediate feedback for developers to verify their test discovery configuration.

As part of this change, the test discovery logic was centralized from the Karma builder into the `unit-test` builder's directory, fulfilling a TODO and improving the overall code structure.
…covery logic

The test discovery logic previously executed a separate `glob` operation for each pattern in the `include` array. In projects with multiple test locations, this resulted in redundant and inefficient file system scans.

This commit refactors the `findTests` function to perform only a single, consolidated `glob` call for all dynamic patterns, significantly improving performance.

Additionally, the logic for handling static (non-glob) paths has been extracted into a dedicated function, and the entire module has been documented with JSDoc comments to improve readability and maintainability.
The `getTestEntrypoints` function previously used a series of chained string replacement operations to generate a bundle name from a test file's path. For each file, this created multiple intermediate strings that were immediately discarded.

This commit refactors the name generation logic into a single-pass function. The new implementation iterates over the file's relative path once to construct the final dash-cased name, significantly reducing the number of temporary string allocations and the resulting garbage collector pressure. This provides a performance improvement, particularly in large projects with thousands of test files.
@clydin clydin force-pushed the unit-test/list-test-files branch from e1aa9a1 to 707b64c Compare September 16, 2025 17:24
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 16, 2025
@clydin clydin requested a review from alan-agius4 September 17, 2025 13:02
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 19, 2025
@clydin clydin merged commit a0f45f9 into angular:main Sep 19, 2025
33 checks passed
@clydin clydin deleted the unit-test/list-test-files branch September 19, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/build detected: feature PR contains a feature commit target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants