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

Update Request and Response to return Promise #55

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

allansson
Copy link

Copy link
Author

@allansson allansson left a comment

Choose a reason for hiding this comment

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

Self-review

@@ -1203,105 +1203,105 @@ async function test() {
//
// Request
//
const request = page.goto(url).then(r => r?.request());
Copy link
Author

Choose a reason for hiding this comment

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

Added ! to the returned request to make sure we're testing the right thing. Without it, we need to use ?. everywhere, changing the return type. This is a problem in case we want to do a change where a function actually returns undefined. Then we get a positive on the test for the wrong reason.


// $ExpectType Promise<Record<string, string> | undefined>
request.then(r => r?.allHeaders());
Copy link
Author

Choose a reason for hiding this comment

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

This pattern is what had me believe that the APIs were already async. I updated it to improve readability and to avoid errors where returning a Promise inside another Promise would flatten into a Promise.

Comment on lines +1300 to +1301
// $ExpectType Promise<{ body: number; headers: number; }>
response.size();
Copy link
Author

Choose a reason for hiding this comment

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

This function did not have a counter-part in Playwright, but I assumed that it's signature would be the same as the one in Request.

Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Nice work. Thanks 🙇

@allansson allansson merged commit 6659cc5 into master-async-browser Jun 18, 2024
1 check passed
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.

2 participants