Skip to content

Commit

Permalink
fix: allow special characters and emoji in output
Browse files Browse the repository at this point in the history
If an emoji is used anywhere in either suite description or inside an
error from a test (e.g. "Expected '👎' to be '👍'"), the reporter
chrashes with "Invalid character (�) in string: 😄 at index 0".

The root cause of this is xmlbuilder, that uses a version that is
3 years old at this time. The current version does not throw any
errors for this.

This PR will suggest updating to the latest version of xmlbuilder,
that includes a lot of bugfixes. As far as I could determine,
there were no breaking changes for this package.
  • Loading branch information
csvn committed Apr 9, 2019
1 parent 952cf26 commit 59fd3c6
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
"author": "Vojta Jina <vojta.jina@gmail.com>",
"dependencies": {
"path-is-absolute": "^1.0.0",
"xmlbuilder": "8.2.2"
"xmlbuilder": "12.0.0"
},
"peerDependencies": {
"karma": ">=0.9"
39 changes: 38 additions & 1 deletion test/reporter.spec.js
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@ var fakeHelper = {
mkdirIfNotExists: sinon.stub().yields()
}

var fakeFormatError = sinon.spy(function (v) { return v })

var fakeConfig = {
basePath: __dirname,
junitReporter: {
@@ -52,7 +54,7 @@ describe('JUnit reporter', function () {
})

beforeEach(function () {
reporter = new reporterModule['reporter:junit'][1](fakeBaseReporterDecorator, fakeConfig, fakeLogger, fakeHelper)
reporter = new reporterModule['reporter:junit'][1](fakeBaseReporterDecorator, fakeConfig, fakeLogger, fakeHelper, fakeFormatError)
})

it('should produce valid XML per the new SonarQube reporting format', function () {
@@ -165,6 +167,41 @@ describe('JUnit reporter', function () {
expect(writtenXml).to.have.string('testcase name="Sender using it get request should not fail"')
})

it('should safely handle special characters', function () {
var fakeBrowser = {
id: 'Android_4_1_2',
name: 'Android',
fullName: 'Android 4.1.2',
lastResult: {
error: false,
total: 1,
failed: 1,
netTime: 10 * 1000
}
}

var fakeResult = {
suite: [
'Sender',
'using it',
'get request'
],
success: false,
description: 'should not fail',
log: ['Expected "👍" to be "👎".']
}

reporter.onRunStart([ fakeBrowser ])
reporter.specSuccess(fakeBrowser, fakeResult)
reporter.onBrowserComplete(fakeBrowser)
reporter.onRunComplete()

expect(fakeFs.writeFile).to.have.been.called

var writtenXml = fakeFs.writeFile.firstCall.args[1]
expect(writtenXml).to.have.string('<failure type="">Expected "👍" to be "👎".</failure>')
})

it('should safely handle missing suite browser entries when specSuccess fires', function () {
reporter.onRunStart([])
// don't try to call null.ele()

0 comments on commit 59fd3c6

Please sign in to comment.