Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage reporting #26

Merged
merged 2 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
*.log
package-lock.json
dist
build
build
coverage
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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') : []
)
}
};
}