Skip to content

Commit

Permalink
fix junit reporter for parallel testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryGinger committed Jun 19, 2020
1 parent 749dbe7 commit fce3855
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ginkgo_dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ type Benchmarker interface {
//
// ginkgo bootstrap
func RunSpecs(t GinkgoTestingT, description string) bool {
specReporters := []Reporter{buildDefaultReporter()}
var specReporters []Reporter

if config.DefaultReporterConfig.ReportFile != "" {
reportFile := config.DefaultReporterConfig.ReportFile
specReporters[0] = reporters.NewJUnitReporter(reportFile)
return RunSpecsWithDefaultAndCustomReporters(t, description, specReporters)
specReporters = append(specReporters, reporters.NewJUnitReporter(reportFile))
}
return RunSpecsWithCustomReporters(t, description, specReporters)
return RunSpecsWithDefaultAndCustomReporters(t, description, specReporters)
}

//To run your tests with Ginkgo's default reporter and your custom reporter(s), replace
Expand Down
7 changes: 7 additions & 0 deletions reporters/junit_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ func (reporter *JUnitReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
if err != nil {
fmt.Printf("\nFailed to create JUnit directory: %s\n\t%s", filePath, err.Error())
}

if config.GinkgoConfig.ParallelTotal > 1 {
ext := filepath.Ext(filePath)
filename := filePath[0:len(filePath)-len(ext)]
filePath = fmt.Sprintf("%s_%02d%s", filename, config.GinkgoConfig.ParallelNode, ext)
}

file, err := os.Create(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create JUnit report file: %s\n\t%s", filePath, err.Error())
Expand Down

0 comments on commit fce3855

Please sign in to comment.