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

Having no tests causes the build to fail. #926

Closed
MatthewJamesBoyle opened this issue Oct 26, 2023 · 5 comments
Closed

Having no tests causes the build to fail. #926

MatthewJamesBoyle opened this issue Oct 26, 2023 · 5 comments

Comments

@MatthewJamesBoyle
Copy link
Contributor

Issue
builds fails if you do not have any test files.

How to repro
Consider an app with the following structure:
image

when I deploy it, the build fails as there are no tests.
image

Adding an empty test file fixes it:
image

Expectation
Whilst bad practise, there is situations where having no test files is fine. I think providing a warning log but the build succeeding would be a good outcome.

@eandre
Copy link
Member

eandre commented Oct 26, 2023

I believe real issue is not that there were no tests, but that there were no Go packages:

$ mkdir foo && cd foo && go mod init example.com

$ go test ./...
go: warning: "./..." matched no packages
no packages to test

$ echo $?
1

Whereas if you have a package:

$ echo "package foo" > foo.go

$ go test ./...
?   	example.com	[no test files]

$ echo $?
0

I'm not sure why Go made the distinction to treat "no matching packages" as a test failure; I guess to avoid mistakes. I believe if you have a matching Go package without tests Encore won't treat the tests as failing.

All that said, maybe Encore should treat this scenario as failing the build, and not just the tests? The "One or more tests failed" error is certainly confusing.

@MatthewJamesBoyle
Copy link
Contributor Author

MatthewJamesBoyle commented Oct 26, 2023

hmm I did have a go package though:
image .

However if I delete the test file now and re-run the build it does pass. Let me try and repro on a new project. Maybe I did something else wrong.

@MatthewJamesBoyle
Copy link
Contributor Author

MatthewJamesBoyle commented Oct 26, 2023

Ok I reproed this.

  • I ran encore create app
  • I created a project called "testing-no-tests"
  • I selected blank project.
  • I created a package as follows:
image image

@eandre
Copy link
Member

eandre commented Oct 26, 2023

But did you actually commit the thing/thing.go file? I believe the error you're seeing only happens when there are no Go packages.

@MatthewJamesBoyle
Copy link
Contributor Author

Aha I'm not sure I did :) will close!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants