使用NYC和基于JEST的E2E测试框架的NYC覆盖不正确的代码覆盖范围

发布于 2025-01-28 11:15:25 字数 711 浏览 5 评论 0原文

我正在尝试为单个E2E测试用例生成代码覆盖范围。这是我为实现这一目标所做的。

  1. 使用NYC与E2E测试案例有关的仪器文件。请注意,我在此处使用了仪器
  2. 执行的测试用例。
  3. 使用窗口.__覆盖范围__存储的覆盖范围报告 .nyc_output/coverage.json 。
  4. 使用NYC报告生成的报告-Reporter = LCOV -REPORTER = TEXT命令。创建的Coverage文件夹

我可以看到它显示了分支,线语句仪器代码的功能。实际上,它应该显示语句,原始代码的行。

这是我的NYCRC文件。

 {
  "extends": "nyc-config-tsx",
  "exclude": [
    "**/*.test.tsx",
    "**/*.mock.tsx",
    "**/*.test.ts",
    "**/*.mock.ts"
  ],
  "extension": [
    ".js",
    ".ts",
    ".jsx",
    ".tsx"
  ],
  "exclude-after-remap": false,
  "all": true,
  "cache": false,
  "source-map": true,
  "produce-source-map": true
}

I am trying to generate code coverage for the single e2e test case. Here is what I did to achieve this.

  1. Instrumented files related to e2e test case using nyc. Note here I used in place instrumentation
  2. Executed test cases.
  3. stored coverage report using window.__coverage__ into .nyc_output/coverage.json.
  4. generated report using nyc report --reporter=lcov --reporter=text command. created coverage folder

I can see that its showing branches , lines statements functions of instrumented code. Actually it should show statement , lines of original code.

Here is my nycrc file.

 {
  "extends": "nyc-config-tsx",
  "exclude": [
    "**/*.test.tsx",
    "**/*.mock.tsx",
    "**/*.test.ts",
    "**/*.mock.ts"
  ],
  "extension": [
    ".js",
    ".ts",
    ".jsx",
    ".tsx"
  ],
  "exclude-after-remap": false,
  "all": true,
  "cache": false,
  "source-map": true,
  "produce-source-map": true
}

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

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

发布评论

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