karma-coverage icon indicating copy to clipboard operation
karma-coverage copied to clipboard

coverage report includes actual tests

Open meg2208 opened this issue 10 years ago • 4 comments

The issue I am having is that the coverage report counts the actual test spec files. Thus, the total lines covered is significantly skewed. What do I have to change in the coverageReporter config to specify paths to ignore in the coverage report without having it not run the tests themselves?

Happy to provide a sample of my config or other info if need be.

thanks!

meg2208 avatar Sep 28 '15 19:09 meg2208

I also have this issue as I have my test files along side the source code rather than in their own directory.

mderrick avatar May 18 '16 11:05 mderrick

https://github.com/karma-runner/karma-coverage/blob/master/docs/configuration.md#check

Check the 'excludes' array here, that should do what you're talking about. While it excludes these files from the total %, I still haven't figured out how to get those files to not display in the table that's printed out when I use type 'text'. Hope this helps you out a little bit at least, though

Cojomax99 avatar May 19 '16 21:05 Cojomax99

@meg2208 make sure your patter for preprocessing src file does not include any test files: preprocessors: { 'src/**/*.js': ['coverage'] },

Post your preprocessors config here, along with paths to source files and test files in your project.

mrt123 avatar Jul 11 '16 13:07 mrt123

I'm also seeing the issue. Coverage includes test files and source files.

Path to source file: src Path to test files: browser-test

Here is my config file:

module.exports = function(config) {
    config.set({
        browsers: ['Safari', 'Chrome', 'Firefox'],
        files: ['browser-test/**/*.js'],
        frameworks: ['browserify', 'mocha', 'events'],
        preprocessors: {
          'browser-test/**/*.js': ['browserify'],
          'src/**/*.js': ['coverage'],
        },
        reporters: ['mocha', 'coverage'],
        singleRun: true,

        browserify: {
            debug: true,
            transform: [
              ['babelify', {
                "babelrc": false,
                "plugins": [
                  "istanbul"
                ],
                "presets": [
                  ["@babel/env", {
                    "targets": {
                      "firefox": 60
                    }
                  }]
                ]
              }]
            ]
        },

        coverageReporter: {
          type : 'lcov',
          dir : 'coverage/',
          includeAllSources: true
        },

        client: {
            mocha: {
                grep: '@nodeonly',
                invert: true
            }
        },

        events: {
          events: {
            run_start: 'npm run start-test-server',
            run_complete: 'npm run stop-test-server'
          }
        }

    });
};

palanik avatar Jun 04 '19 18:06 palanik