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

Đang mở
#472 10 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
babel, node.js, typescript
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu với repository tái hiện được liên kết và chạy npm test để xác nhận .nyc_output/out.json trống. Sau đó kiểm tra package.json, cypress/plugins/index.cjs và cấu hình Cypress để xem thiết lập ESM, kiểm thử component và instrumentation. Được xem là hoàn tất khi dữ liệu coverage xuất hiện trong .nyc_output/out.json và báo cáo được tạo chứa các tệp đã kiểm thử.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
440
Fork
114
Merge trung bình
42 phút
Pull request đã merge (30 ngày)
19

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cypress-io/code-coverage

Tất cả issue của cypress-io/code-coverage

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.