Skip to content

Commit 9e2cd22

Browse files
committed
✨ (utils.test.ts): add test for parsing cobertura project with a single file to enhance test coverage
📝 (utils.test.ts.snap): update snapshot to include new test case for single file coverage 📝 (cobertura-project-single-file.xml): add fixture for cobertura project with a single file to support new test ♻️ (utils.ts): refactor parseXML function to include 'coverage.project.file' in the array for improved parsing logic
1 parent b8338e0 commit 9e2cd22

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

__tests__/__snapshots__/utils.test.ts.snap

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`parse cobertura file with empty classes 1`] = `
44
{
@@ -48,6 +48,21 @@ exports[`parse cobertura file with empty packages 1`] = `
4848
}
4949
`;
5050

51+
exports[`parse cobertura project with single file 1`] = `
52+
{
53+
"basePath": "/foo.php",
54+
"coverage": 2.65,
55+
"files": {
56+
"83e0f134b069618626405250ccb3fd4adcc0fdfc7714b387d4aa4f30862f75a7": {
57+
"absolute": "/foo.php",
58+
"coverage": 0,
59+
"relative": "/foo.php",
60+
},
61+
},
62+
"timestamp": 1752615692,
63+
}
64+
`;
65+
5166
exports[`parse empty cobertura file 1`] = `
5267
{
5368
"basePath": "",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1752615692">
3+
<project timestamp="1752615692">
4+
<file name="/foo.php">
5+
<metrics loc="17" ncloc="17" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
6+
</file>
7+
<metrics files="130" loc="11080" ncloc="9188" classes="122" methods="224" coveredmethods="13" conditionals="0" coveredconditionals="0" statements="4039" coveredstatements="100" elements="4263" coveredelements="113"/>
8+
</project>
9+
</coverage>

__tests__/utils.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ test('parse empty cobertura file', async () => {
174174
expect(ret).toMatchSnapshot()
175175
})
176176

177+
test('parse cobertura project with single file', async () => {
178+
const ret = await parseCoverage(__dirname + '/fixtures/cobertura-project-single-file.xml')
179+
expect(ret).toMatchSnapshot()
180+
})
181+
177182
test('parse cobertura file with empty packages', async () => {
178183
const ret = await parseCoverage(__dirname + '/fixtures/cobertura-empty-packages.xml')
179184
expect(ret).toMatchSnapshot()

dist/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export async function parseXML<T>(filename: string): Promise<T | null> {
5050
return false;
5151
}
5252
return inArray(jpath, [
53+
'coverage.project.file',
5354
'coverage.project.package',
5455
'coverage.project.package.file',
5556
'coverage.packages.package',

0 commit comments

Comments
 (0)