Skip to content

Commit 2834c47

Browse files
committed
chore(*): setup coveralls.io
* code coverage activated by default on TRAVIS * coverage reports sent to coveralls at the end of the build Don't forget to add COVERALLS_REPO_TOKEN to travis env vars. Resources: * https://github.com/caitp/karma-coveralls * https://coveralls.zendesk.com/hc/en-us/articles/201769715-Javascript-Node
1 parent fb6c462 commit 2834c47

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ before_script:
1919
- npm run build-travis
2020
- "npm run serve-dist > /dev/null &"
2121
script:
22-
- echo "UNIT TESTS - via karma"
22+
- echo "UNIT TESTS - via karma - with code coverage"
2323
- npm test
2424
- echo "UNIT TESTS - via mocha"
2525
- npm run mocha
2626
- echo "END 2 END TESTS - via protractor / through SauceLabs"
2727
- npm run test-e2e -- --port 3000
28+
after_success:
29+
- cat ./build/reports/coverage/**/lcov.info | ./node_modules/.bin/coveralls

karma.conf.js

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// retrieve args
22
const argv = require('minimist')(process.argv.slice(2));
3-
const COVERAGE = argv.coverage === true;
3+
const TRAVIS = process.env.TRAVIS;
4+
const COVERAGE = argv.coverage === true || TRAVIS;// code coverage on by default on TRAVIS, or activated by flag --coverage
45

56
// the following env vars are used in webpack.config.js
67
process.env.UNIT_TEST = true;
@@ -10,14 +11,33 @@ const webpackConfig = require('./webpack.config');
1011
const log = require('npmlog');
1112
log.level = 'silly';
1213

13-
const reporters = ['mocha'];
14-
const coverageReporter_reporters = [
15-
{type: 'lcov', dir: './build/reports/coverage'}
14+
const plugins = [
15+
'karma-webpack',
16+
'karma-sinon',
17+
'karma-mocha',
18+
'karma-mocha-reporter',
19+
'karma-sourcemap-loader',
20+
'karma-chrome-launcher',
21+
'karma-phantomjs-launcher'
1622
];
23+
const reporters = ['mocha'];
24+
// default coverage reporter (we may want different reporters between local & CI)
25+
var coverageReporter = {
26+
reporters: [
27+
{type: 'lcov', dir: './build/reports/coverage'}
28+
]
29+
};
1730

1831
if (COVERAGE) {
1932
log.info('karma', 'COVERAGE mode enabled');
2033
reporters.push('coverage');
34+
plugins.push('karma-coverage');
35+
}
36+
if (COVERAGE && TRAVIS) {
37+
log.info('karma', 'TRAVIS mode - will send coverage reports to coveralls.io');
38+
reporters.push('coveralls');
39+
plugins.push('karma-coveralls');
40+
coverageReporter = { type: 'lcovonly', dir: './build/reports/coverage' };
2141
}
2242

2343
module.exports = function(config) {
@@ -48,26 +68,15 @@ module.exports = function(config) {
4868
noInfo: true //please don't spam the console when running in karma!
4969
},
5070

51-
plugins: [
52-
'karma-webpack',
53-
'karma-sinon',
54-
'karma-mocha',
55-
'karma-mocha-reporter',
56-
'karma-sourcemap-loader',
57-
'karma-chrome-launcher',
58-
'karma-phantomjs-launcher',
59-
'karma-coverage'
60-
],
71+
plugins: plugins,
6172

6273

6374
//babelPreprocessor: {
6475
// options: {
6576
// presets: ['airbnb']
6677
// }
6778
//},
68-
coverageReporter: {
69-
reporters: coverageReporter_reporters
70-
},
79+
coverageReporter: coverageReporter,
7180
reporters: reporters,
7281
port: 9876,
7382
colors: true,

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"karma-babel-preprocessor": "^6.0.1",
8989
"karma-chrome-launcher": "^0.2.3",
9090
"karma-coverage": "^0.5.5",
91+
"karma-coveralls": "^1.1.2",
9192
"karma-mocha": "^0.2.2",
9293
"karma-mocha-reporter": "^2.0.0",
9394
"karma-phantomjs-launcher": "^1.0.0",

0 commit comments

Comments
 (0)