Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function removeInvalidXMLCharacters(value: any, removeDiscouragedChars: boolean)

function escapeXML(value: any): string {
return removeInvalidXMLCharacters(
String(value)
stripVTControlCharacters(String(value))
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
Expand Down Expand Up @@ -481,7 +481,7 @@ export class JUnitReporter implements Reporter {
return
}
const result = this.ctx.logger.formatError(error, errorOptions)
await this.baseLog(escapeXML(stripVTControlCharacters(result.output.trim())))
await this.baseLog(escapeXML(result.output.trim()))
},
)
}
Expand Down
32 changes: 31 additions & 1 deletion test/e2e/test/reporters/junit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'
import { resolve } from 'pathe'
import { expect, test, TestRunner } from 'vitest'
import { rolldownVersion } from 'vitest/node'
import { runVitest, runVitestCli } from '#test-utils'
import { runInlineTests, runVitest, runVitestCli } from '#test-utils'
import { getDuration } from '../../../../packages/vitest/src/node/reporters/junit'

const root = resolve(import.meta.dirname, '../../fixtures/reporters')
Expand Down Expand Up @@ -113,6 +113,36 @@ test('format error', async () => {
expect(stabilizeReport(readJunitReport(ctx!.config.root))).toMatchSnapshot()
})

test('strips ANSI sequences from the failure message attribute', async () => {
const { root } = await runInlineTests(
{
'ansi.test.ts': /* ts */ `
import { test } from 'vitest'
test('ansi', () => {
throw new Error('\\x1b[36m<body>\\x1b[39m')
})
`,
},
{ reporters: 'junit' },
)

expect(stabilizeReport(readJunitReport(root))).toMatchInlineSnapshot(`
"<?xml version="1.0" encoding="UTF-8" ?>
<testsuites name="vitest tests" tests="1" failures="1" errors="0" time="...">
<testsuite name="ansi.test.ts" timestamp="..." hostname="..." tests="1" failures="1" errors="0" skipped="0" time="...">
<testcase classname="ansi.test.ts" name="ansi" time="...">
<failure message="&lt;body&gt;" type="Error">
Error: &lt;body&gt;
❯ ansi.test.ts:5:17
</failure>
</testcase>
</testsuite>
</testsuites>
"
`)
})

test('write testsuite name relative to root config', async () => {
const { ctx } = await runVitest({
reporters: 'junit',
Expand Down
Loading