vue测试覆盖范围Jest只检查进口

发布于 2025-02-12 02:08:10 字数 588 浏览 0 评论 0原文

我正在用jestvue-test-utils测试我的vue.js 2项目,测试效果很好,但是当我尝试测量该测试时,我有问题的覆盖范围.vue文件。

问题是,当我执行jest -Coverage时,我会在这些文件中获得100%的覆盖范围,但是如果我输入以检查哪个行覆盖范围,则只检查了进口量以获取了Jest Covery和代码号的其余部分(您可以在第二张图片中看到。)

”在此处输入图像描述“

“在此处输入映像说明”

I'm testing my vue.js 2 project with jest and vue-test-utils, the test works fine, but I've a problem when I try to measure the coverage of .vue files.

The problem is that when I execute jest --coverage I obtain 100% of coverage in those files, but if i enter to inspect which lines are coverage I see only the imports have been checked for Jest coverage and the rest of the code No (You can see that in the second picture.)

enter image description here

enter image description here

???? If you need more info please leave me a commend. Thanks

This is my package.json (only relevant info):

"scripts": {
  "test": "jest --coverage",
 },
"dependencies": {
    "core-js": "3.20.3",
    "single-spa-vue": "2.5.0",
    "systemjs-webpack-interop": "2.3.7",
    "vue": "2.6.14",
    "vue-i18n": "8",
    "vue-router": "3.5.2"
  },
"devDependencies": {
    "@vue/cli-plugin-unit-jest": "~4.5.19",
    "@vue/cli-service": "~4.5.19",
    "@vue/test-utils": "^1.3.0",
    "babel-jest": "^26.6.3",
    "jest": "^26.6.3",
    "jest-junit": "^13.0.0",
    "jest-transform-stub": "^2.0.0"
}

And my `jest.config.js`:


    ```
const alias = require("./aliases.config");

module.exports = {
  moduleFileExtensions: ["js", "vue", "json"],
  transform: {
    "^.+\\.js
quot;: "babel-jest",
    "^.+\\.vue
quot;: "vue-jest",
    ".+\\.(css|styl|less|sass|scss|jpg|jpeg|png|svg|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|avif)
quot;:
      "jest-transform-stub",
  },
  preset: "@vue/cli-plugin-unit-jest",
  testPathIgnorePatterns: ["/node_modules/"],
  modulePathIgnorePatterns: ["/node_modules/"],
  testMatch: ["**/tests/unit/**/*.(unit|test|spec).js"],
  collectCoverage: false,
  collectCoverageFrom: [
    "<rootDir>/src/**/*.{vue,js}",
    "!<rootDir>/src/main.js",
    "!<rootDir>/src/set-public-path.js",
    "!<rootDir>/src/router/index.js",
  ],
  coverageDirectory: "reports/unit-reports/coverage",
  coverageReporters: ["text-summary", "html", "cobertura"],
  moduleNameMapper: {
    ...alias.forJest,
    "@divilo/styleguide-base-front":
      "<rootDir>/tests/mocks/styleguide-base-front.js",
    "@divilo/api-mfes-front": "<rootDir>/tests/mocks/api-mfes-front.js",
  },
  coverageProvider: "babel",
  coverageThreshold: {
    global: {
      branches: 80,
      functions: 80,
      lines: 80,
      statements: -10,
    },
  },
  reporters: [
    "default",
    [
      "jest-junit",
      {
        outputDirectory: "reports/unit-reports/tests",
        outputName: "junit.xml",
      },
    ],
  ],
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文