Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit b0dbfa5

Browse files
committed
Add coverage to browser tests
1 parent 3fa3b6c commit b0dbfa5

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

karma.conf.js

+33-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@ var webpack = require('webpack');
33

44
module.exports = function (config) {
55

6+
var runCoverage = process.env.COVERAGE === 'true';
7+
8+
var coverageLoaders = [];
9+
var coverageReporters = [];
10+
11+
if (runCoverage) {
12+
coverageLoaders.push({
13+
test: /\.js$/,
14+
include: path.resolve('modules/'),
15+
exclude: /__tests__/,
16+
loader: 'isparta'
17+
})
18+
19+
coverageReporters.push('coverage');
20+
}
21+
622
config.set({
723

824
browsers: [ 'Firefox' ],
925
frameworks: [ 'mocha' ],
10-
reporters: [ 'mocha' ],
26+
reporters: [ 'mocha' ].concat(coverageReporters),
1127

1228
files: [
1329
'test/index.js'
@@ -21,13 +37,20 @@ module.exports = function (config) {
2137

2238
webpack: {
2339
devtool: 'inline-source-map',
24-
entry: path.join(__dirname, 'test', 'index.js'),
2540
module: {
2641
preLoaders: [
2742
{
2843
test: /\.js$/,
29-
exclude: /node_modules/,
44+
exclude: [
45+
path.resolve('src/'),
46+
path.resolve('node_modules/')
47+
],
3048
loader: 'babel'
49+
},
50+
{
51+
test: /\.js$/,
52+
include: path.resolve('src/'),
53+
loader: 'isparta'
3154
}
3255
]
3356
}
@@ -36,5 +59,12 @@ module.exports = function (config) {
3659
webpackServer: {
3760
noInfo: true
3861
},
62+
63+
coverageReporter: {
64+
reporters: [
65+
{ type: 'text' },
66+
{ type: 'html', subdir: 'html' }
67+
]
68+
}
3969
});
4070
};

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
"expect": "^1.13.0",
3737
"history": "^1.13.1",
3838
"isparta": "^4.0.0",
39+
"isparta-loader": "^2.0.0",
3940
"karma": "^0.13.3",
4041
"karma-chrome-launcher": "^0.2.0",
42+
"karma-coverage": "^0.5.3",
4143
"karma-firefox-launcher": "^0.1.7",
4244
"karma-ie-launcher": "^0.2.0",
4345
"karma-mocha": "^0.2.0",

0 commit comments

Comments
 (0)