Skip to content

Conversation

@clydin
Copy link
Member

@clydin clydin commented Oct 27, 2025

Adds a new runnerConfig option to the unit-test system to provide more control over the test runner's configuration file. This option is runner-agnostic and enhances flexibility for both Vitest and Karma.

The option accepts a boolean or a string path:

  • true: Automatically searches for a default config file (karma.conf.js or vitest.config.ts). If not found, the runner will use its internal default configuration.
  • false (default): Disables the use of any external config file.
  • path/to/config: Uses the specified configuration file.

For Vitest, the loaded configuration is deep-merged with the system's programmatic config. This allows users to add or override advanced options (like test.coverage) while preserving the essential in-memory integration. The system's settings take precedence in case of conflicts.

Please note that while the file is loaded, the Angular team does not provide direct support for its specific contents or any third-party plugins used within it.

Informational messages are now logged to indicate which configuration file is being used, improving transparency.

Closes #31392

@clydin clydin added the target: rc This PR is targeted for the next release-candidate label Oct 27, 2025
@clydin clydin requested a review from alan-agius4 October 27, 2025 02:29
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 27, 2025
…test

Adds a new `runnerConfig` option to the `unit-test` system to provide more control over the test runner's configuration file. This option is runner-agnostic and enhances flexibility for both Vitest and Karma.

The option accepts a boolean or a string path:
- `true`: Automatically searches for a default config file (`karma.conf.js` or `vitest.config.ts`). If not found, the runner will use its internal default configuration.
- `false` (default): Disables the use of any external config file.
- `path/to/config`: Uses the specified configuration file.

For Vitest, the loaded configuration is deep-merged with the system's programmatic config. This allows users to add or override advanced options (like `test.coverage`) while preserving the essential in-memory integration. The system's settings take precedence in case of conflicts.

Please note that while the file is loaded, the Angular team does not provide direct support for its specific contents or any third-party plugins used within it.

Informational messages are now logged to indicate which configuration file is being used, improving transparency.
@clydin clydin force-pushed the unit-test/config-file branch from 90e8dcf to cb8727e Compare October 27, 2025 11:12
@yjaaidi
Copy link
Contributor

yjaaidi commented Oct 27, 2025

Nice one @clydin, thanks!

Just one thing.
While I think that the feature is crucial and I know that a standalone vitest.config.ts requires more effort and is not the current goal, I am afraid that such a config file, especially when using the conventional name (vitest.config.ts) will actually confuse the integration with tools such as the IDE plugins as it’s a partial configuration.

To avoid user and tool confusion, what about naming it differently (e.g. vitest-overrides.config.ts or something)
Or what about exposing a defineVitestConfig function that strips the options that can't be overridden from the typing.
I can already imagine issues such as:

  • I've changed this option in vitest.config.ts and when I run the tests using vitest, the options work but the tests involving Angular components do not work, and when I use the builder, the option seems to be ignored, but that other option is not ignored.

@clydin
Copy link
Member Author

clydin commented Oct 27, 2025

This is opt-in and the name can be configured to an arbitrary value. If there is need to avoid it being picked up by other tools (some actually may want it picked up), it can be named something different. Also of relevance, this is more of a "base" rather than an override. Options specified on command execution take precedence which follows the behavior of Vitest.

"enum": ["karma", "vitest"]
},
"runnerConfig": {
"type": ["boolean", "string"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: Not sure how to handle this, but having type both boolean or string will make runnerConfig config not possible to be used from the CLI. As options cannot be either boolean or string.

@yjaaidi
Copy link
Contributor

yjaaidi commented Oct 27, 2025

Agreed, something like a base suffix would be a better fit.

I am actually concerned about the default name. Newcomers and AI-generated code will more likely pick vitest.config.ts and be surprised of the behavior.

@clydin clydin 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 Oct 27, 2025
@clydin
Copy link
Member Author

clydin commented Oct 27, 2025

Initial goal here was consistency as the Angular CLI has used the existing karma.conf.js default file name.
However, we can evaluate a different default but it would require implementing manual file discovery that would match vitest's.

@clydin clydin merged commit 20079ed into angular:main Oct 27, 2025
32 checks passed
@clydin
Copy link
Member Author

clydin commented Oct 27, 2025

This PR was merged into the repository. The changes were merged into the following branches:

@clydin clydin deleted the unit-test/config-file branch October 27, 2025 17:08
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 target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@angular/build:unit-test: Configuration option for the time watermark of the progress reporters similar to the coverageWatermarks option

3 participants