Skip to content

Commit

Permalink
fix: escape XML in error stack trace when using junit reporter (#3038)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 20, 2023
1 parent a768015 commit cc5779d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/junit.ts
Expand Up @@ -131,7 +131,7 @@ export class JUnitReporter implements Reporter {
for (const frame of stack) {
const path = relative(this.ctx.config.root, frame.file)

await this.baseLog(` ${F_POINTER} ${[frame.method, `${path}:${frame.line}:${frame.column}`].filter(Boolean).join(' ')}`)
await this.baseLog(escapeXML(` ${F_POINTER} ${[frame.method, `${path}:${frame.line}:${frame.column}`].filter(Boolean).join(' ')}`))

// reached at test file, skip the follow stack
if (frame.file in this.ctx.state.filesMap)
Expand Down
1 change: 1 addition & 0 deletions test/reporters/src/data-for-junit.ts
Expand Up @@ -28,6 +28,7 @@ function createSuiteHavingFailedTestWithXmlInError(): File[] {

errorWithXml.stack = 'Error: error message that has XML in it <tag>\n'
+ ' at /vitest/test/core/test/basic.test.ts:8:32\n'
+ ' at /vitest/test/core/test/<bracket-name>.ts:3:11\n'
+ ' at etc....'

const tasks: Task[] = [
Expand Down
2 changes: 1 addition & 1 deletion test/reporters/tests/__snapshots__/html.test.ts.snap
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`html reporter > resolves to "failing" status for test file "json-fail" > tests are failing 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion test/reporters/tests/__snapshots__/json.test.ts.snap
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`json reporter > generates correct report 1`] = `
{
Expand Down
3 changes: 2 additions & 1 deletion test/reporters/tests/__snapshots__/reporters.spec.ts.snap
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`JUnit reporter (no outputFile entry) 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
Expand Down Expand Up @@ -249,6 +249,7 @@ exports[`JUnit reporter with outputFile with XML in error message 2`] = `
<failure message=\\"error message that has XML in it &lt;tag&gt;\\" type=\\"AssertionError\\">
AssertionError: error message that has XML in it &lt;tag&gt;
test/core/test/basic.test.ts:8:32
test/core/test/&lt;bracket-name&gt;.ts:3:11
</failure>
</testcase>
</testsuite>
Expand Down

0 comments on commit cc5779d

Please sign in to comment.