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

[Issue #2537] Create e2e tests for subscribe page #3787

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

KeithNava
Copy link
Contributor

Summary

Fixes #2537

Time to review: 15 mins

Changes proposed

Creates the E2E tests for the /subscribe page.

Context for reviewers

Because of some challenges with mocking API calls within NextJS' server components in the current version (v15 as of this PR) we had to utilize some experimental features - https://github.com/vercel/next.js/tree/canary/packages/next/src/experimental/testmode/playwright

Warning

There is some risk in depending on experimental features but this does appear to be the recommended path today

  1. Subject to Breaking Changes
  • Experimental features can change without prior notice
  • May introduce unexpected behavior in future releases
  • Not recommended for production-critical applications
  1. Performance and Stability Risks
  • Not fully tested across all use cases
  • Potential performance overhead
  • May require additional debugging
  1. Upgrade Considerations
  • Always review release notes when updating Next.js
  • Experimental configs might require manual migration
  • Potential need to refactor code after updates

Additional information

subscribe spec ts-passing

@@ -101,6 +101,9 @@ const nextConfig = {
"types",
],
},
experimental: {
testProxy: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

🆒

await page.getByRole("button", { name: /subscribe/i }).click();

await expect(page.getByTestId("errorMessage")).toHaveCount(1);
await expect(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this test seems to be failing, and I think it's because the API request isn't being proxied for some reason. Logging out the requests that come through the proxy locally it seems to be only catching a google analytics request at the moment. My guess is that's because the request for subscription is in a server action, so it isn't being made from the client directly?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's interesting that this test is failing now in CI, but on my local, it seems to be passing and showing that it's mocking the server-side request. I will take a deeper look and will definitely check out MSW. Thanks @doug-s-nava @acouch !
subscribe-spec-e2e

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@doug-s-nava @acouch I think I've figured out what might be happening. I noticed this error in the github actions logs [WebServer] Error subscribing user: Failed to parse URL from /subscribe. I was able to reproduce this error locally by unsetting the SENDY_API_URL variable, as opposed to setting it to http://localhost:3000.

Can you confirm that SENDY_API_URL variable is set to something in the action?

Copy link
Collaborator

Choose a reason for hiding this comment

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

the e2e test action does not have the sendy variables set, so that could definitely be what's going on here. Since we're mocking the request, hopefully the sendy url won't matter, and we can set it to be something random and harmless rather than using the real sendy url.

if you want to test that out, this is where you'd want to look in the code

cat .env.development >> .env.local

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks so much @doug-s-nava I actually was able to get it to work by defaulting to localhost if that SENDY_API_URL variable is not set 4a7113c

Copy link
Collaborator

Choose a reason for hiding this comment

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

Glad you cracked the issue! This change is probably fine but I'd rather avoid any change to the application itself if we can make a change just to the testing configuration. Can you try adding the environment variable to the action definition instead of defaulting within the app itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@doug-s-nava doug-s-nava left a comment

Choose a reason for hiding this comment

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

✅ ✅ ✅ ✅

Copy link
Collaborator

@coilysiren coilysiren left a comment

Choose a reason for hiding this comment

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

defer to others 🙏🏼

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.

Add e2e tests for /subscribe
4 participants