Search code examples
vue.jsjestjstest-coverage

Jest test coverage for VueJS application with Nuxt


I have VueJS application written with NuxtJS. This setup causes that I have many files index.vue in different directories. When I run the testing suite with commend jest --no-cache --watch --coverage only 1 file index.vue has being picked up by coverage results.

my configuration of jest in package.json is:

"jest": {
    "transform": {
      "^.+.vue$": "vue-jest",
      "^.+.js$": "babel-jest"
    },
    "collectCoverage": true,
    "collectCoverageFrom": [
      "**/*.{js,vue}",
      "!**/node_modules/**"
    ],
    "coverageReporters": [
      "text"
    ],
    "setupTestFrameworkScriptFile": "jest-extended"
}

and results show only coverage for 1 index.vue file (even I have multiple of them as well other .vue files).

What configuration option I need to add to run coverage for all .vue files?


Solution

  • At a first sight, I would expect to see Jest's moduleFileExtensions config option in place like:

     "jest": {
        "moduleFileExtensions": ["js", "json", "jsx", "node", "vue"],
        // The rest of your config...
      }
    

    The option tells Jest which file extensions are used by the modules of your application.