Coverage seems to be incorrect
RobbieTheWagner opened this issue · 7 comments
I am using karma-coverage and I am getting like 98%+ coverage on all of my files and I know my tests don't exercise that much of the code. Any idea why the coverage is falsely high?
It's like it's only reporting for what the tests run for and not the remainder of the JS in each file.
I'm using this
https://github.com/ColCh/isparta-instrumenter-loader
I got the same problem, some of my components (it's a react app) are 100% covered but are not even used in the tests?
// Karma configuration
// Generated on Sun Sep 13 2015 12:16:34 GMT+0800 (SGT)
var webpack = require("webpack"),
path = require("path");
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
'./test/**/*.js'
],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"./test/**/*.js": ["webpack"]
},
webpack: {
module: {
preLoaders: [
{
test: /\.js?$/,
exclude: /(test|node_modules)/,
loader: 'isparta-instrumenter-loader'
}
],
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules)/,
loader: 'babel'
},
{
test: /\.scss$/,
loader: 'style!css!sass'
},
{
test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/,
loader: 'url-loader?limit=30000&name=[name]-[hash].[ext]'
},
]
},
plugins: [],
resolve: {}
},
webpackMiddleware: {
noInfo: true
},
plugins: [
require("karma-webpack"),
require("karma-jasmine"),
require("karma-junit-reporter"),
require("karma-coverage"),
require("karma-phantomjs-launcher")
],
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'junit', 'coverage'],
coverageReporter: {
type: 'cobertura',
dir: 'reports',
subdir: './'
},
junitReporter: {
outputDir: 'reports', // results will be saved as $outputDir/$browserName.xml
outputFile: '', // if included, results will be saved as $outputDir/$browserName/$outputFile
suite: '' // suite will become the package name attribute in xml testsuite element
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
})
};
I'm closing this for now. Feel free to reopen it if you still have this issue.
I also have the same problem with a similar setup, components that have no unit tests yet being reported as 100% coverage
Are you guys looking for the --include-all-sources
flag?
--include-all-sources
instrument all unused sources after running tests, defaults to false
I still have this issue (browserify-istanbul 0.2.1 and istanbul 0.3.22). @jedmao how can I use that option with browserify-istanbul
?
@carneiror I've never used browserify-istanbul, so I couldn't tell you, but I would just refer you to their documentation. However you can provide istanbul options.
I fixed my problem and now isparta is working perfectly fine. Basically, in my webpack config, I was using the "exclude" keyword to select the files to "pack" then I replaced by "include" instead.
include: [path.resolve(__dirname, 'src')],