Skip to content

[@angular/build:unit-test][vitest] Configurable vitest #30429

Description

@joergbaier

Command

test

Description

First of all, I support the initiative to add vitest to Angular. Especially since vite is already used for build & serve.

Early feedback for vitest in Angular v20. Based on a quick browse of packages/angular/build/src/builders/unit-test/builder.ts there doesn't seem to be a way to pass configuration settings.

For this to be even slightly usable, you would need to set vitest options such as:

  • timeouts
  • setupFiles
  • coverage (specify lcov reporter)

Describe the solution you'd like

One option is letting people pass vitest options in angular.json and doing a deep object merge. This is probably the easiest to implement but most likely to lead to configuration confusion and conflicts.

Describe alternatives you've considered

Personally I would rather see less obfuscation... let people have a vitest.config.ts. Projects that don't have advanced testing needs would never need to add this file.

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {}
});

With the vitest.config.ts, Angular could add a plugin similar to @analogjs/vite-plugin-angular.

OR

Export an Angular version of defineConfig which is used instead of vitest/config. Then you can strongly type the options and include/exclude ones that make sense for angular.

import { defineConfig } from "@angular/vitest";

export default defineConfig({ ... });

Please press the 👍 since this needs at least 20 to be considered!

Activity

  1. added
    feature
    on Jun 2, 2025
  2. added
    feature: votes required
    on Jun 2, 2025
  3. angular-robot commented on Jun 2, 2025

    @angular-robot
    Contributor

    This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

    You can find more details about the feature request process in our documentation.

  4. brandonroberts commented on Jun 3, 2025

    @brandonroberts
    Contributor

    Thanks for the mention @joergbaier. One point of clarification is that vite is not used by the Angular CLI for building the application. esbuild is used for building both during development and production. Vite is used only as the development server to serve the assets produced by esbuild.

    I do like the idea of the @angular/vitest package though exporting a subset of supported features. Similar to how the karma.conf.js was supported. It will cause confusion though as people will try to override with the config file and things will break unexpectedly.

    The Angular team has traditionally not allowed any official means of supporting configuration outside of the angular.json though.

  5. added
    feature: under consideration
    and removed
    feature: votes required
    on Jun 4, 2025
  6. umarkashmiri commented on Jun 5, 2025

    @umarkashmiri

    Is there any way to change the coverage provider to @vitest/coverage-istanbul

    by default it is set to @vitest/coverage-v8 and i dont have a way to change it to make it compatible with sonarqube :/

  7. joergbaier commented on Jun 5, 2025

    @joergbaier
    Author

    @umarkashmiri I solved this in a non-angular project by setting coverage.reporter to ["lcovonly"] even with v8. But still, we would need the ability to do the same here.

    This update could be enough for you as well #30464

  8. drdreo commented on Jun 11, 2025

    @drdreo

    I am experimenting with the new unit-test builder and vitest, and switched to a browser based environment. But could not figure out how to configure headless mode. Exposing some of the vitest settings would be really great, like they support a headless option via vitest --browser.headless

  9. fgirardey commented on Jun 26, 2025

    @fgirardey

    Letting people opt-in to a vitest.config.ts file workflow would also enable the usage of the Vitest VS Code extension and boost the developer experience.

  10. snebjorn commented on Jul 26, 2025

    @snebjorn

    I was looking to play around with vitest and msw but that requires me to add some setupFiles to the vitest configuration.
    https://mswjs.io/docs/quick-start

    // vitest.setup.ts
    import { beforeAll, afterEach, afterAll } from 'vitest'
    import { server } from './mocks/node.js'
     
    beforeAll(() => server.listen())
    afterEach(() => server.resetHandlers())
    afterAll(() => server.close())

    Hopefully support for this will come soon

  11. 1 remaining item

  12. dcbroad3 commented on Aug 6, 2025

    @dcbroad3

    Attempting to use the new vitest builder today, I encountered two limitations.

    I imagine that either including these as options in the builder config or a full vitest config file would address this.

  13. brandonroberts commented on Aug 7, 2025

    @brandonroberts
    Contributor

    An option for coverage thresholds could be added to the schema/builder.

    There's a PR for supporting the outputFile #30682

    I think the most common configurable items will be added to the unit-test builder over time.

    If you need a fully configurable vitest.config.ts, using the AnalogJS Vite plugin for Angular along with the @analogjs/vitest-angular package is the more likely option.

  14. yogeshgadge commented on Aug 21, 2025

    @yogeshgadge

    The Angular team has traditionally not allowed any official means of supporting configuration outside of the angular.json though.

    @brandonroberts wondering what advise does vcsode/IDE plugin developers (like vitest, jest, playwright) should take from this approach where the configs for test frameworks must be only read from angular.json.

  15. brandonroberts commented on Aug 21, 2025

    @brandonroberts
    Contributor

    The Angular team has traditionally not allowed any official means of supporting configuration outside of the angular.json though.

    @brandonroberts wondering what advise does vcsode/IDE plugin developers (like vitest, jest, playwright) should take from this approach where the configs for test frameworks must be only read from angular.json.

    I'm not sure. Angular doesn't produce the configuration files necessary for the VSCode/IDE plugins are looking for to make this work. Special hooks would have to be made to support Angular conventions. Tools like Vite/Vitest are implementation details in this case.

    It's a chicken/egg problem. Even if Angular produced the configuration files, the plugins run the tools directly, which is counter to what Angular does which is run the tools internally through the builders. There would need to be some sort of communication layer for Angular to communicate with these tools. I don't know if that's a goal on either side though.

  16. attilaolah commented on Aug 29, 2025

    @attilaolah

    I came here looking for a way to pass code coverage options to vitest, but apparently there is already a codeCoverageReporters option. Just putting it here, since I didn't find any documentation on it, not on https://angular.dev/guide/testing/code-coverage, but the schema is documented in @angular/build/src/builders/unit-test/schema.d.ts.

  17. italosll commented on Sep 17, 2025

    @italosll
  18. brandonroberts commented on Sep 17, 2025

    @brandonroberts
  19. clydin commented on Dec 18, 2025

    @clydin
    Member

    This is now possible with Angular v21. Please see the documentation for further details: https://angular.dev/guide/testing

  20. angular-automatic-lock-bot commented on Jan 18, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  21. locked and limited conversation to collaborators on Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    angular/build:unit-testarea: @angular/buildfeaturefeature: under consideration

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions