Skip to content

Commit

Permalink
Merge pull request #3506 from camptocamp/coverage
Browse files Browse the repository at this point in the history
Use istanbul coverage tool int the webpack coverage
  • Loading branch information
sbrunner authored Feb 12, 2018
2 parents 9743207 + 1fe38d7 commit bc173ad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ jobs:
- make lint
- make check-examples-webpack
- if [ ${IS_HOME} = TRUE ]; then JOB=publish-examples buildtools/deploy.sh; fi
after_success:
- cat .build/coverage/lcov.info | node ./node_modules/coveralls/bin/coveralls.js

- stage: Build
env:
Expand Down
48 changes: 39 additions & 9 deletions karma-conf-webpack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');

var isDebug = process.argv.some(function(argument) {
return argument === '--debug';
return argument === '--debug';
});

const webpackMerge = require('webpack-merge');
Expand All @@ -10,6 +10,17 @@ let webpackConfig = commons.config;
webpackConfig = webpackMerge(webpackConfig, require('./buildtools/webpack.dev'));
webpackConfig = webpackMerge(webpackConfig, {
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.js$/,
use: {
loader: 'istanbul-instrumenter-loader' ,
options: { esModules: true }
},
enforce: 'post',
exclude: /node_modules|\.spec\.js$/,
}]
}
});

module.exports = function(config) {
Expand Down Expand Up @@ -38,7 +49,7 @@ module.exports = function(config) {
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: isDebug ? ['progress'] : ['progress', 'coverage'],
reporters: isDebug ? ['progress', 'coverage-istanbul'] : ['coverage-istanbul'],

// web server port
port: 9876,
Expand Down Expand Up @@ -68,13 +79,32 @@ module.exports = function(config) {
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

coverageReporter: {
includeAllSources: true,
dir : '.build/coverage/',
reporters: [
{type: 'lcov', subdir: './'},
{type: 'text-summary', subdir: './', file: 'coverage.txt'}
]
// any of these options are valid: https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-api/lib/config.js#L33-L39
coverageIstanbulReporter: {

// reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib
reports: isDebug ? ['lcovonly', 'text-summary', 'html'] : ['lcovonly', 'text-summary'],

// base output directory. If you include %browser% in the path it will be replaced with the karma browser name
dir: path.resolve(__dirname, '.build/coverage'),

// if using webpack and pre-loaders, work around webpack breaking the source path
fixWebpackSourcePaths: true,

// stop istanbul outputting messages like `File [${filename}] ignored, nothing could be mapped`
skipFilesWithNoCoverage: true,

// enforce percentage thresholds
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
thresholds: {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
global: { // thresholds for all files
statements: 40,
lines: 40,
branches: 25,
functions: 30,
}
}
}
});
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"googshift": "0.9.8",
"html-loader": "0.5.5",
"html-webpack-plugin": "2.30.1",
"istanbul-instrumenter-loader": "3.0.0",
"jasmine-core": "2.99.0",
"jquery": "3.3.1",
"jquery-datetimepicker": "2.5.17",
Expand All @@ -70,6 +71,7 @@
"karma": "2.0.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.1",
"karma-coverage-istanbul-reporter": "1.3.0",
"karma-jasmine": "1.1.1",
"karma-sourcemap-loader": "0.3.7",
"karma-webpack": "2.0.6",
Expand Down

0 comments on commit bc173ad

Please sign in to comment.