`.nyc_output/out.json` is an empty object when using with `@cypress/react`

未关闭
#472 10 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
babel, node.js, typescript
领域
testing

调研方向

从链接的复现仓库开始,运行 npm test 以确认 .nyc_output/out.json 为空。然后检查 package.json、cypress/plugins/index.cjs 和 Cypress 配置中的 ESM、组件测试及插桩设置。完成的标准是 .nyc_output/out.json 中出现 coverage 数据,并且生成的报告包含经过测试的文件。

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

描述

Logs and screenshots
Please provide debug logs by running Cypress from the terminal with DEBUG=code-coverage environment variable set, see the Debugging section of the README file.

Debug logs
  code-coverage reset code coverage in interactive mode +0ms
  code-coverage parsed sent coverage +32ms
  code-coverage wrote coverage file /Users/chrisrzhou/Github/cypress-coverage-repo/.nyc_output/out.json +1ms
  code-coverage parsed sent coverage +25ms
  code-coverage wrote coverage file /Users/chrisrzhou/Github/cypress-coverage-repo/.nyc_output/out.json +0ms
⚠️ file /Users/chrisrzhou/Github/cypress-coverage-repo/.nyc_output/out.json has no coverage information
Did you forget to instrument your web application? Read https://github.com/cypress-io/code-coverage#instrument-your-application
  code-coverage ⚠️ file /Users/chrisrzhou/Github/cypress-coverage-repo/.nyc_output/out.json has no coverage information +8s
  code-coverage ⚠️ file /Users/chrisrzhou/Github/cypress-coverage-repo/.nyc_output/out.json has no coverage information +1ms
  code-coverage calling NYC reporter with options { 'report-dir': '/Users/chrisrzhou/Github/cypress-coverage-repo/coverage', reporter: [ 'lcov', 'clover', 'json', 'json-summary' ], extension: [ '.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx' ], excludeAfterRemap: false, 'temp-dir': '/Users/chrisrzhou/Github/cypress-coverage-repo/.nyc_output', tempDir: '/Users/chrisrzhou/Github/cypress-coverage-repo/.nyc_output', reportDir: '/Users/chrisrzhou/Github/cypress-coverage-repo/coverage' } +7ms
  code-coverage current working directory is /Users/chrisrzhou/Github/cypress-coverage-repo +0ms
  code-coverage after reporting, returning the report folder name /Users/chrisrzhou/Github/cypress-coverage-repo/coverage +40ms
  code-coverage Final coverage in /Users/chrisrzhou/Github/cypress-coverage-repo/coverage/coverage-final.json +0ms
  code-coverage There are 0 key(s) in /Users/chrisrzhou/Github/cypress-coverage-repo/coverage/coverage-final.json +0ms

Versions

  • What is this plugin's version? @cypress/[email protected] (latest)
  • What is Cypress version? [email protected], @cypress/[email protected], @cypress/[email protected] (see package.json in repo for more details).
  • What is your operating system? Mac
  • What is the shell? zsh
  • What is the Node version? v12.22.1
  • What is the NPM version? 6.14.12
  • How do you instrument your application? Through the official docs' recommendation. See repo below for details.
  • When running tests, if you open the web application in regular browser, and open DevTools, do you see window.__coverage__ object? Following the official docs, I can see window.__coverage__ object for the files that the test is touching.
    image
  • Is there .nyc_output folder? Is there .nyc_output/out.json file. Is it empty? Both folder and file exists, the contents is just the empty object {}.
  • Do you have any custom NYC settings in package.json (nyc object) or in other NYC config files No
  • Do you run Cypress tests in a Docker container? No, just locally

Describe the bug

Bug Report

Repro Link

https://github.com/chrisrzhou/cypress-code-coverage-issue-472

Context

It is a minimal example with the following requirements:

  • Is an ESM module
    • i.e. "type": "module" is explicitly marked in the package.json
    • appropriate Cypress files need to be marked as .cjs in order for the tests to run.
      In cypress/plugins/index.cjs and fields in cypress.json.
  • Uses component testing (i.e. @cypress/react and using open-ct and run-ct test runners).
  • Uses code coverage (i.e. @cypress/code-coverage and babel-plugin-istanbul based on the official docs for instrumentation).

The requirements above are needed in the actual bug faced in the project, so the repo is capturing the minimal configuration of reproducing the same bug.

Reproduce

npm i
npm test

The test runner runs fine, and tests the code correctly.

Expected Behavior

Code coverage to output something meaningful in .nyc_output/out.json

Actual Behavior

.nyc_output/out.json is an empty object. The test runner complains that the code is not instrumented.

主要语言
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 摘要。