Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit reporter does not create directory before creating file. #554

Closed
wingyplus opened this issue Dec 25, 2018 · 5 comments
Closed

JUnit reporter does not create directory before creating file. #554

wingyplus opened this issue Dec 25, 2018 · 5 comments
Labels
v2 Issues that will be resolved by v2

Comments

@wingyplus
Copy link
Contributor

When call RunSpecsWithCustomReporters with not current directory and it doesn't exist. Ginkgo print an error and stop running:

Failed to create JUnit report file: /tmp/not_exists_folder/junit.xml
	open /tmp/not_exists_folder/junit.xml: no such file or directoryFailed to generate JUnit report
	invalid argumentPASS

Ginkgo ran 1 suite in 930.288973ms
Test Suite Passed

I can produce this issue by this code below:

package main

import (
	"testing"

	"github.com/onsi/ginkgo"
	"github.com/onsi/ginkgo/reporters"
	"github.com/onsi/gomega"
)

func TestSuite(t *testing.T) {
	rpts := []ginkgo.Reporter{
		reporters.NewJUnitReporter("/tmp/not_exists_folder/junit.xml"),
	}

	gomega.RegisterFailHandler(ginkgo.Fail)
	ginkgo.RunSpecsWithCustomReporters(t, "Suite", rpts)
}

var _ = ginkgo.Describe("first", func() {
	ginkgo.It("do something", func() {
	})
})

I have workaround solution by called mkdir before run spec. But I think it would be nice if ginkgo can create directory before create a filename.

@wingyplus wingyplus changed the title JUnit reporter create directory before creating file. JUnit reporter does not create directory before creating file. Dec 25, 2018
wingyplus pushed a commit to wingyplus/ginkgo that referenced this issue Jan 2, 2019
wingyplus pushed a commit to wingyplus/ginkgo that referenced this issue Jan 2, 2019
wingyplus pushed a commit to wingyplus/ginkgo that referenced this issue Jan 3, 2019
@onsi
Copy link
Owner

onsi commented Apr 5, 2021

This will be fixed in v2

@onsi onsi closed this as completed Apr 5, 2021
@onsi onsi added v2 Issues that will be resolved by v2 and removed bug labels Apr 5, 2021
@jlojosnegros
Copy link

jlojosnegros commented Jul 12, 2022

Migrating to v2 but still having this issue

./bin/mybinaryfile.test --ginkgo.v --ginkgo.fail-fast --ginkgo.junit-report=/tmp/artifacts/report --ginkgo.focus='my desired tests'
Failed to generate JUnit report:
  open /tmp/artifacts/report: no such file or directory
  In [ReportAfterSuite] at: vendor/github.com/onsi/ginkgo/v2/reporting_dsl.go:127

@onsi
Copy link
Owner

onsi commented Jul 12, 2022

hey - you can use:

./bin/mybinaryfile.test --ginkgo.v --ginkgo.fail-fast --ginkgo.junit-report=report --ginkgo.focus='my desired tests' --ginkgo.output-dir=/tmp/artifacts

@jlojosnegros
Copy link

hey - you can use:

./bin/mybinaryfile.test --ginkgo.v --ginkgo.fail-fast --ginkgo.junit-report=report --ginkgo.focus='my desired tests' --ginkgo.output-dir=/tmp/artifacts

Thanks for the hint :) . Sadly something did not work.

Running this script:

echo "Ginkgo version: " `ginkgo version`
./bin/mybinaryfile.test --ginkgo.v --ginkgo.fail-fast --ginkgo.output-dir=/tmp/artifacts --ginkgo.junit-report=report --ginkgo.focus='my desired tests'

Got this:

Ginkgo Version:  Ginkgo Version 2.1.4                                
flag provided but not defined: -ginkgo.output-dir                                         
Controlling Test Order                                                    
  --ginkgo.seed [int] (default: randomly generated by Ginkgo)
    The seed used to randomize the spec suite.                                           
  --ginkgo.randomize-all                                                       
    If set, ginkgo will randomize all specs together.  By default, ginkgo only
    randomizes the top level Describe, Context and When containers.
    
    .... this continue with all the supported flags

@onsi
Copy link
Owner

onsi commented Jul 13, 2022

dump, so sorry. I was moving too fast when I replied. the output-dir flag is only available on the CLI (which moves the generated report file after it is written by the test process). so you can do:

ginkgo -v -fail-fast -junit-report=report -focus='my desired tests' -output-dir=/tmp/artifacts ./bin/mybinaryfile.test

You're now probably thinking "that sounds incredibly dumb" which... fair. what's happening here is the workflow is optimized for running multiple suites that each generate a report and then collating those reports into a single file (or a set of files) all in one location. That collation is done by the cli (it has to be - each suite is a separate go test binary so it's the CLI that orchestrates running them and merging artifacts)... what isn't currently supported is specifying output-dir for a single suite with the suite's config flags. unit-report also doesn't support absolute paths though this is something I might fix later, I'm just now going to be able to get to it for a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 Issues that will be resolved by v2
Projects
None yet
Development

No branches or pull requests

4 participants