1

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?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Liero
  • 25,216
  • 29
  • 151
  • 297

2 Answers2

0

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",
    },
dave0688
  • 5,372
  • 7
  • 33
  • 64
  • I know, but most angular developers just run `ng test` not `npm run test`, because that is how the angular docs mentions it. Anyway, it does not answer the question – Liero Oct 24 '19 at 09:09
  • It depends on what you use as package manager. For `npm` yes you're right. In my project I use `yarn`. You can then directly call `yarn test` and it will execute the script from `package.json`. Unfortunately `npm` is a bit dumb in that sense. – dave0688 Oct 24 '19 at 09:13
0

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

Mateusz Budzisz
  • 598
  • 7
  • 15