Skip to content

Commit fd41ff2

Browse files
author
Jean-Philippe Leclerc
committed
feat(reporter): Removed the mention of suitename in classnameTemplate
Change-Id: I6d4e936a6cabaacf31a82036acf22f9af401bdb0
1 parent 2e3dc97 commit fd41ff2

File tree

4 files changed

+6
-10
lines changed

4 files changed

+6
-10
lines changed

docs/guide/reporters.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,12 @@ The outputted XML contains nested `testsuites` and `testcase` tags. You can use
254254
The supported placeholders for the `classnameTemplate` option are:
255255
- filename
256256
- filepath
257-
- suitename
258257

259258
```ts
260259
export default defineConfig({
261260
test: {
262261
reporters: [
263-
['junit', { suiteName: 'custom suite name', classnameTemplate: 'filename:{filename} - filepath:{filepath} - suite:{suitename}' }]
262+
['junit', { suiteName: 'custom suite name', classnameTemplate: 'filename:{filename} - filepath:{filepath}' }]
264263
]
265264
},
266265
})

packages/vitest/src/node/reporters/junit.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { IndentedLogger } from './renderers/indented-logger'
1414
interface ClassnameTemplateVariables {
1515
filename: string
1616
filepath: string
17-
suitename: string
1817
}
1918

2019
export interface JUnitOptions {
@@ -23,7 +22,7 @@ export interface JUnitOptions {
2322
classname?: string
2423

2524
/**
26-
* Template for the classname attribute. Can be either a string or a function. The string can contain placeholders like {filename}, {filepath}, {suitename}.
25+
* Template for the classname attribute. Can be either a string or a function. The string can contain placeholders {filename} and {filepath}.
2726
*/
2827
classnameTemplate?: string | ((classnameVariables: ClassnameTemplateVariables) => string)
2928
suiteName?: string
@@ -212,7 +211,6 @@ export class JUnitReporter implements Reporter {
212211
const templateVars: ClassnameTemplateVariables = {
213212
filename: task.file.name,
214213
filepath: task.file.filepath,
215-
suitename: this.options.suiteName ?? task.suite?.name ?? '',
216214
}
217215

218216
if (typeof this.options.classnameTemplate === 'function') {
@@ -222,7 +220,6 @@ export class JUnitReporter implements Reporter {
222220
classname = this.options.classnameTemplate
223221
.replace(/\{filename\}/g, templateVars.filename)
224222
.replace(/\{filepath\}/g, templateVars.filepath)
225-
.replace(/\{suitename\}/g, templateVars.suitename)
226223
}
227224
else if (typeof this.options.classname === 'string') {
228225
classname = this.options.classname

test/reporters/tests/__snapshots__/reporters.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exports[`JUnit reporter with custom function classnameTemplate 1`] = `
1818
"<?xml version="1.0" encoding="UTF-8" ?>
1919
<testsuites name="vitest tests" tests="1" failures="0" errors="0" time="0">
2020
<testsuite name="test/core/test/basic.test.ts" timestamp="2022-01-19T10:10:01.759Z" hostname="hostname" tests="1" failures="0" errors="0" skipped="0" time="0.145992842">
21-
<testcase classname="filename:basic.test.ts - filepath:/vitest/test/core/test/basic.test.ts - suite:suite" name="Math.sqrt()" time="0.001442286">
21+
<testcase classname="filename:basic.test.ts - filepath:/vitest/test/core/test/basic.test.ts" name="Math.sqrt()" time="0.001442286">
2222
</testcase>
2323
</testsuite>
2424
</testsuites>
@@ -40,7 +40,7 @@ exports[`JUnit reporter with custom string classnameTemplate 1`] = `
4040
"<?xml version="1.0" encoding="UTF-8" ?>
4141
<testsuites name="vitest tests" tests="1" failures="0" errors="0" time="0">
4242
<testsuite name="test/core/test/basic.test.ts" timestamp="2022-01-19T10:10:01.759Z" hostname="hostname" tests="1" failures="0" errors="0" skipped="0" time="0.145992842">
43-
<testcase classname="filename:basic.test.ts - filepath:/vitest/test/core/test/basic.test.ts - suite:suite" name="Math.sqrt()" time="0.001442286">
43+
<testcase classname="filename:basic.test.ts - filepath:/vitest/test/core/test/basic.test.ts" name="Math.sqrt()" time="0.001442286">
4444
</testcase>
4545
</testsuite>
4646
</testsuites>

test/reporters/tests/reporters.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test('JUnit reporter with custom string classname', async () => {
9090

9191
test('JUnit reporter with custom function classnameTemplate', async () => {
9292
// Arrange
93-
const reporter = new JUnitReporter({ classnameTemplate: task => `filename:${task.filename} - filepath:${task.filepath} - suite:${task.suitename}` })
93+
const reporter = new JUnitReporter({ classnameTemplate: task => `filename:${task.filename} - filepath:${task.filepath}` })
9494
const context = getContext()
9595

9696
// Act
@@ -103,7 +103,7 @@ test('JUnit reporter with custom function classnameTemplate', async () => {
103103
})
104104
test('JUnit reporter with custom string classnameTemplate', async () => {
105105
// Arrange
106-
const reporter = new JUnitReporter({ classnameTemplate: `filename:{filename} - filepath:{filepath} - suite:{suitename}` })
106+
const reporter = new JUnitReporter({ classnameTemplate: `filename:{filename} - filepath:{filepath}` })
107107
const context = getContext()
108108

109109
// Act

0 commit comments

Comments
 (0)