How to configure code coverage for .vue files?

602 views Asked by At

I'm using mocha for unit testing and want to add code coverage. For that I added nyc, istanbul-instrumenter-loader and babel-plugin-istanbul and it works for js files but for .vue files an error occurs: "TypeError: Cannot read property 'fileCoverage' of undefined". Please help me

package.json

{
"name": "ZINGUI",
"version": "1.0.0",
"description": "ZINGWHEEEE",
"author": "John Matos <[email protected]>",
"private": true,
"browserslist": [
    "defaults"
],
"workspaces": [
    "packages/z-common",
    "packages/z-search",
    "packages/z-ui",
    "packages/z-admin-module",
    "packages/z-smartviewz-module",
    "packages/z-theme",
    "packages/z-dashboard-module",
    "packages/z-dashboard-base-tiles",
    "packages/z-events-module",
    "packages/z-user-module",
    "packages/z-mock-client",
    "packages/z-catalog"
],
"scripts": {
    "dev": "yarn run z-ui",
    "z-ui": "yarn run --cwd=packages/z-ui dev",
    "watch": "node scripts/watch.js",
    "build": "npm-run-all lint test build-ui",
    "build-ui": "yarn run --cwd=packages/z-ui build",
    "lint": "yarn workspaces run lint",
    "test": "yarn workspaces run test",
    "test:coverage": "nyc yarn run test",
    "bootstrap": "yarn install",
    "clean": "yarn workspaces run clean && rm -rf node_modules",
    "add-package": "cd packages && vue init ../scripts/package-template",
    "playground": "yarn run --cwd=playground playground",

},
"dependencies": {
    "@vue/composition-api": "^0.3.4",
    "atob": "^2.1.0",
    "cryptiles": "^4.1.2",
    "dot-prop": "^4.2.1",
    "fstream": "^1.0.12",
    "graphql": "^0.13.2",
    "sshpk": "^1.13.2",
    "stringstream": "^0.0.6",
    "vue": "^2.6.6",
    "vue-router": "3.0.1",
    "vuetify": "2.4.0",
    "vuex": "^3.5.1",
    "clone": "^2.1.2",
    "cookies-js": "^1.2.3",
    "d3": "^5.7.0",
    "d3-format": "^1.4.3",
    "deep-equal": "^2.0.1",
    "deepmerge": "^4.2.2",
    "graphql-tag": "^2.10.3",
    "humanize": "^0.0.9",
    "humanize-duration": "^3.22.0",
    "moment": "^2.24.0",
    "throttle-debounce": "^2.2.1",
    "yamr-js": "zenoss/yamr-js#4.6.2",
    "z-admin-module": "^1.0.0",
    "z-catalog": "^1.0.0",
    "z-common": "^1.0.0",
    "z-dashboard-module": "^1.0.0",
    "z-events-module": "^1.0.0",
    "z-mock-client": "^1.0.0",
    "z-search": "^1.0.0",
    "z-smartviewz-module": "^1.0.0",
    "z-theme": "^1.0.0",
    "z-user-module": "^1.0.0",
    "z-in-time": "zenoss/z-in-time#1.1.7"
},
"devDependencies": {
    "chai-sorted": "^0.2.0",
    "backstopjs": "^4.5.0",
    "babel-plugin-istanbul": "^6.0.0",
    "chai": "^4.1.2",
    "core-js": "3",
    "chokidar": "^2.0.1",
    "eslint": "^4.19.1",
    "eslint-config-airbnb-base": "^13.0.0",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-import-resolver-webpack": "^0.8.3",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-import": "^2.20.0",
    "eslint-plugin-vue": "^6.2.2",
    "eslint-plugin-vuetify": "^1.0.0-beta.7",
    "inject-loader": "^4.0.1",
    "istanbul-instrumenter-loader": "^3.0.1",
    "jsdom": "^11.12.0",
    "jsdom-global": "^3.0.2",
    "mocha": "^5.2.0",
    "mocha-webpack": "2.0.0-beta.0",
    "npm-run-all": "^4.1.2",
    "nyc": "^15.1.0",
    "sinon": "^6.1.4",
    "sinon-chai": "^3.2.0",
    "webpack-merge": "^4.1.0",
    "webpack-node-externals": "^1.7.2",
    "yargs": "^15.1.0"
}

}

.babelrc

{
  "env": {
    "development": {
      "presets": [
        ["env", { "modules": false }],
        "stage-3"
      ]
    },
    "production": {
      "presets": [
        ["env", { "modules": false }],
        "stage-3"
      ]
    },
    "test": {
      "presets": [
        ["env", {
          "modules": false,
          "targets": { "node": "current" }
        }],
        "stage-3"
      ],
        "plugins": [
            ["istanbul", {
                "exclude": [
                    "**/*.spec.js"
                ]
            }]
        ]
    }
  }
}

webpack.base.conf.js

            {
            test: /\.js$|\.vue$/,
            use: {
                loader: "istanbul-instrumenter-loader",
                options: { esModules: true }
            },
            enforce: 'post',
            exclude: /node_modules|\.spec\.js$/
        }
0

There are 0 answers