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

Refactor options to const #1044

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft

Refactor options to const #1044

wants to merge 41 commits into from

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Sep 21, 2023

What?

This refactors the key strings to consts.

Why?

The main reason is to avoid typos when writing out new option parsers or working with options in other ways. Note thought that I've not done a refactor for all configs, e.g. the options for newContext.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Motivated by: comment.

ankur22 and others added 30 commits September 21, 2023 10:36
This is where the options or predicate function will be parsed. This
aligns with how we're parsing options in other APIs.
This copies the parsing logic from the existing browserContext.waitFor
Event() into the new WaitForEventOptions type's parse method. It also
modifies it so that the data that is parsed is updated in the type and
during parsing it will return an error instead of panicking.
This commit refactors the code so that it works with the new
WaitForEventOptions type.
This now defaults to the browserContext's default timeout. This should
fix the confusion of mixing seconds and milliseconds when working with
the timeouts in this API.

NOTE though that there is a default timeout of 30 seconds now, whereas
in PW there is no timeout unless one is set explicitly in
browserContext using SetDefaultTimeout.
At the moment we only support working with the new page creation event
(i.e. "page" event) when waitForEvent is used. This commit helps
clarify this to users.
When working with waitForEvent we now notify the user if the timeout
was reached, or whether the context is closed (i.e. the test iteration
has ended).
Instead of panicking when an error occurs, this commit refactors
waitForEvent to return an error back to the mapping layer where it can
do what it needs with the error.
This new way of working allows us to test the code with integration
tests, and it still works as expected when we run the API through a
test script. Before it seemed overly complex to try to create a goja
object that required reflection.
It's valid for a user not to pass anything but the event. A change
needed to be made to allow for a nil predicate to allow for this.
When a return occurs from runWaitForEventHandler it needs to perform
the same steps for all returns out of the method. This refactors those
duplicate steps into a defer function.
waitForEvent is useless without it being promisified. This changes
that so that waitForEvent returns a promise, allowing the user to set
a waitForEvent and then call further APIs which will unblock the
waitForEvent when possible (only for new page creations and if the
predicate function is set and returns a truthy value).
This helps make things more maintainable and reduces the risk of typos
when working with the event types for waitForEvent.

Co-authored-by: İnanç Gümüş <[email protected]>
This helps tidy up the code and keeps the happy path more left aligned.

Co-authored-by: İnanç Gümüş <[email protected]>
This just helps make the line lengths of comments consistent.
This not only use a more concise naming convention it also adds '_' to
the names, which makes it easier to find tests if they fail.

Co-authored-by: İnanç Gümüş <[email protected]>
This will help avoid typo issues and make the code more maintainable.
@ankur22 ankur22 changed the base branch from main to refactor/wait-for-event September 21, 2023 12:57
@ankur22 ankur22 mentioned this pull request Sep 21, 2023
3 tasks
@ankur22 ankur22 marked this pull request as draft September 21, 2023 13:35
@ankur22 ankur22 force-pushed the refactor/wait-for-event branch 2 times, most recently from 9c20fdd to 41b5d7f Compare September 26, 2023 09:23
Base automatically changed from refactor/wait-for-event to main September 26, 2023 09:49
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.

1 participant