Skip to content

Commit f5f8c4f

Browse files
author
Rija Menage
committed
Setup coverage more correctly with karma-coverage, babel-plugin-istanbul
Now there is a proper babel config file (babel.config.js) where the istanbul plugin is mentioned for the test environment only. Which means that I need the cross-env package to be able to specify to karma command which babel environment to pass. Now that babel has a config file the loader rule in webpack config file can be simpler The coverage report is still odd (I think code instrumentation may not happen properly), but at least the configuration is in a better state than before
1 parent 3a29246 commit f5f8c4f

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

babel.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = function (api) {
2+
3+
console.log('********** Loading Babel config ***************************');
4+
api.cache(true);
5+
6+
const presets = [ '@babel/preset-env' ];
7+
// const plugins = [ 'istanbul' ];
8+
9+
return {
10+
presets,
11+
"env": {
12+
"test": {
13+
"plugins": ["istanbul"]
14+
}
15+
}
16+
};
17+
}

karma.conf.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ module.exports = function(config) {
88
frameworks: ['jasmine'],
99

1010
files: [
11-
// 'test/**/*.spec.js'
1211
'test/testloader.js'
1312
],
1413

1514
// preprocess matching files before serving them to the browser
1615
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
17-
preprocessors: {
18-
// '**/*.spec.js': ['webpack']
16+
preprocessors: { //do not add 'coverage' here, as code already instrumented in babel plugin
17+
'src/**/*.js': ['webpack'],
1918
'test/testloader.js': ['webpack']
2019
},
2120

2221
webpack: webpackConfig,
2322

24-
reporters: ['spec'],
23+
reporters: ['spec', 'coverage'],
2524

2625
coverageReporter: {
2726
dir: './coverage',

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
"@vue/test-utils": "^1.0.0-beta.30",
1616
"babel-loader": "^8.0.6",
1717
"babel-plugin-istanbul": "^5.2.0",
18+
"cross-env": "^6.0.3",
1819
"css-loader": "^3.3.2",
1920
"jasmine-core": "^3.5.0",
2021
"karma": "^4.4.1",
2122
"karma-chrome-launcher": "^3.1.0",
23+
"karma-coverage": "^2.0.1",
2224
"karma-firefox-launcher": "^1.2.0",
2325
"karma-jasmine": "^2.0.1",
2426
"karma-spec-reporter": "0.0.32",
@@ -29,7 +31,7 @@
2931
"webpack-cli": "^3.3.10"
3032
},
3133
"scripts": {
32-
"test": "karma start --no-watch --no-progress",
34+
"test": "cross-env BABEL_ENV=test karma start --no-watch --no-progress",
3335
"build": "webpack"
3436
},
3537
"author": "Rija Menage",

webpack.config.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ module.exports = {
2020
]
2121
},
2222
{
23-
test: /\.m?js$/,
24-
exclude: /(node_modules|bower_components)/,
25-
use: {
26-
loader: 'babel-loader',
27-
options: {
28-
presets: ['@babel/preset-env']
29-
}
30-
}
23+
test: /\.js$/,
24+
loader: 'babel-loader',
25+
exclude: /node_modules/
3126
}
3227
]
3328
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy