Search code examples
angularkarma-runnerangular15

Configure karma-firefox-launcher in Angular 15


Angular 15 comes with fewer configuration files than the previous versions, incl. karma.conf.js having been dropped. For running ng test --browsers=FirefoxHeadless under Angular 14, I used to configure karma.conf.js to require('karma-firefox-launcher') plugin.

How should this be done in Angular 15?

  • is it ok to copy over the full karma.conf.js from the previous Angular 14 project and add set "architect.test.options.karmaConfig" in angular.json to that karma.conf.js file?
  • or is there some other way to configure Karma plugins in angular.json directly, and would that be better?
  • and can Angular 15 still help me by generating an initial karma.conf.js?

(motivation: my build server executes ng test in a headless container, so for the sake of a simple build container configuration, I prefer FirefoxHeadless over the test runner's default browser)


Solution

  • In Angular 15 you can generate the missing config by doing ng generate config karma then modify it to your needs. This also automatically updates the angular.json config file for you.