Open serak88 opened 4 years ago
Hey @serak88 , I've accidentally stumbled upon this issue. Most likely it happens because karma-jasmine-diff-reporter adds some tricky characters in it's output and karma-sonarqube-unit-reporter fails to parse them. To avoid it you should change positions of the reporters in your karma.conf.js
to look like following:
reporters: ['sonarqubeUnit', 'jasmine-diff', 'mocha'],
So sonarqube reporter will start first and work with clean Jasmine output and generate XML. Then jasmine-diff will make some nasty things to add colors to the diffs. And then mocha will display things nicely.
I run this updated configuration on your sample project, here is the result
Hope it helps.
Changing the order of reporters bypasses the issue, but I believe that sanitizing the log from invalid XML characters could be implemented without drawbacks, removing the issue altogether.
Thanks for your help!
When a test fails if colors are active in the report (for example with karma-jasmine-diff-reporter) the following exception is thrown, interrupting the test execution:
08 05 2020 17:18:37.002:ERROR [karma-server]: Error: Invalid character in string: Error: Expected false to be truthy. at <Jasmine> at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/app.component.spec.ts:2:17) at Object.toHaveReturnedFalseFromThen (node_modules/jasmine-given/dist/jasmine-given.js:261:34) at node_modules/jasmine-given/dist/jasmine-given.js:52:24 at index 16 at XMLStringifier.assertLegalChar (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\node_modules\xmlbuilder\lib\XMLStringifier.js:208:19) at XMLStringifier.text (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\node_modules\xmlbuilder\lib\XMLStringifier.js:52:21) at new XMLText (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\node_modules\xmlbuilder\lib\XMLText.js:22:37) at XMLElement.text (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\node_modules\xmlbuilder\lib\XMLNode.js:308:17) at XMLElement.node (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\node_modules\xmlbuilder\lib\XMLNode.js:294:17) at XMLElement.element (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\node_modules\xmlbuilder\lib\XMLNode.js:187:30) at XMLElement.ele (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\node_modules\xmlbuilder\lib\XMLNode.js:611:21) at SonarQubeUnitReporter.specSuccess.specSkipped.specFailure (**\sonar-reporter-bug\node_modules\karma-sonarqube-unit-reporter\index.js:197:16) at SonarQubeUnitReporter.BaseReporter.onSpecComplete (**\sonar-reporter-bug\node_modules\karma\lib\reporters\base.js:109:12) at Server.<anonymous> (**\sonar-reporter-bug\node_modules\karma\lib\events.js:40:26) at Server.emit (events.js:208:15) at Browser.onResult (**\sonar-reporter-bug\node_modules\karma\lib\browser.js:159:20) at Array.forEach (<anonymous>) at Browser.onResult (**\sonar-reporter-bug\node_modules\karma\lib\browser.js:156:14) at Socket.<anonymous> (**\sonar-reporter-bug\node_modules\karma\lib\browser.js:209:42) at Socket.emit (events.js:203:13)
The words "false" and "truthy" have a background color in this case. When colors are disabled the error isn't shown anymore and the report is created correctly.
I uploaded a simple Angular project to reproduce the error, you can take a look at it here: https://github.com/serak88/sonar-reporter-bug