Skip to content

Bad error message in --experimental-test-coverage output when a source maps source module is missing #54756

Description

@jaydenseric

Version

v22.8.0

Platform

Darwin TRI-N93DLJDY6Y 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

In dist/a.mjs:

console.log("Hi");
export {};
//# sourceMappingURL=a.mjs.map

In dist/a.mjs.map:

{"version":3,"file":"a.mjs","sourceRoot":"","sources":["../src/a.mts"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC"}

In test.mjs:

import "./dist/a.mjs";

Then, run:

node --experimental-test-coverage --test test.mjs

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior? Why is that the expected behavior?

An error message reported after the tests output, explaining that a particular source module at a path is missing. If multiple are missing, then output the list of missing paths.

What do you see instead?

Hi
✔ test.mjs (46.715834ms)
ℹ Warning: Could not report code coverage. TypeError: Cannot read properties of undefined (reading '0')
ℹ tests 1
ℹ suites 0
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 51.063542

Additional information

This scenario comes up very frequently when working in a TypeScript project with source maps enabled, that has src and dist directories. Often you have a build script watching the src directory, and as you work you rename or delete a source module. The result is that old artifacts don't get cleaned in the dist directory, but the next time the tests run on the dist directory the coverage explodes with the error this issue reports.

Note that if multiple test modules run, then the coverage report for everything is obscured by the error message:

ℹ Warning: Could not report code coverage. TypeError: Cannot read properties of undefined (reading '0')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-bugIssues and PRs for confirmed bugs.coverageIssues and PRs related to Node.js code coverage support.source mapsIssues and PRs related to source map support.test_runnerIssues and PRs related to the test runner subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions