Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Adding code coverage using Istanbul #1307

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions build/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ const webpackConfig = require('./webpack.config')

const TEST_BUNDLER = './tests/test-bundler.js'

webpackConfig.module.rules.push({
enforce: 'post',
test: /\.js$/,
loader: 'istanbul-instrumenter-loader',
query: {
esModules: true
},
exclude: /(tests|node_modules|\.spec\.js$)/,
})

const karmaConfig = {
basePath: '../',
browsers: ['PhantomJS'],
singleRun: !argv.watch,
coverageReporter: {
reporters: [
{ type: 'text-summary' },
],
coverageIstanbulReporter: {
reports: argv.watch ? ['text-summary'] : ['html', 'lcovonly', 'text-summary'],
dir: 'build/coverage',
fixWebpackSourcePaths: true,
skipFilesWithNoCoverage: false
},
files: [{
pattern : TEST_BUNDLER,
Expand All @@ -19,7 +30,7 @@ const karmaConfig = {
included : true
}],
frameworks: ['mocha'],
reporters: ['mocha'],
reporters: ['mocha', 'coverage-istanbul'],
preprocessors: {
[TEST_BUNDLER]: ['webpack'],
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@
"file-loader": "^0.11.1",
"fs-extra": "^3.0.1",
"html-webpack-plugin": "^2.24.1",
"istanbul-instrumenter-loader": "^2.0.0",
"karma": "^1.7.0",
"karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.1",
"karma-phantomjs-launcher": "^1.0.4",
Expand Down
3 changes: 3 additions & 0 deletions tests/test-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ const changedTests = allTests.filter(path => {
return __karmaWebpackManifest__.indexOf(path) !== -1
})

const componentsContext = require.context('./../src', true, /\.(js)$/)
componentsContext.keys().forEach(componentsContext)

;(changedTests.length ? changedTests : allTests).forEach(testsContext)