Skip to content

Commit

Permalink
feat(reporter): default to options.suiteName for the suitename in the…
Browse files Browse the repository at this point in the history
… classnameTemplate

Change-Id: I03a3d47d26aa36ca5c14cf790a19629d151b7c61
  • Loading branch information
Jean-Philippe Leclerc committed Nov 4, 2024
1 parent b061706 commit 9bad3c8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/vitest/src/node/reporters/junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,20 @@ export class JUnitReporter implements Reporter {
for (const task of tasks) {
let classname = filename

const templateVars: ClassnameTemplateVariables = {
filename: task.file.name,
filepath: task.file.filepath,
suitename: this.options.suiteName ?? task.suite?.name ?? '',
}

if (typeof this.options.classnameTemplate === 'function') {
classname = this.options.classnameTemplate({
filename: task.file.name,
filepath: task.file.filepath,
suitename: task.suite?.name ?? '',
})
classname = this.options.classnameTemplate(templateVars)
}
else if (typeof this.options.classnameTemplate === 'string') {
classname = this.options.classnameTemplate
.replace(/\{filename\}/g, task.file.name)
.replace(/\{filepath\}/g, task.file.filepath)
.replace(/\{suitename\}/g, task.suite?.name ?? '')
.replace(/\{filename\}/g, templateVars.filename)
.replace(/\{filepath\}/g, templateVars.filepath)
.replace(/\{suitename\}/g, templateVars.suitename)
}
else if (typeof this.options.classname === 'string') {
classname = this.options.classname
Expand Down

0 comments on commit 9bad3c8

Please sign in to comment.