-
Notifications
You must be signed in to change notification settings - Fork 85
Add test harness for headless browser testing #881
Conversation
Hmm... I guess chromedp needs Chrome 😄 @chaodaiG any ideas of how we'd get chrome into our binary? There's a base image we could borrow from: https://github.com/chromedp/docker-headless-shell |
For FB config - can we make that injected config from the runtime environment? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modulo some nits, this LGTM.
// NewServer creates a new test UI server instance. When this function returns, | ||
// a full UI server will be running locally on a random port. Cleanup is handled | ||
// automatically. | ||
func NewServer(tb testing.TB) *TestServerResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nomenclature niggle. The function's entitled NewServer
yet it doesn't return a Server
type, it returns a response. It feels like here (and the below function NewServerConfig
) are either misnamed, or the the type returned is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns the server and everything needed to run it. We have to return things like the database because tests might need to insert or assert records.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to other names
var _, self, _, _ = runtime.Caller(0) | ||
|
||
// Root returns the filepath to the root of this project. | ||
func Root() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a global constant, like self
, and the init generation code in the compiler will sort out the dependency chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be a global var
, which would be mutable. AFAIK, you can't create a constant that uses filepath.Join
since it wouldn't be constant across systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point. Root
could still be a LHS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's an LHS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left hand side. common compiler nomenclature for a "result of an expression"
} | ||
|
||
// RandomString returns a random hex-encoded string of the given length. | ||
func RandomString(tb testing.TB, length int) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API is slightly clunky. length
is the length of the random string, not the encoded string. Might want to document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the length of the encoded string (that's why I divide by 2).
How about add |
@chaodaiG That could work, but it will make running tests locally harder. It would be better if we could have chrome or chrome-headless in |
Agreed, we can append |
@chaodaiG sounds good. Do you have any cycles to work on that today? I imagine we're going to have some trial and error to get it working against this PR. |
google/exposure-notifications-server#1104 |
Just approved |
Image pushed |
/retest |
Hmm @chaodaiG
Different error this time. Do we need to do something to allow for that networking? |
1d683f6
to
a56da70
Compare
3f52773
to
f68dea8
Compare
e154154
to
b1fb8e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chaodaiG @jeremyfaller @whaught this is ready for review now
var _, self, _, _ = runtime.Caller(0) | ||
|
||
// Root returns the filepath to the root of this project. | ||
func Root() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's an LHS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM generally, left a comment
After evaluation, I decided to use chromedp since it's a pure-go solution that should work headlessly on our existing CI infrastructure (fingers crossed). This also adds a few new internal-only packages to help with testing: - `internal/project` - project-wide helpers. Currently the only function is one that returns the filesystem root of the project, which is needed for telling the server where to find its assets. It will also be used by enx-redirector and any other filesystem-ey things. - `internal/envstest` - globally shared test helpers. I'm going to start centralizing things here across all our test suites. This package also includes all the logic and helpers for spinning up a full in-memory UI server (with database and dependencies) for local testing. - `internal/browser` - wrapper around chromedp. It's small, but I expect to add more helpers and things as we expand our testing.
b1fb8e6
to
1248464
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chaodaiG, sethvargo The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
After evaluation, I decided to use chromedp since it's a pure-go solution that should work headlessly on our existing CI infrastructure (fingers crossed).
This also adds a few new internal-only packages to help with testing:
internal/project
- project-wide helpers. Currently the only function is one that returns the filesystem root of the project, which is needed for telling the server where to find its assets. It will also be used by enx-redirector and any other filesystem-ey things.internal/envstest
- globally shared test helpers. I'm going to start centralizing things here across all our test suites. This package also includes all the logic and helpers for spinning up a full in-memory UI server (with database and dependencies) for local testing.internal/browser
- wrapper around chromedp. It's small, but I expect to add more helpers and things as we expand our testing.Release Note