I have been trying for hours now to get the istanbul code coverage reports up and running for my new vue (typescript based) project, generated with the vue-cli v3.
Whenever I run my tests: (nodemon --exec nyc vue-cli-service test:unit
) only the .ts files are included, even though I have specificly set that nyc should include those files:
Package.json
"nyc": {
"check-coverage": true,
"per-file": true,
"lines": 80,
"instrument": true,
"sourceMap": true,
"statements": 80,
"functions": 80,
"branches": 80,
"include": [
"apollo-server/**/*.{ts,vue}",
"apollo-server/*.vue",
"src/**/*.{ts,vue}",
"src/*.vue"
],
"exclude": [
],
"reporter": [
"lcov",
"text",
"text-summary"
],
"extension": [
".ts",
".vue"
],
"cache": true,
"all": true
}
I have also tried setting nyc.instrument
and nyc.sourceMap
to false in order to allow a custom loader in the webpack configuration like so:
Vue.config.js
module.exports = {
baseUrl: process.env.NODE_ENV === 'production'
? '/'
: '/',
configureWebpack: config => {
// if (process.env.NODE_ENV === "coverage") {
config = Object.assign(config, {
module: Object.assign(config.module, {
rules: config.module.rules.concat([
{
test: /\.(ts|tsx|vue)$/,
enforce: 'post',
include: [
path.resolve('src'),
path.resolve('apollo-server')
],
loader: 'istanbul-instrumenter-loader'
}
])
})
})
// }
}
I have also tried doing this using the vue.config.js > chainWebpack
hook and when using a vue config instead of the package.json it results in no files being included at all:
Vue.config.js with chainWebpack instead of configureWebpack
chainWebpack: config => {
if (process.env.NODE_ENV === "coverage") {
config.module
.rule("istanbul")
.test(/\.(ts|tsx|vue)$/)
.enforce("post")
.pre()
.include
.add(__dirname + "/apollo-server")
.add(__dirname + "/src")
.end()
.use("istanbul-instrumenter-loader")
.loader("istanbul-instrumenter-loader")
.options({
esModules: true
})
.end()
}
}
It might be due to the __dirname + [filename]
I am using in this config, though I have no idea what else it should be. I was doing this based on this link: https://github.com/vuejs/vue-cli/issues/1363, where I was supposed to add 'src'
, though it results in an error stating that the included paths are not absolute.