[Code Coverage] Cobertura report missing <condition> elements
Describe the bug
When using vitest with the v8 provider and generating a Cobertura report, the resulting XML report does not include <condition> elements inside <line> entries. This causes issues with tools that rely on them for accurate merging of multiple coverage reports (e.g. dotnet-coverage).
Example: Cobertura report with <conditions>
Reproduction
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="22" lines-covered="10" line-rate="0.4545" branches-valid="8" branches-covered="4" branch-rate="0.5" timestamp="1749219797741" complexity="0" version="0.1">
<sources>
<source>C:/code-coverage__vitests/foo</source>
</sources>
<packages>
<package name="main" line-rate="0.4545" branch-rate="0.5">
<classes>
<class name="get-quarter-name.ts" filename="src\get-quarter-name.ts" line-rate="0.625" branch-rate="0.5714">
<methods>
<method name="getQuarterName" hits="4" signature="()V">
<lines>
<line number="1" hits="4"/>
</lines>
</method>
</methods>
<lines>
<line number="1" hits="1" branch="true" condition-coverage="100% (1/1)"/>
<line number="2" hits="4" branch="false"/>
<line number="4" hits="4" branch="true" condition-coverage="100% (1/1)"/>
<line number="5" hits="2" branch="false"/>
<line number="6" hits="2" branch="false"/>
<line number="8" hits="4" branch="true" condition-coverage="0% (0/1)"/>
<line number="9" hits="0" branch="false"/>
<line number="10" hits="0" branch="true" condition-coverage="100% (1/1)"/>
<line number="12" hits="4" branch="true" condition-coverage="100% (1/1)"/>
<line number="13" hits="2" branch="false"/>
<line number="14" hits="2" branch="true" condition-coverage="0% (0/1)"/>
<line number="16" hits="4" branch="true" condition-coverage="0% (0/1)"/>
<line number="17" hits="0" branch="false"/>
<line number="18" hits="0" branch="false"/>
<line number="20" hits="0" branch="false"/>
<line number="21" hits="0" branch="false"/>
</lines>
</class>
<class name="main.ts" filename="src\main.ts" line-rate="0" branch-rate="0">
<methods>
<method name="(empty-report)" hits="0" signature="()V">
<lines>
<line number="1" hits="0"/>
</lines>
</method>
</methods>
<lines>
<line number="1" hits="0" branch="true" condition-coverage="0% (0/1)"/>
<line number="2" hits="0" branch="false"/>
<line number="3" hits="0" branch="false"/>
<line number="5" hits="0" branch="false"/>
<line number="8" hits="0" branch="false"/>
<line number="11" hits="0" branch="false"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['cobertura'],
reportsDirectory: '../.coverage/foo',
include: ['**/*.{ts,vue}'],
}
},
})
{
"name": "foo",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"test": "vitest run --coverage"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.1.4",
"typescript": "~5.8.3",
"vite": "^6.3.5",
"vitest": "^3.1.4"
}
}
System Info
npmPackages:
@vitest/coverage-v8: ^3.1.4 => 3.1.4
vite: ^6.3.5 => 6.3.5
vitest: ^3.1.4 => 3.1.4
Used Package Manager
npm
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [x] The provided reproduction is a minimal reproducible example of the bug.
I guess this is the specification for Cobertura? https://github.com/cobertura/web/blob/master/htdocs/xml/coverage-04.dtd
Looks like Istanbul reporters don't add <condition> at all: https://github.com/istanbuljs/istanbuljs/blob/main/packages/istanbul-reports/lib/cobertura/index.js#L79-L137
I would recommend to open an issue at: https://github.com/istanbuljs/istanbuljs/issues
Closing as upstream issue. There's nothing to change on Vitest side.
Note that you can also create custom reporters: https://vitest.dev/guide/coverage.html#custom-coverage-reporter.