Skip to content

Commit

Permalink
Merge pull request #26 from andrewiggins/coverage
Browse files Browse the repository at this point in the history
Add code coverage reporting
  • Loading branch information
developit committed Apr 3, 2019
2 parents 4ae5ece + fb8b7fb commit 382cf9d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@ node_modules
*.log
package-lock.json
dist
build
build
coverage
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-istanbul": "^5.1.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-polyfill": "^6.26.0",
Expand All @@ -46,6 +47,7 @@
"jasmine-core": "^2.9.1",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-jasmine": "^1.1.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.32",
Expand Down
3 changes: 2 additions & 1 deletion src/cli.js
Expand Up @@ -15,7 +15,8 @@ let prog = sade('karmatic');
prog
.version(version)
.option('--files', 'Minimatch pattern for test files')
.option('--headless', 'Run using Chrome Headless', true);
.option('--headless', 'Run using Chrome Headless', true)
.option('--coverage', 'Report code coverage of tests', true);

prog
.command('run [...files]', '', { default: true })
Expand Down
16 changes: 14 additions & 2 deletions src/configure.js
Expand Up @@ -27,7 +27,9 @@ export default function configure(options) {
'karma-spec-reporter',
'karma-sourcemap-loader',
'karma-webpack'
];
].concat(
options.coverage ? 'karma-coverage' : []
);

const WEBPACK_CONFIGS = [
'webpack.config.babel.js',
Expand Down Expand Up @@ -109,7 +111,9 @@ export default function configure(options) {
basePath: cwd,
plugins: PLUGINS.map(require.resolve),
frameworks: ['jasmine'],
reporters: ['spec'],
reporters: ['spec'].concat(
options.coverage ? 'coverage' : []
),
browsers: [options.headless===false ? 'KarmaticChrome' : 'KarmaticChromeHeadless'],

customLaunchers: {
Expand All @@ -122,6 +126,14 @@ export default function configure(options) {
}
},

coverageReporter: {
reporters: [
{ type: 'text-summary' },
{ type: 'html' },
{ type: 'lcovonly', subdir: '.', file: 'lcov.info' }
]
},

formatError(msg) {
try {
msg = JSON.parse(msg).message;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/babel-loader.js
Expand Up @@ -17,7 +17,9 @@ export default function babelLoader(options) {
plugins: [
[require.resolve('babel-plugin-transform-object-rest-spread')],
[require.resolve('babel-plugin-transform-react-jsx'), { pragma: options.pragma || 'h' }]
]
].concat(
options.coverage ? require.resolve('babel-plugin-istanbul') : []
)
}
};
}

0 comments on commit 382cf9d

Please sign in to comment.