[ViteJS] Empty coverage for all files not covered by tests

オープン
#539 コメント 27 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, typescript, vite

調査の方向性

Cypress の dev-server 設定、vite.config.js、およびレポートに示されている @cypress/code-coverage のサポートとタスクのセットアップから始めます。vite-plugin-istanbul を使って NYC の all 設定の場合を再現し、その後、空のファイルがどのようにカバレッジレポートに変換されるかを追跡します。未テストのファイルが instrumented な行データを保持し、最終的なカバレッジ計算に含まれれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Versions

  • What is this plugin's version? 3.9.12
  • What is Cypress version? 9.1.0
  • What is your operating system? MacOS
  • How do you instrument your application? Instanbul
  • Is there .nyc_output folder? Yes, not empty
  • Do you have any custom NYC settings? Yes, all
  • Do you run Cypress tests in a Docker container? No

Describe the bug
Despite using the all setting of NYC, it seems like only files touched by tests have their line numbers included in the report.
The other files are present but show 0 lines thus are ignored in the final computation of the code coverage.
Using the debug flag, I see them added:

  code-coverage adding empty coverage for file /Users/Sytten/Projects/*****/src/main.ts +0ms
  code-coverage adding empty coverage for file /Users/Sytten/Projects/*****/src/composables/index.ts +0ms
  code-coverage adding empty coverage for file /Users/Sytten/Projects/*****/src/composables/useId.ts +0ms
  code-coverage adding empty coverage for file /Users/Sytten/Projects/*****src/composables/useName.ts +0ms

But I would expect them to get line numbers at some point. But they only get:

TN:
SF:src/main.ts
FNF:0
FNH:0
LF:0
LH:0
BRF:0
BRH:0
end_of_record

I use ViteJS and my plugins looks like:

const path = require("path");
const { startDevServer } = require("@cypress/vite-dev-server");
const codeCoverageTask = require("@cypress/code-coverage/task");
const istanbul = require("vite-plugin-istanbul");

module.exports = (on, config) => {
  on("dev-server:start", (options) =>
    startDevServer({
      options,
      viteConfig: {
        logLevel: "warn",
        configFile: path.resolve(__dirname, "..", "..", "vite.config.js"),
        plugins: [istanbul({})],
      },
    })
  );

  codeCoverageTask(on, config);
  return config;
};

Support contains:

// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')

import "@cypress/code-coverage/support";

The coverage for files under test works fine.

Link to the repo
This is not an open-source project, but happy to provide a reproduction if that can help debug it.

主要言語
TypeScript
スター
440
フォーク
114
平均マージ
42分
マージ済み PR(30日)
19

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cypress-io/code-coverage のほかの issue

cypress-io/code-coverage の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。