istanbuljs / babel-plugin-istanbul

A babel plugin that adds istanbul instrumentation to ES6 code
BSD 3-Clause "New" or "Revised" License
624 stars 73 forks source link

All tests passing but statements are ignored #237

Open AlexisLagniel opened 4 years ago

AlexisLagniel commented 4 years ago

Hi, I do have an issue on my project while trying to update to 6.0

The first part of my application is working as expected and the change to 6.0 had no impact

However, on the second part of my application, all my tests are passing but for some reason it looks like a lot of statements, branches functions and lines are ignored, for instance, this is what I should have

image

But this is what I get image

I can't quite find out why so many are not being considered when all checks are made.

Configuration:

I am using Karma to perform the test coverage, below is what I am using "test:coverage": "cross-env BABEL_ENV=test karma start --single-run"

My karma.conf.js:

  config.set({
    frameworks: ['mocha'],

    files: ['tests/**/*.spec.js'],

    preprocessors: {
      '**/*.spec.js': ['webpack', 'sourcemap'],
    },

    webpack: webpackConfig,

    reporters: ['spec', 'coverage'],
    // these options are here to fix https://github.com/cormoran-io/mitrust-backend/issues/2455
    // https://discuss.circleci.com/t/fontconfig-error-on-node-10-browsers/29029/7
    disable_watching: true,
    launch_in_ci: ['Chrome'],
    launch_in_dev: ['Chrome'],
    browser_args: {
      Chrome: {
        mode: 'ci',
        args: [
          // --no-sandbox is needed when running Chrome inside a container
          process.env.CI ? '--no-sandbox' : null,
          '--disable-gpu',
          '--remote-debugging-port=0',
          '--window-size=1440,900',
          '--headless',
          // https://github.com/GoogleChrome/puppeteer/issues/3774
          // adding this parameter to chrome to fix https://github.com/cormoran-io/mitrust-backend/issues/2455
          '--disable-features=VizDisplayCompositor',
        ].filter(Boolean),
      },
    },
    coverageReporter: {
      dir: './tests/coverage',
      reporters: [{ type: 'lcov', subdir: '.' }, { type: 'text-summary' }],
      check: {
        global: {
          statements: 50,
          branches: 40,
          functions: 50,
          lines: 50,
        },
      },
    },
    browsers: ['Chrome'],
  });
};

Thanks!

coreyfarrell commented 4 years ago

I don't know much about karma but I don't think any of the karma components have updated to the latest istanbuljs modules yet. Might be best to stick with nyc 14 / babel-plugin-istanbul 5.x until the karma plugin updates (only the production dependencies matter). I've seen issues caused by mixing previous and current versions of istanbul modules.

maogongzi commented 4 years ago

I've encountered the same kind of issue in my project, after I upgrade babel-plugin-istanbul from 5.1.0 to 6.0.0, all my Vue SFC component coverage is gone, only left some js modules, finally I downgrade it to 5.2.0 and I can see the Vue components come back again.

coreyfarrell commented 4 years ago

@maogongzi please post a new issue including a link to a repository demonstrating the issue. It could be a simple issue that 6.0.0 needs to be reconfigured or you could have conflicts between multiple components.