diff --git a/types/k6/experimental/browser.d.ts b/types/k6/experimental/browser.d.ts index d41ff24f1bd118..03b6574e2f5ec7 100644 --- a/types/k6/experimental/browser.d.ts +++ b/types/k6/experimental/browser.d.ts @@ -3683,7 +3683,7 @@ export interface Request { * lower-case. * @returns The headers object. */ - allHeaders(): Record; + allHeaders(): Promise>; /** * @returns the Frame that initiated this request @@ -3703,14 +3703,14 @@ export interface Request { * `Set-Cookie`, appear in the array multiple times. * @returns An array of all the request HTTP headers. */ - headersArray(): Array<{ name: string; value: string }>; + headersArray(): Promise>; /** * Retuns the value of the header matching the name. The name is case insensitive. * @param name Header name to retrieve value for. * @returns The value of the header matching the name. */ - headerValue(name: string): string | null; + headerValue(name: string): Promise; /** * @returns a boolean stating whether the request is for a navigation @@ -3727,7 +3727,7 @@ export interface Request { * Contains the request's post body, if any. * @returns request's post body */ - postData(): string; + postData(): string | null; /** * Request's post body in a binary form, if any. @@ -3749,13 +3749,13 @@ export interface Request { * due to error. * @returns The `Response` object, or `null` if the response was not received due to error. */ - response(): Response | null; + response(): Promise; /** * Returns resource size information for given request. * @returns Resource size information for given request. */ - size(): { body: number; headers: number }; + size(): Promise<{ body: number; headers: number }>; /** * Returns resource timing information for given request. Most of the timing values @@ -3781,13 +3781,13 @@ export interface Response { * lower-case. * @returns The headers object. */ - allHeaders(): Record; + allHeaders(): Promise>; /** * Returns the response body. * @returns A buffer with response body. */ - body(): ArrayBuffer; + body(): Promise; /** * @returns the Frame that initiated this response @@ -3807,7 +3807,7 @@ export interface Response { * appear in the array multiple times. * @returns An array of all the request HTTP headers. */ - headersArray(): Array<{ name: string; value: string }>; + headersArray(): Promise>; /** * Returns the value of the header matching the name. The name is case insensitive. @@ -3817,7 +3817,7 @@ export interface Response { * @param name Header name to retrieve value for. * @returns The header value for the given name. */ - headerValue(name: string): string | null; + headerValue(name: string): Promise; /** * Returns all values of the headers matching the name, for example `set-cookie`. @@ -3825,14 +3825,14 @@ export interface Response { * @param name Header name to retrieve values for. * @returns An array of header values for the given name. */ - headerValues(name: string): string[]; + headerValues(name: string): Promise; /** * Returns the JSON representation of response body. Throws if response body is not * parsable via `JSON.parse`. * @returns JSON representation of response body. */ - json(): any; + json(): Promise; /** * Contains a boolean stating whether the response was successful (status in the @@ -3851,13 +3851,13 @@ export interface Response { * Security details associated with this response. * @returns A matching `SecurityDetailsObject` */ - securityDetails(): SecurityDetailsObject | null; + securityDetails(): Promise; /** * Returns the IP address and port of the server for this response. * @returns The IP address and port of the server */ - serverAddr(): { ipAddress: string; port: number } | null; + serverAddr(): Promise<{ ipAddress: string; port: number } | null>; /** * Contains the status code of the response (e.g., 200 for a success). @@ -3875,7 +3875,7 @@ export interface Response { * The size of the response body and the headers. * @returns The size of the response body and the headers. */ - size(): { body: number; headers: number }; + size(): Promise<{ body: number; headers: number }>; /** * Contains the URL of the response. diff --git a/types/k6/test/browser.ts b/types/k6/test/browser.ts index 6f28067b182276..daf9db38880ad2 100644 --- a/types/k6/test/browser.ts +++ b/types/k6/test/browser.ts @@ -1203,105 +1203,105 @@ async function test() { // // Request // - const request = page.goto(url).then(r => r?.request()); + const request = await page.goto(url).then(r => r?.request()!); - // $ExpectType Promise | undefined> - request.then(r => r?.allHeaders()); + // $ExpectType Promise> + request.allHeaders(); - // $ExpectType Promise - request.then(r => r?.frame()); + // $ExpectType Frame + request.frame(); - // $ExpectType Promise | undefined> - request.then(r => r?.headers()); + // $ExpectType Record + request.headers(); - // $ExpectType Promise<{ name: string; value: string; }[] | undefined> - request.then(r => r?.headersArray()); + // $ExpectType Promise<{ name: string; value: string; }[]> + request.headersArray(); // @ts-expect-error - request.then(r => r?.headerValue()); - // $ExpectType Promise - request.then(r => r?.headerValue("content-type")); + request.headerValue(); + // $ExpectType Promise + request.headerValue("content-type"); - // $ExpectType Promise - request.then(r => r?.isNavigationRequest()); + // $ExpectType boolean + request.isNavigationRequest(); - // $ExpectType Promise - request.then(r => r?.method()); + // $ExpectType string + request.method(); - // $ExpectType Promise - request.then(r => r?.postData()); + // $ExpectType string | null + request.postData(); - // $ExpectType Promise - request.then(r => r?.postDataBuffer()); + // $ExpectType ArrayBuffer | null + request.postDataBuffer(); - // $ExpectType Promise<"document" | "stylesheet" | "image" | "media" | "font" | "script" | "texttrack" | "xhr" | "fetch" | "eventsource" | "websocket" | "manifest" | "other" | undefined> - request.then(r => r?.resourceType()); + // $ExpectType ResourceType + request.resourceType(); - // $ExpectType Promise - request.then(r => r?.response()); + // $ExpectType Promise + request.response(); - // $ExpectType Promise<{ body: number; headers: number; } | undefined> - request.then(r => r?.size()); + // $ExpectType Promise<{ body: number; headers: number; }> + request.size(); - // $ExpectType Promise - request.then(r => r?.timing()); + // $ExpectType ResourceTiming + request.timing(); // // Response // - const response = page.goto(url); + const response = await page.goto(url).then(r => r!); - // $ExpectType Promise | undefined> - response.then(r => r?.allHeaders()); + // $ExpectType Promise> + response.allHeaders(); - // $ExpectType Promise - response.then(r => r?.body()); + // $ExpectType Promise + response.body(); - // $ExpectType Promise - response.then(r => r?.frame()); + // $ExpectType Frame + response.frame(); - // $ExpectType Promise | undefined> - response.then(r => r?.headers()); + // $ExpectType Record + response.headers(); - // $ExpectType Promise<{ name: string; value: string; }[] | undefined> - response.then(r => r?.headersArray()); + // $ExpectType Promise<{ name: string; value: string; }[]> + response.headersArray(); // @ts-expect-error - response.then(r => r?.headerValue()); - // $ExpectType Promise - response.then(r => r?.headerValue("content-type")); + response.headerValue(); + // $ExpectType Promise + response.headerValue("content-type"); // @ts-expect-error - response.then(r => r?.headerValues()); - // $ExpectType Promise - response.then(r => r?.headerValues("content-type")); + response.headerValues(); + // $ExpectType Promise + response.headerValues("content-type"); // $ExpectType Promise - response.then(r => r?.json()); + response.json(); - // $ExpectType Promise - response.then(r => r?.ok()); + // $ExpectType boolean + response.ok(); - // $ExpectType Promise - response.then(r => r?.request()); + // $ExpectType Request + response.request(); - // $ExpectType Promise - response.then(r => r?.securityDetails()); + // $ExpectType Promise + response.securityDetails(); - // $ExpectType Promise<{ ipAddress: string; port: number; } | null | undefined> - response.then(r => r?.serverAddr()); + // $ExpectType Promise<{ ipAddress: string; port: number; } | null> + response.serverAddr(); - // $ExpectType Promise - response.then(r => r?.status()); + // $ExpectType number + response.status(); - // $ExpectType Promise - response.then(r => r?.statusText()); + // $ExpectType string + response.statusText(); - // $ExpectType Promise<{ body: number; headers: number; } | undefined> - response.then(r => r?.size()); + // $ExpectType Promise<{ body: number; headers: number; }> + response.size(); - // $ExpectType Promise - response.then(r => r?.url()); + // $ExpectType string + response.url(); // // ElementHandle