@cypress/code-coverage attempts to collect back-end coverage when we are not running end-to-end tests

未关闭
#473 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
cypress, typescript
领域
testing-qa

调研方向

Issue 指向第 168-172 行的 support.js,并提出了 PR #474;首先检查该逻辑以及现有的 expectBackendCoverageOnly 配置。在启用 expectFrontendCoverageOnly 时,确认 integration specs 的行为,同时保持当前的端到端行为不变。完成标准是:在这种情况下,插件不会尝试访问缺失的 /coverage URL。

由索引模型根据 Issue 内容生成。

描述

Logs and screenshots

code-coverage combined NYC options { 'report-dir': './coverage', reporter: [ 'lcov', 'json-summary', 'text', 'cobertura' ], extension: [ '.jsx', '.js' ], excludeAfterRemap: false, sourceMap: false, instrument: false } +0ms
code-coverage reset code coverage in interactive mode +0ms
code-coverage reset code coverage in interactive mode +2s
code-coverage parsed sent coverage +8s
code-coverage wrote coverage file /Users/nyee2/dev/plugins/campaign-manager-web-plugin/.nyc_output/out.json +30ms
code-coverage parsed sent coverage +721ms
code-coverage wrote coverage file /Users/nyee2/dev/plugins/campaign-manager-web-plugin/.nyc_output/
code-coverage parsed sent coverage +2s
code-coverage wrote coverage file /Users/nyee2/dev/plugins/campaign-manager-web-plugin/.nyc_output/out.json +61ms
code-coverage parsed sent coverage +915ms
code-coverage wrote coverage file /Users/nyee2/dev/plugins/campaign-manager-web-plugin/.nyc_output/out.json +54ms
code-coverage parsed sent coverage +799ms
code-coverage wrote coverage file /Users/nyee2/dev/plugins/campaign-manager-web-plugin/.nyc_output/out.json +57ms
code-coverage parsed sent coverage +3s
code-coverage wrote coverage file /Users/nyee2/dev/plugins/campaign-manager-web-plugin/.nyc_output/out.json +50ms
code-coverage parsed sent coverage +2s
code-coverage wrote coverage file /Users/nyee2/dev/plugins/campaign-manager-web-plugin/.nyc_output/out.json +53ms

Versions

  • @cypress/code-coverage v3.9.7
  • Cypress 7.0.1
  • OS: MacOS Big Sur 11.4
  • shell: bash
  • Node v14.16.0
  • NPM 6.14.11
  • How do you instrument your application? babel-plugin-istanbul
  • do you see window.__coverage__ object? yes, window.__coverage__ exists and instrumentation works
  • Is there .nyc_output folder? yes coverage data is generated
  • custom NYC settings in package.json
  "nyc": {
    "extension": [
      ".jsx",
      ".js"
    ],
    "reporter": [
      "lcov",
      "json-summary",
      "text",
      "cobertura"
    ],
    "sourceMap": false,
    "instrument": false
  },
  • Do you run Cypress tests in a Docker container? yes in CI, MacOS locally

Describe the bug
The logic to determine if cypress is running an "end-to-end" test incorrectly resolves as true in my cypress tests, as our baseUrl and proxyUrl are different.

Code reference in question:
https://github.com/cypress-io/code-coverage/blob/c51751f9f9875c88aaacf648c738bec63b4163f1/support.js#L168-L172

From the above code, runningEndToEndTests evaluates to true if your baseUrl and proxyUrl are different, which they are in my case but I am not running end-to-end tests.

Cursor_and_campaign-manager-web-plugin

As my specType is integration, after tests complete an attempt is made to reach a /coverage URL which does not exist, thus failing the test.
Cursor_and_campaign-manager-web-plugin

I would like to propose perhaps setting & checking against a new config codeCoverage.expectFrontendCoverageOnly explicitly to determine if backend coverage needs to be collected (similar to the pre-existing expectBackendCoverageOnly config), eg. the above code reference could be augmented to preserve the existing behavior but allowing an explicit check against expectFrontendCoverageOnly

const runningEndToEndTests = baseUrl !== Cypress.config('proxyUrl')
const specType = Cypress._.get(Cypress.spec, 'specType', 'integration')
const isIntegrationSpec = specType === 'integration'
const expectFrontendCoverageOnly = Cypress._.get(Cypress.env('codeCoverage'), 'expectFrontendCoverageOnly', 
  false)

if (!expectFrontendCoverageOnly && runningEndToEndTests && isIntegrationSpec) {

Link to the repo
The code I am using @cypress/code-coverage is behind a private GH instance so I unfortunately can't share here. I have created https://github.com/cypress-io/code-coverage/pull/474 with the above suggestion

主要语言
TypeScript
星标
440
派生
114
平均合并
42 分钟
30 天内合并 PR
19

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cypress-io/code-coverage 的其他 Issue

查看 cypress-io/code-coverage 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。