Skip to content

Commit

Permalink
Make cobertura parser tolerate empty arrays (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorio-gerardi authored Oct 28, 2024
1 parent 949a867 commit ad11c1c
Show file tree
Hide file tree
Showing 13 changed files with 6,857 additions and 4,755 deletions.
48 changes: 48 additions & 0 deletions __tests__/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`parse cobertura file with empty classes 1`] = `
{
"basePath": "",
"coverage": 49.83,
"files": {},
"timestamp": 1715832361332,
}
`;

exports[`parse cobertura file with empty lines 1`] = `
{
"basePath": "src/main.ts",
"coverage": 49.83,
"files": {
"4fab5baaca5c14d2de62d8d2fceef376ddddcc8e9509d86cfa5643f51b89ce3d": {
"absolute": "src/main.ts",
"coverage": 0,
"relative": "src/main.ts",
},
},
"timestamp": 1715832361332,
}
`;

exports[`parse cobertura file with empty methods 1`] = `
{
"basePath": "src/main.ts",
"coverage": 49.83,
"files": {
"4fab5baaca5c14d2de62d8d2fceef376ddddcc8e9509d86cfa5643f51b89ce3d": {
"absolute": "src/main.ts",
"coverage": 0,
"relative": "src/main.ts",
},
},
"timestamp": 1715832361332,
}
`;

exports[`parse cobertura file with empty packages 1`] = `
{
"basePath": "",
"coverage": 0,
"files": {},
"timestamp": 1716003335,
}
`;

exports[`parse empty cobertura file 1`] = `
{
"basePath": "",
Expand Down
13 changes: 13 additions & 0 deletions __tests__/fixtures/cobertura-empty-classes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="303" lines-covered="151" line-rate="0.49829999999999997" branches-valid="143" branches-covered="64" branch-rate="0.4475" timestamp="1715832361332" complexity="0" version="0.1">
<sources>
<source>/usr/src/code-coverage-report-action</source>
</sources>
<packages>
<package name="src" line-rate="0.4058" branch-rate="0.4083">
<classes>
</classes>
</package>
</packages>
</coverage>
28 changes: 28 additions & 0 deletions __tests__/fixtures/cobertura-empty-lines.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="303" lines-covered="151" line-rate="0.49829999999999997" branches-valid="143" branches-covered="64" branch-rate="0.4475" timestamp="1715832361332" complexity="0" version="0.1">
<sources>
<source>/usr/src/code-coverage-report-action</source>
</sources>
<packages>
<package name="src" line-rate="0.4058" branch-rate="0.4083">
<classes>
<class name="main.ts" filename="src/main.ts" line-rate="0" branch-rate="0">
<methods>
<method name="run" hits="0" signature="()V">
<lines>
</lines>
</method>
<method name="generateMarkdown" hits="0" signature="()V">
<lines>
<line number="107" hits="0"/>
</lines>
</method>
</methods>
<lines>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
19 changes: 19 additions & 0 deletions __tests__/fixtures/cobertura-empty-methods.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="303" lines-covered="151" line-rate="0.49829999999999997" branches-valid="143" branches-covered="64" branch-rate="0.4475" timestamp="1715832361332" complexity="0" version="0.1">
<sources>
<source>/usr/src/code-coverage-report-action</source>
</sources>
<packages>
<package name="src" line-rate="0.4058" branch-rate="0.4083">
<classes>
<class name="main.ts" filename="src/main.ts" line-rate="0" branch-rate="0">
<methods>
</methods>
<lines>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
7 changes: 7 additions & 0 deletions __tests__/fixtures/cobertura-empty-packages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="0" lines-covered="0" line-rate="0" branches-valid="0" branches-covered="0" branch-rate="0" timestamp="1716003335.624" complexity="0" version="5.4.3+1">
<sources/>
<packages>
</packages>
</coverage>
20 changes: 20 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ test('parse empty cobertura file', async () => {
expect(ret).toMatchSnapshot()
})

test('parse cobertura file with empty packages', async () => {
const ret = await parseCoverage(__dirname + '/fixtures/cobertura-empty-packages.xml')
expect(ret).toMatchSnapshot()
})

test('parse cobertura file with empty classes', async () => {
const ret = await parseCoverage(__dirname + '/fixtures/cobertura-empty-classes.xml')
expect(ret).toMatchSnapshot()
})

test('parse cobertura file with empty lines', async () => {
const ret = await parseCoverage(__dirname + '/fixtures/cobertura-empty-lines.xml')
expect(ret).toMatchSnapshot()
})

test('parse cobertura file with empty methods', async () => {
const ret = await parseCoverage(__dirname + '/fixtures/cobertura-empty-methods.xml')
expect(ret).toMatchSnapshot()
})

test('parse many sources cobertura file', async () => {
const ret = await parseCoverage(
__dirname + '/fixtures/cobertura-many-sources.xml'
Expand Down
Loading

0 comments on commit ad11c1c

Please sign in to comment.