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

docs: add testing documentation for Playwright #823

Conversation

juan-carlos-correa
Copy link

Ref: #822

Initial testing example documentation using Playwright.

Copy link

changeset-bot bot commented May 22, 2024

⚠️ No Changeset found

Latest commit: c1ad878

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented May 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2024 0:50am

applications in a browser.

We can use Playwright to create **integration tests** for our `UploadThing`
funcionality, independently of the frontend framework we are using.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
funcionality, independently of the frontend framework we are using.
functionality, independently of the frontend framework we are using.

We can use Playwright to create **integration tests** for our `UploadThing`
funcionality, independently of the frontend framework we are using.

<Callout type="info">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure that we necessarily have to go to this level of explanation. I'm ok to leave it in, but cc @t3dotgg

test("should upload a file successfully", async ({ page }) => {
// Mock the API endpoint, so we don't actually upload a file
// This is a Next.js API route, but you can replace it with your own
await page.route(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels like the wrong place to be mocking, since the api code is also provided by uploadthing.

might make more sense to be mocking the API calls to uploadthing.com/api that the server code does, but even still I am having difficulty understanding what you are trying to do here.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense to me, specially if the example is suppose to be FE framework agnostic

Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to take a look at how we are doing our mocks with MSW for some inspiration there.

https://github.com/pingdotgg/uploadthing/blob/3376306731d34c36fea8df3c6b117eeb17328f0f/packages/uploadthing/test/__test-helpers.ts

Copy link
Author

Choose a reason for hiding this comment

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

Hey there,

It result that it's pretty complicated to mock the uploadthing endpoints because of the nature of Next.js. Explanation:

  1. Next.js is fullstack framework.
  2. Playwright is a E2E testing tool.
  3. Playwright can only mocks the network requests that are made in the client side.
  4. The Uploadthing library for Next.js approach is to create a Next.js api routes where internally is the logic and rules in order to actually fetch de files to the Uploadthing APIs.
  5. The Uploadthing internal implementation is executed in the server side, not exposed to the client.

Therefore, I was not able to mock the real Uploadthing endpoints 😞

So probably having the example mocking the Next.js API route is the only way, so far.

What I have seen is a combination of Mock Service Worker with Playwright, but it looks more complex than I would like to see when working with testing.

What are your thoughts?

@t3dotgg
Copy link
Member

t3dotgg commented Sep 6, 2024

IMO, integration testing of dependencies like this is not a great practice. The effort to "make it work" doesn't seem worthwhile relative to the potential safety and peace of mind after implementing.

If you've gotten actual value from including tests like this with your usage of UploadThing, let me know and I'll reconsider

@t3dotgg t3dotgg closed this Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants