test_runner: source-mapped coverage marks an unexecuted return as covered

未關閉
#67,099 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
66/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript, node.js
領域
devtools, testing

研究方向

Start by running the reproduction with Node.js source maps and test coverage enabled, then compare its report with the same file after removing the source-map comment. Trace how the test runner maps executed JavaScript coverage back to the embedded TypeScript source; the issue gives no implementation file or test path, so first locate the coverage and source-map tests. Done means the uncovered return is reported as uncovered in both the text and lcov reports.

由索引模型根據 Issue 內容生成。

描述

test_runner
Version

v26.12.1

Platform

Darwin arm64

Subsystem

test_runner coverage

Reproduction

Create these two files in an empty directory. No packages or module hooks are required. The inline source map contains its TypeScript source.

compiled.mjs

function choose(value) {
  if (value) {
    return "yes";
  }
  return "no";
}
export {
  choose
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiZXhhbXBsZS50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiZXhwb3J0IGZ1bmN0aW9uIGNob29zZSh2YWx1ZTogYm9vbGVhbik6IHN0cmluZyB7XG4gIGlmICh2YWx1ZSkge1xuICAgIHJldHVybiBcInllc1wiO1xuICB9XG4gIHJldHVybiBcIm5vXCI7XG59XG4iXSwKICAibWFwcGluZ3MiOiAiQUFBTyxTQUFTLE9BQU8sT0FBd0I7QUFDN0MsTUFBSSxPQUFPO0FBQ1QsV0FBTztBQUFBLEVBQ1Q7QUFDQSxTQUFPO0FBQ1Q7IiwKICAibmFtZXMiOiBbXQp9Cg==

compiled.test.mjs

import assert from "node:assert/strict";
import test from "node:test";
import { choose } from "./compiled.mjs";

test("branch", () => assert.equal(choose(true), "yes"));

Run:

node --enable-source-maps --experimental-test-coverage --test compiled.test.mjs

The embedded original source is:

export function choose(value: boolean): string {
  if (value) {
    return "yes";
  }
  return "no";
}
Expected behavior

The test only calls choose(true). Original line 5 (return "no") should be uncovered. With the source-map comment removed, the JavaScript report correctly shows line 5 uncovered.

Actual behavior

The source-mapped report shows example.ts at 100% lines, 66.67% branches, and 100% functions, with no uncovered lines. The lcov reporter also emits DA:5,1. This overstates execution of a branch that the test never takes.

This reproduces with a single test process and a precompiled module. The example was generated using esbuild 0.28.2, but the reproduction above does not require esbuild. Related source-map coverage reports include #65946 and #67077; those describe off-thread hooks or merging multiple test processes, while this case needs neither.

主要語言
JavaScript
星號
123k
分支
39.3k
平均合併
4 天 16 小時
30 天內合併 PR
227

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

nodejs/node 的其他 Issue

查看 nodejs/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。