Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cobertura parser tolerate empty arrays #88

Merged

Conversation

gregorio-gerardi
Copy link
Contributor

This will fix #82 along with some other potential errors.

Problem

the cobertura spec allows some empty tags like <!ELEMENT packages (package*)>, where package* means 0 or more package elements.

An xml like the one in the linked issue

<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="0" lines-covered="0" line-rate="NaN" branches-valid="0" branches-covered="0" branch-rate="NaN" timestamp="1726170429312" complexity="0" version="0.1">
  <sources>
    <source>/Users/gregoriogerardi/Documents/dashjs</source>
  </sources>
  <packages>
  </packages>
</coverage>

Is an example of hoy the tag packages could be empty and still valid.

The action does not handle this scenario, it assumes that all lists will be defined (i.e. have at least one element).

Solution

I went over the spec, and tweaked all the typescript definitions related to empty lists. An empty list in the xml will end up as an undefined key in its parent typescript interface, so making all of them conditional is the correct approach based on how the xml parser works. Also, for every list that is not part of https://github.com/clearlyip/code-coverage-report-action/blob/main/src/utils.ts#L49-L53 I also added an optional type to be either an array or a single element.

@tm1000 tm1000 merged commit ad11c1c into clearlyip:main Oct 28, 2024
1 check failed
@tm1000
Copy link
Member

tm1000 commented Oct 28, 2024

Thanks @gregorio-gerardi sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot read properties of undefined (reading 'Symbol(Symbol.asyncIterator)')
2 participants