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

Running in node 12 generates an invalid XML when running using '--reporter cobertura' #149

Closed
assaf-xm opened this issue Sep 12, 2019 · 8 comments · Fixed by #203
Closed
Labels
bug help wanted Issue is well defined but needs assignment

Comments

@assaf-xm
Copy link

assaf-xm commented Sep 12, 2019

Version: v12.9.1
Platform: 4.4.0-130-generic

We use c8 with the cobertura reporter.
Moving from node 10 to node 12 the generated XML was invalid and crashed the Jenkins Cobertura publisher.

It seems that node 12 the '(anonymous function)' now becomes '<computed>' and the '<' character is invalid inside an attribute (in the cobertura-coverage.xml).

For example:
Node12
<method name="self.cam.<computed>.handler" hits="6" signature="()V">

Node10
<method name="self.cam.(anonymous function).handler" hits="6" signature="()V">

The Jenkins error:
FATAL: Unable to parse .../builds/3622/coverage.xml
09:17:48 hudson.util.IOException2: Cannot parse coverage results
09:17:48 at hudson.plugins.cobertura.CoberturaCoverageParser.parse(CoberturaCoverageParser.java:84)
09:17:48 at hudson.plugins.cobertura.CoberturaCoverageParser.parse(CoberturaCoverageParser.java:52)
09:17:48 at hudson.plugins.cobertura.CoberturaPublisher.perform(CoberturaPublisher.java:593)
09:17:48 at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:79)
09:17:48 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
09:17:48 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
09:17:48 at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
09:17:48 at hudson.model.Build$BuildExecution.post2(Build.java:186)
09:17:48 at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
09:17:48 at hudson.model.Run.execute(Run.java:1840)
09:17:48 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
09:17:48 at hudson.model.ResourceController.execute(ResourceController.java:97)
09:17:48 at hudson.model.Executor.run(Executor.java:429)
09:17:48 Caused by: org.xml.sax.SAXParseException; lineNumber: 47595; columnNumber: 42; The value of attribute "name" associated with an element type "method" must not contain the '<' character.
09:17:48 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
09:17:48 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:944)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanAttribute(XMLDocumentFragmentScannerImpl.java:1548)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1315)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
09:17:48 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
09:17:48 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
09:17:48 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
09:17:48 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
09:17:48 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
09:17:48 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
09:17:48 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
09:17:48 at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
09:17:48 at hudson.plugins.cobertura.CoberturaCoverageParser.parse(CoberturaCoverageParser.java:76)
09:17:48 ... 12 more
09:17:48 ERROR: Step ‘Publish Cobertura Coverage Report’ failed: [Cobertura] Unable to parse .../builds/3622/coverage.xml

@bcoe bcoe added the more-info-needed For issues that have not be described fully label Sep 13, 2019
@bcoe
Copy link
Owner

bcoe commented Sep 13, 2019

@assaf-xm could you share a repo with a minimal reproduction?

Out of curiosity does your repository use ts-node, or some other transpiler.

@assaf-xm
Copy link
Author

Sure, here is a short code that reproduces it:

test-c8.js

class Test {
  constructor() {
    this.map = {};
  }

  run(i) {
    this.map[i] = {};
    this.map[i].f = () => console.log("FUNC RUN");
    console.log("TEST RUN");
  }
}

let t = new Test();
t.run(20);
t.map[20].f();

To get the XML (use node v12.9.1 or similar):

mkdir ./coverage
mkdir ./coverage/tmp
NODE_V8_COVERAGE=./coverage/tmp node test-c8.js
c8 report  -x "coverage/**" -x "test/**" -x "**/node_modules/**" -x "tmp/**"  test-c8.js --reporter cobertura

Then the resulted XML in ./coverage/cobertura-coverage.xml will include the '<computed>' field:

<methods>
        <method name="Test" hits="1" signature="()V">
          <lines>
            <line number="2" hits="1"/>
          </lines>
        </method>
        <method name="run" hits="1" signature="()V">
          <lines>
            <line number="6" hits="1"/>
          </lines>
        </method>
        <method name="map.<computed>.f" hits="1" signature="()V">
          <lines>
            <line number="8" hits="1"/>
          </lines>
        </method>
</methods>

@bcoe
Copy link
Owner

bcoe commented Sep 13, 2019

👋 oh fascinating, should be a pretty simple fix; we'll want to make it upstream here:

https://github.com/istanbuljs/istanbuljs

@assaf-xm
Copy link
Author

Any update regarding this issue?

@bcoe
Copy link
Owner

bcoe commented Sep 27, 2019

@assaf-xm I believe the fix should be fairly simple, just haven't had the cycles to work on it; I'm about to dive in to a few updates to c8 based on work that has been done in Node.js around source-maps. I'll update you soon.

@bcoe bcoe added bug help wanted Issue is well defined but needs assignment and removed more-info-needed For issues that have not be described fully labels Oct 24, 2019
@assaf-xm
Copy link
Author

@bcoe , reminder regarding this issue

@jehy
Copy link

jehy commented Feb 7, 2020

Just one more friendly reminder, I had to deal with it today.

UPD. Added an issue istanbuljs/istanbuljs#527

@jehy
Copy link

jehy commented Feb 7, 2020

A quick and ugly workaround:

sed -i 's/<computed>/\&lt;computed\&gt;/g' ./cobertura-coverage.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted Issue is well defined but needs assignment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants