Open mgechev opened 1 year ago
Don't forget about Vitest π
After talking to @alan-agius4 and @dgp1130, looks like testing frameworks can override the unit test template by reusing the current schematics for generation of directives/components/pipes/services.
I don't see any major blockers to prioritize this and put it in the queue.
Vitest should also work fine given we can use JiT in testing. Next step would be to discuss timeline and follow up.
@mgechev would love if it will be implemented soon :)
Sounds fantastic. It would be great to get rid of Karma/Jasmine. It feels old and heavy. I currently use Jest which is really great. However, problems can also occur because the runtime is Node (with JSDOM). Same for ESM packages. Maybe the simplest way is to use Babel as precompiler. But I don't know what the best solution is. Vitest also looks modern and interesting. I'll try it next, maybe. In Vue CLI/UI you can also choose the testing framework. Angular could do the same thing it already does with CSS, SCSS, etc. Or for the first step: Allow removing the testing framework (Karma/Jasmine). Option in wizard: None or Karma/Jest. And later with Jest and Vitest and Mocha, etc. One of the first things I do on a new project is remove/replace Karma/Jasmine.
I just want to note that since this issue was opened we did publish a blog post describing our general unit testing strategy: https://blog.angular.dev/moving-angular-cli-to-jest-and-web-test-runner-ef85ef69ceca. I wanted to mention this for anyone just discovering this issue who wants to understand our current plans.
It's not exactly what @mgechev described in this issue, but it's pretty similar. Also just a friendly reminder that anyone can make their own Angular CLI builder today running any arbitrary unit test runner (such as Analog's Vitest builder).
I think what would be useful for this issue is to understand what developers would like to see beyond what's mentioned in that blog post which would make it easier to adopt alternative test runners.
π Feature request
Allow developers to select a unit testing framework similarly to
ng e2e
.Command (mark with an
x
)Description
Over the past few years we stopped shipping a linter by default and in v12 we enabled a plugin-based selection of an e2e testing framework similarly to
ng deploy
. At the same time, we've been getting lots of requests for Jest in the CLI and even mocha. The different tools have their trade-offs and even thoughkarma
allows real browser testing it's often outperformed byjest
.Describe the solution you'd like
Meet developers where they are and enable them to use the unit testing framework they want. Remove
karma
by default and instead changeng test
to output a list of available and supported options, such askarma
andjest
.Similarly to
ng e2e
andng deploy
we can recommend solutions which have high adoption and are maintained by the owner of the testing tool to provide guarantees for higher reliability.A challenge with this approach is that it gets harder to automatically generate a unit test for every generated component/directive/component/pipe. We'd like to enable testing vendors to plug into the corresponding generator so they can provide a template that we can use in
ng generate
to produce a dummy unit test.That's the open question as of right now, which will unblock us to provide flexibility while continuing to enforce best practices.