diff --git a/reporters/junit_reporter.go b/reporters/junit_reporter.go index 2c9f3c7929..9756592706 100644 --- a/reporters/junit_reporter.go +++ b/reporters/junit_reporter.go @@ -13,6 +13,7 @@ import ( "fmt" "math" "os" + "path/filepath" "strings" "github.com/onsi/ginkgo/config" @@ -124,6 +125,9 @@ func (reporter *JUnitReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) { reporter.suite.Time = math.Trunc(summary.RunTime.Seconds()*1000) / 1000 reporter.suite.Failures = summary.NumberOfFailedSpecs reporter.suite.Errors = 0 + if err := os.MkdirAll(filepath.Dir(reporter.filename), 0755); err != nil { + fmt.Printf("Failed to create JUnit report file: %s\n\t%s", reporter.filename, err.Error()) + } file, err := os.Create(reporter.filename) if err != nil { fmt.Printf("Failed to create JUnit report file: %s\n\t%s", reporter.filename, err.Error()) diff --git a/reporters/junit_reporter_test.go b/reporters/junit_reporter_test.go index 9b75dc0066..73e7364b5e 100644 --- a/reporters/junit_reporter_test.go +++ b/reporters/junit_reporter_test.go @@ -255,4 +255,18 @@ var _ = Describe("JUnit Reporter", func() { }) }) } + + When("output directory doesn't exist", func() { + It("should create before open file", func() { + output := "/tmp/not/exists/report.xml" + reporter := reporters.NewJUnitReporter(output) + reporter.SpecSuiteDidEnd(&types.SuiteSummary{ + NumberOfSpecsThatWillBeRun: 1, + NumberOfFailedSpecs: 0, + RunTime: testSuiteTime, + }) + defer os.RemoveAll("/tmp/not") + Ω(output).Should(BeAnExistingFile()) + }) + }) })