Skip to content

Commit 2772516

Browse files
committed
Add code coverage reporting
1 parent 252e7e1 commit 2772516

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
*.log
33
package-lock.json
44
dist
5-
build
5+
build
6+
coverage

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"dependencies": {
3737
"babel-core": "^6.26.0",
3838
"babel-loader": "^7.1.2",
39+
"babel-plugin-istanbul": "^5.1.0",
3940
"babel-plugin-transform-object-rest-spread": "^6.26.0",
4041
"babel-plugin-transform-react-jsx": "^6.24.1",
4142
"babel-polyfill": "^6.26.0",
@@ -46,6 +47,7 @@
4647
"jasmine-core": "^2.9.1",
4748
"karma": "^2.0.0",
4849
"karma-chrome-launcher": "^2.2.0",
50+
"karma-coverage": "^1.1.2",
4951
"karma-jasmine": "^1.1.1",
5052
"karma-sourcemap-loader": "^0.3.7",
5153
"karma-spec-reporter": "0.0.32",

src/cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ let prog = sade('karmatic');
1515
prog
1616
.version(version)
1717
.option('--files', 'Minimatch pattern for test files')
18-
.option('--headless', 'Run using Chrome Headless', true);
18+
.option('--headless', 'Run using Chrome Headless', true)
19+
.option('--coverage', 'Report code coverage of tests', true);
1920

2021
prog
2122
.command('run [...files]', '', { default: true })

src/configure.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export default function configure(options) {
2727
'karma-spec-reporter',
2828
'karma-sourcemap-loader',
2929
'karma-webpack'
30-
];
30+
].concat(
31+
options.coverage ? 'karma-coverage' : []
32+
);
3133

3234
const WEBPACK_CONFIGS = [
3335
'webpack.config.babel.js',
@@ -109,7 +111,9 @@ export default function configure(options) {
109111
basePath: cwd,
110112
plugins: PLUGINS.map(require.resolve),
111113
frameworks: ['jasmine'],
112-
reporters: ['spec'],
114+
reporters: ['spec'].concat(
115+
options.coverage ? 'coverage' : []
116+
),
113117
browsers: [options.headless===false ? 'KarmaticChrome' : 'KarmaticChromeHeadless'],
114118

115119
customLaunchers: {
@@ -122,6 +126,14 @@ export default function configure(options) {
122126
}
123127
},
124128

129+
coverageReporter: {
130+
reporters: [
131+
{ type: 'text-summary' },
132+
{ type: 'html' },
133+
{ type: 'lcovonly', subdir: '.', file: 'lcov.info' }
134+
]
135+
},
136+
125137
formatError(msg) {
126138
try {
127139
msg = JSON.parse(msg).message;

src/lib/babel-loader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export default function babelLoader(options) {
1717
plugins: [
1818
[require.resolve('babel-plugin-transform-object-rest-spread')],
1919
[require.resolve('babel-plugin-transform-react-jsx'), { pragma: options.pragma || 'h' }]
20-
]
20+
].concat(
21+
options.coverage ? require.resolve('babel-plugin-istanbul') : []
22+
)
2123
}
2224
};
2325
}

0 commit comments

Comments
 (0)