使用Nuxt对VueJS应用程序进行Jest测试覆盖

ben*_*siu 6 test-coverage vue.js jestjs

我有用NuxtJS编写的VueJS应用程序.这个设置导致我在不同的目录中有很多文件index.vue.当我运行测试套件时,jest --no-cache --watch --coverage仅推荐1个文件index.vue已被覆盖结果选中.

我在package.json中的jest配置是:

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

并且结果显示仅覆盖1个index.vue文件(即使我有多个以及其他.vue文件).

我需要添加哪些配置选项来运行所有.vue文件的覆盖范围?

And*_*aro 4

乍一看,我希望看到 Jest 的moduleFileExtensions config option位置如下:

 "jest": {
    "moduleFileExtensions": ["js", "json", "jsx", "node", "vue"],
    // The rest of your config...
  }
Run Code Online (Sandbox Code Playgroud)

该选项告诉 Jest 您的应用程序的模块使用哪些文件扩展名。