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

Create first e2e tests for cert creation #28

Merged
merged 22 commits into from Dec 4, 2022
Merged

Conversation

DavidRV00
Copy link
Collaborator

I've created a couple basic e2e tests to test certificate creation in the UI.
Also a couple quality-of-life improvements related to tests and continuous integration.

See the individual commit messages for more details.

Critiques are extremely welcome; I'm still very new to Javascript and playwright!

This makes it so that you don't have to wait to PR to see the github
workflow, if you've created a new development branch to work on your
feature.
Chromium tests are flaking pretty frequently. This will allow for less
frequent manually rerunning while doing local e2e test runs.
I've added two basic tests:
- Just create a cert and check that we end up on the right page
- Create a cert and verify that the fields are filled out

I've added some TODOs to verify even more fields than I've checked so
far.
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Retry on both CI and local dev */
retries: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you already notice brittleness or is this just in case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed, pretty frequently, the Chromium browser will just sit and timeout after 30 seconds waiting for the first page to load. Retries have made it work.

Not sure why; Firefox and Webkit have not experienced this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, weird. Thanks!

@Telofy
Copy link
Contributor

Telofy commented Nov 29, 2022

Is the test ready for, uh, testing? ^.^ I’ve had a look over the code but haven’t run it locally yet.

@DavidRV00
Copy link
Collaborator Author

Yup, it's ready. You should see the tests running in the Github workflow, and they work locally for me.

(Also I've "tested the tests" by modifying the assertions to incorrect values, seeing them fail, then switching back to the correct values and seeing them pass. You can try this exercise as well if you want more hands-on verification)

@DavidRV00
Copy link
Collaborator Author

Also, I recommend going into the playwright config locally and setting Headless to False; that'll let you see the test run in actual browser windows.

@Telofy
Copy link
Contributor

Telofy commented Nov 29, 2022

I surmised that the server might not be ready right away when it starts listening to the port. With the url parameter, Playwright instead checks if the server is running by sending HTTP requests. Fingers crossed that’s the real reason. (I also deleted the old sample test that probably came with the framework.)

I noticed another issue though (at least on my machine): The new docker-compose file is fairly inert apart from changing the port: The database seems to be the same. So if I run the tests and then resume my normal dev work, the test certs are in the database.

  1. Could you please change it such that the database is a separate one – either a separate Postgres with a different data directory or a database with a different name (say, im-app-test) in the same Postgres?
  2. It would also be convenient if the test web server could listen at 3001 so that I don’t need to stop my dev web server.

Thankies!

@DavidRV00
Copy link
Collaborator Author

Thanks for looking into this stuff; great ideas. Yep I can get on all this soon! Expect more additions to this PR within the next couple days.

Now running the e2e tests locally won't modify your local im-app
database anymore. They get their own im-app-test database.
Now, locally, you don't need to run `cp .env.test .env` anymore.
@DavidRV00
Copy link
Collaborator Author

@Telofy These changes eliminate all sources of local conflict I could find (and also we don't need to cp .env.test .env when running locally anymore. The tests will just use .env.test automatically).

I've tried a few scenarios running the dev server on 3000 while simultaneously running local e2e tests, and it all seems to go fine.

@Telofy
Copy link
Contributor

Telofy commented Dec 3, 2022

Awesome! That all works now! It just looks like my fix didn’t fix the brittleness at all… I’ll look into it some more.

Copy link
Collaborator Author

@DavidRV00 DavidRV00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, looks like this change is making the e2e tests fail for some reason?

@DavidRV00
Copy link
Collaborator Author

Seems that the NEXTAUTH_URL variable is actually required: https://next-auth.js.org/warnings#nextauth_url

@Telofy
Copy link
Contributor

Telofy commented Dec 4, 2022

Yeah, was a mistake to remove it… I’ve found a way to reference other variables in .env, so I’m going with that now to avoid the duplication.

@Telofy
Copy link
Contributor

Telofy commented Dec 4, 2022

I’ve fixed my mistake, and I hope I’ve resolved the flakiness. I’ve switched to using the production build for the tests, which makes the start of the server quick. Other advantages are that it has sometimes detected errors for me that the type check couldn’t find and that didn’t come up in my tested through the dev server, and that the behavior is generally closer to production. But the disadvantage is that the startup time of the tests is long now. :-/

I also ran into this bug: microsoft/playwright#18865. Luckily fixed in the latest version.

@Telofy Telofy merged commit 3a9a1c6 into development Dec 4, 2022
@Telofy Telofy deleted the cert-create-e2e branch December 4, 2022 03:19
@DavidRV00
Copy link
Collaborator Author

Awesome, great to have this merged, and thanks for the improvements!

Ah yeah, it's a shame test startup will take longer now. Probably worth it though.

@Telofy Telofy added this to the Release 2.3 milestone Dec 28, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants