`.nyc_output/out.json` is an empty object when using with `@cypress/react`
维护者通常 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.jsonin 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 seewindow.__coverage__object for the files that the test is touching.

- Is there
.nyc_outputfolder? Is there.nyc_output/out.jsonfile. 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(nycobject) 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 thepackage.json - appropriate Cypress files need to be marked as
.cjsin order for the tests to run.
Incypress/plugins/index.cjsand fields incypress.json.
- i.e.
- Uses component testing (i.e.
@cypress/reactand usingopen-ctandrun-cttest runners). - Uses code coverage (i.e.
@cypress/code-coverageandbabel-plugin-istanbulbased 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 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cypress-io/code-coverage 的其他 Issue
-
难度 3/5 半天 新手友好度 40/100
cypress-io/code-coverage#1018 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
cypress-io/code-coverage#993 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
cypress-io/code-coverage#967 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
cypress-io/code-coverage#959 ·
维护者通常 1 天内回复
-
performance
难度 4/5 3-5 天 新手友好度 42/100
cypress-io/code-coverage#933 ·
维护者通常 1 天内回复
查看 cypress-io/code-coverage 的全部 Issue
相似的 Issue
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
liberation-data/drivine#615 ·
维护者通常 1 天内回复
-
backend bug ready-for-agent
难度 2/5 1-3 小时 新手友好度 78/100
geolens-io/geolens#3639 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
radius-project/ai-extensions#1196 ·
维护者通常 1 天内回复
-
good first issue
难度 1/5 1-3 小时 新手友好度 88/100