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

change waitFor brace style, switch interval default #10662

Closed
wants to merge 1 commit into from

Conversation

phryneas
Copy link
Member

do not merge before #10661 has been merged

This PR changes from

waitFor(() => {
  expect(...)
}, {interval: 1}
)

to

waitFor(() => expect(...))

in a ton of places,
and in return replaced

waitFor(() => {
  expect(...)
})

with

waitFor(
  () => expect(...),
  {interval: 50}
)

We used interval: 1 a lot more often than skipping the parameter, and like this, it makes it much more obvious where we still had the slower default. We might want to revisit those places.

I've also highlighted some waitFor instances that just seem wrong, but I didn't change any runtime behaviour of the tests - that's for another PR.

I've also dropped the method body braces where there was only one statement in waitFor, as that compacts the tests a bit.

do not merge before #10661 has been merged

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2023

⚠️ No Changeset found

Latest commit: f445736

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

@lhmzhou lhmzhou left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

Yay for reducing test boilerplate!

Were you able to automate this with a codemod or editor tricks? If it was all by hand, we should try to get these changes merged sooner, so you don't have to keep rebasing.

Copy link
Contributor

@alessbell alessbell 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
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

I'm gonna be the bad guy here 😜. Check out my comments and let me know what you think.

I'd also like to float the question: is this PR still relevant? We've had it open for some time now unmerged and wasn't sure if thats because it was forgotten or not.

@@ -5260,11 +5250,11 @@ describe("useSuspenseQuery", () => {
},
});

await waitFor(() => {
await waitFor(() =>
Copy link
Member

Choose a reason for hiding this comment

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

Any reason these needed to change? Perhaps I'm picky/selfish, but this seems like a change for the sake of change. I'd prefer to leave these alone for now.

Copy link
Member

Choose a reason for hiding this comment

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

I'll be the bad guy and say I'm not sure I see much meaningful change in this file. It feels like change for the sake of change. Any chance we could revert this?

@@ -27,6 +32,9 @@ import { QueryResult } from "../../types/types";
import { useQuery } from "../useQuery";
import { useMutation } from "../useMutation";

const waitFor: typeof _waitFor = (callback, options) =>
Copy link
Member

Choose a reason for hiding this comment

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

I see enough interval: 50 overrides in here to think that this change doesn't make as big of an impact as normal. Could you perhaps rename this to waitForOne and use that in places where interval: 1 is set? That way we can leave anything with interval: 50 to use the default waitFor function without needing the override.

@@ -19,6 +19,9 @@ import { QueryResult } from "../../types/types";

const IS_REACT_18 = React.version.startsWith("18");

const waitFor: typeof _waitFor = (callback, options) =>
Copy link
Member

Choose a reason for hiding this comment

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

Could we consider naming this waitForOne and use that everywhere we use waitFor with interval: 1? That way its easier to use the built-in waitFor without needing the override where necessary. Thoughts?

@phryneas
Copy link
Member Author

phryneas commented Jul 6, 2023

This was a follow-up PR to the prettier PR, so I guess some of the style changes you are seeing might be prettier-related - with prettier the extra braces mean more newlines and one-line statements became four-line statements, so this is an attempt to undo some of that bloat.

I'm fine with either waitFor or waitForOne, I'd just like to reduce the 100-times-over-repeated {interval: 1}.

So yeah, still relevant, but something I'll probably have to redo after the prettier PR :)

@phryneas
Copy link
Member Author

At this point, I guess this has lost relevance as the new testing style mostly works without waitFor. I'm closing this.

@phryneas phryneas closed this Sep 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants