Set default launcher flags when I run ng test without additional arguments

1.2k views Asked by At

I need to pass custom argument to chrome in order to set locale: --lang en-US

I've done it using customLauncher. My src/karma.conf.js:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
    ],
    customLaunchers: {
      ChromeHeadlessLang: {
        base: 'ChromeHeadless',
        flags: [
          '--lang en-US', // ensure that the test works on all environments with the same locale
        ]
      }
    },
    browsers: ['Chrome'],
    ...
  });
};

And I can run it using

ng test --browsers ChromeHeadlessLang

However, I would like to use the lang flags by default, without specifying --browsers

ng test

Can I override the default flags, so that they are used when I run just ng test?

2

There are 2 answers

0
Mateusz Budzisz On

You can specify default values for all parameters of ng test inside angular.json

e.g.:

 "test": {
          "builder": "ngx-build-plus:karma",
          "options": {
            "codeCoverageExclude": ["src/*.ts"],
            "codeCoverage": true,

All available parameters: https://angular.io/cli/test

2
dave0688 On

You can override the default behavour of any script in your package.json. Just add it to your scripts object like this:

"scripts": {
        "ng": "ng",
        "test": "ng test --watch=false --whateverParamYouWantToAddHere",
    },