Angular-cli: Test-coverage says that coverage is not 100%, but it truly is!

Created on 7 Apr 2017  ·  16Comments  ·  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.0.0
node: 6.9.5
os: darwin x64
@angular/animations: 4.0.1
@angular/common: 4.0.1
@angular/compiler: 4.0.1
@angular/core: 4.0.1
@angular/forms: 4.0.1
@angular/http: 4.0.1
@angular/platform-browser: 4.0.1
@angular/platform-browser-dynamic: 4.0.1
@angular/platform-server: 4.0.1
@angular/router: 4.0.1
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.1

Repro steps.


Upgrade your 100% tested angular 2.4.8 app to 4.0.1, along with Angular CLI 1.0.0

The log given by the failure.


There's no actual failure (stacktrace thown), but the behaviour of the text-coverage is wrong. I'm hitting every line, statement, branch and function of the code, but coverage does not "cover" constructor signature.

Desired functionality.


The test coverage should be 100%, and was until I upgraded from Angular 2.4.8 (CLI 1.0.0 RC.0) to Angular 4.01 (CLI 1.0.0).

Before
before

After
after

Coverage error (example)
example

Mention any other details that might be useful.

My karma.conf.js file looks like:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma'),
      require('karma-spec-reporter'),
      require('karma-appveyor-reporter')
    ],
    files: [
      {pattern: './src/test.ts', watched: false}
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },
    mime: {
      'text/x-typescript': ['ts', 'tsx']
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly', 'text' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
      ? ['spec', 'coverage-istanbul', 'appveyor']
      : ['spec', 'appveyor'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

I'm unfortunately not permitted to share the code-base, since it's a closed source, propriatary product I'm working on. I can however provide you with various configuration files. So, do not refrain from asking for these.

easy (hours) investigation 2 (required) confusing

Most helpful comment

@rg1220

Well, not exactly... since we're not only experiencing it in constructors, but also in class parameters.

All 16 comments

We have the same problem on this opensource project: https://gitlab.com/linagora/petals-cockpit (at commit 78c6928e4f78279a2a105fe357981a6cff88da21).

Same issue here, certain constructor params are marked as 'branch not covered'. Same code / tests run against previous versions of the CLI report 100% coverage.

Unfortunately I have the same. Even 4 issues in one constructor :(

:+1: having the same problem

👍 encountered same issue

At one point we switched the karma code-coverage plugin, that might be related.

Same problem

Same issue but I'm looking into the matter. Will start looking at what exactly the karma plugin is doing.

fix it please :)

Because of that reason, I'm using newest ng, but replacing karma.conf with karma-remap-istanbul setup (like it was before we switched to code-coverage plugin).

It's not silver bullet, the issue is still present in setup with karma-remap-istanbul, but with less branches reported as not-tested.

+1 Having the same issue in several places:

screen shot 2017-07-02 at 8 55 13 am

screen shot 2017-07-02 at 8 54 40 am

screen shot 2017-07-02 at 8 56 24 am

@rg1220

Well, not exactly... since we're not only experiencing it in constructors, but also in class parameters.

I am also unable to cover 100% code coverage due to this problem. Will wait until it will be pushed into later version.

currently using 1.1.0

  constructor(private elementRef: ElementRef, private tagApi: TagApi, private tagTypeApi: TagTypeApi,
              private businessObjectDefinitionTagApi: BusinessObjectDefinitionTagApi) {
  }

these two properties are not covered expect everything else is fine.
_private tagApi: TagApi, private tagTypeApi: TagTypeApi,_

Going to close this one as duplicate of #5526, they are the same and the other one has a lot more info on the problem.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings