angularkarma-jasminekarma-coverage

ng test --code-coverage-exclude not working


My use case is to generate coverage report for Angular project by excluding certain files, I've excluded those files in angular.json it's working as expected. However I'm looking to exclude them via ng test command

ng test project --source-map=false --browsers=Chrome --code-coverage --watch=true --progress=true --code-coverage-exclude=['projects/folder1/template1/**']

Above command isn't working.


Solution

  • As stated in Angular docs about Angular CLI, to specify array options to the CLI, the syntax is to provide the argument name and then the options separated by space. Hence your command would be

    ng test project --source-map=false --browsers=Chrome \
      --code-coverage --watch=true --progress=true \
      --code-coverage-exclude 'projects/folder1/template1/**'
    

    And you could add more arguments to --code-coverage-exclude by:

    1. Separating values with spaces
    ng test project \
      --code-coverage-exclude 'projects/folder1/template1/**' 'projects/folder1/template2/**'
    
    1. Repeating argument name / argument value pairs
    ng test project \
      --code-coverage-exclude 'projects/folder1/template1/**' \
      --code-coverage-exclude 'projects/folder1/template2/**'