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

fix: escape XML in error stack trace when using junit reporter #3038

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/junit.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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