Skip to content

Code coverage is reported for non teste files after pulling changes from main #7788

@ChristopherDedominici

Description

@ChristopherDedominici

What happened?

While working on the code coverage I noticed different behavior after pulling the latest changes from main.

Previously, when running in the example-project:

pnpm hardhat test solidity contracts/Counter.t.sol --coverage

I was getting coverage results only for the Counter.t.sol file.

After pulling the changes from main, I started getting coverage results for ALL solidity files. The results are correct, all the non tested files have 0% coverage, but I think they should not appear at all, since I am targeting a specific file.

Day when I noticed the difference, in case it is useful to investigate changes that were merged into main: Wednesday 10/11/2025.

Image

Minimal reproduction steps

In main run coverage for a single file in the example-project:

pnpm hardhat test solidity contracts/Counter.t.sol --coverage

You should get the result only for that file, but instead you get coverage for all Solidity files, including those that were not executed.

Update after initial investigation

I had to go back quite far in the main commit to find a plausible cause.

In commit b57b02d9ef596316795397c54bd998be6f85f2d6, coverage is generated only for the specific file being executed.
In the next commit, 4168c11ce7b2a4ad690fcb4ea8c110569bdfe760, the logic no longer works as expected.
But none of these commits changes the coverage logic.

Interestingly, when I went back several commits before b57b02d9ef596316795397c54bd998be6f85f2d6, the commit 98e6be90bb2ea40be95a806f8810ef70ece69eb7 also does not work.

4168c11ce7b2a4ad690fcb4ea8c110569bdfe760, does not work
b57b02d9ef596316795397c54bd998be6f85f2d6, works
98e6be90bb2ea40be95a806f8810ef70ece69eb7, does not work

When printing the metadata received from edr (see here), I noticed that when the code works as expected, only the executed files are passed, whereas when it does not, all files are passed.

This might be related on the artifacts that hardhat passes to edr when running the solidity tests here:

const solidityTestResult = await edrContext.runSolidityTests(
.
When the bug appears, additional artifacts are passed, even the ones that are NOT being tested.

It might be related to this block of code: https://github.com/NomicFoundation/hardhat/blame/40615f8e80907aca3a844ea92766616878298f71/v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts#L83.
If it is removed, the coverage works as expected. We need to understand why this code was added.
Probably related to this PR: #7686

Metadata

Metadata

Labels

Type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions