-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
// $ExpectType Promise<{ body: number; headers: number; }> | ||
response.size(); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. Thanks 🙇
pnpm test <package to test>
.- Migrate Response APIs to async xk6-browser#1309
- Migrate Request APIs to async xk6-browser#1308