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

Aberta
#67,099 1 comentário 1 reação 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
66/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
javascript, node.js
Domínio
devtools, testing

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
JavaScript
Estrelas
123k
Forks
39.3k
Merge médio
4d 16h
PRs com merge (30d)
227

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de nodejs/node

Todas as issues de nodejs/node

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.