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

Abierto
#67,099 1 comentario 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
66/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, node.js
Área
devtools, testing

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
JavaScript
Estrellas
123k
Forks
39.3k
Merge medio
4 d 11 h
PR fusionados (30 d)
237

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nodejs/node

Todos los issues de nodejs/node

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.