karma-runner / karma-runner/karma-coverage

Coverage is off (karma-coverage, browserify-istanbul)

Open
#361 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
771
Forks
242
PR merge metrics
No merged PRs in 30d

Description

I'm running vue unittests using karma, phantomjs, jasmine and vue/test-utils. The unittests run fine and as expected. However, the coverage seems to be off. I am for example triggering button clicks and expect the functions that are called from that button click to be covered, but they aren't. Instead really random stuff like which type a prop is (String, for example) gets covered. I'm not sure if this is an issue with karma-coverage or if I'm using it wrong somehow. All suggestions are appreciated :). My karma.conf.js looks like this:

```
module.exports = function(config) {

var doVueify = require('vueify');
var doBabelify = require('babelify');
var doCover = require('browserify-istanbul');

var coverOptions = {
ignore: ['tests/my_project/**/*.js'],
defaultIgnore: true
}

config.set({

basePath: '',

frameworks: ['jasmine', 'browserify'],

browserify: {
debug: true,
extensions: [".js", ".vue"],
configure: function(bundle){
bundle.on('prebundle', function(){
bundle
.transform(doBabelify)
.transform(doVueify)
.transform(doCover(coverOptions));
});
}
},

files: [
'node_modules/es6-promise/dist/es6-promise.js',
'node_modules/whatwg-fetch/fetch.js',
'tests/my_project/**/*.js'
],

preprocessors: {
'tests/my_project/**/*.js': ['browserify']
},

reporters: ['spec', 'coverage'],

coverageReporter: {
dir: 'reports/coverage/javascript',
includeAllSources: true,
reporters: [
{ type : 'cobertura', subdir: '.', file: 'cobertura.xml' },
{ type : 'lcov', subdir: '.' },
{ type: 'text-summary' }
]
},

junitReporter: {
outputFile: 'reports/test-results.xml',
useBrowserName: false
},

port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
})
}
```

And my package.json like this

```
"devDependencies": {
"@mapbox/stylelint-processor-arbitrary-tags": "^0.2.0",
"@vue/test-utils": "^1.0.0-beta.13",
"ajv": "^5.3.0",
"autoprefixer": "^7.1.4",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babelify": "^8.0.0",
"browserify-istanbul": "^3.0.1",
"eslint": "^4.17.0",
"eslint-plugin-vue": "4.3.0",
"es6-promise": "^2.3.0",
"grunt": "^1.0.2",
"grunt-browserify": "^5.2.0",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-less": "^1.4.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^20.1.0",
"grunt-postcss": "^0.9.0",
"grunt-stylelint": "^0.9.0",
"jasmine": "^2.5.3",
"karma": "^2.0.0",
"karma-browserify": "^5.3.0",
"karma-cli": "^1.0.1",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.1",
"karma-junit-reporter": "^1.2.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-spec-reporter": "0.0.32",
"karma-sourcemap-loader": "^0.3.7",
"stylelint": "^8.2.0",
"stylelint-config-standard": "^17.0.0",
"vueify": "^9.4.1"
},
"dependencies": {
"@fortawesome/fontawesome": "^1.1.5",
"@fortawesome/fontawesome-free-solid": "^5.0.10",
"@fortawesome/vue-fontawesome": "0.0.22",
"core-js": "^2.5.3",
"normalize.css": "^7.0.0",
"pikaday": "^1.6.1",
"v-tooltip": "^2.0.0-rc.32",
"vue": "^2.5.13",
"whatwg-fetch": "^2.0.4"
},
"browser": {
"vue": "vue/dist/vue.common.js"
},
"scripts": {
"test": "npm run test:browser",
"test:browser": "karma start --single-run --browsers PhantomJS",
"test:ci": "npm run test:browser -- --reporters spec,coverage,junit"
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the supplied karma.conf.js, especially the Browserify transforms, browserify-istanbul options, and coverageReporter settings; then compare the relevant versions in package.json. Reproduce the PhantomJS run with the Vue unit tests and determine whether instrumentation or source-map handling causes click-triggered functions to be omitted. Done means coverage reports the expected application functions rather than unrelated prop-type code.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.