From ed44b0728d1da5d74978d6d831e56e22065fcb4a Mon Sep 17 00:00:00 2001 From: Ankur Date: Mon, 10 Nov 2025 13:47:19 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#74019=20Type=20upd?= =?UTF-8?q?ates=20for=20v1.4.0=20k6=20release=20by=20@ankur22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: AgnesToulet <35176601+AgnesToulet@users.noreply.github.com> Co-authored-by: İnanç Gümüş --- types/k6/browser/index.d.ts | 72 +++++++++++++++++++++++++++++++++++++ types/k6/package.json | 2 +- types/k6/test/browser.ts | 72 +++++++++++++++++++++++++++++++++++++ types/k6/test/global.ts | 2 -- 4 files changed, 145 insertions(+), 3 deletions(-) diff --git a/types/k6/browser/index.d.ts b/types/k6/browser/index.d.ts index 577a878ced4916..0bd90326c4fc8e 100644 --- a/types/k6/browser/index.d.ts +++ b/types/k6/browser/index.d.ts @@ -1,3 +1,5 @@ +/// + /** * Represents event-specific properties. Refer to the events documentation for * the lists of initial properties: @@ -12,6 +14,7 @@ export type EvaluationArgument = object; export type PageFunction = string | ((arg: Unboxed) => R); +export type PageFunctionOn = string | ((on: On, arg2: Unboxed) => R); export type Unboxed = Arg extends [infer A0, infer A1] ? [Unboxed, Unboxed] : Arg extends [infer A0, infer A1, infer A2] ? [Unboxed, Unboxed, Unboxed] @@ -2997,6 +3000,35 @@ export interface Locator { */ dblclick(options?: MouseMoveOptions & MouseMultiClickOptions): Promise; + /** + * Evaluates the page function and returns its return value. + * This method passes this locator's matching element as the first argument to the page function. + * + * @param pageFunction Function to be evaluated in the page context. + * @param arg Optional argument to pass to `pageFunction`. + * @returns Return value of `pageFunction`. + */ + // eslint-disable-next-line @definitelytyped/no-unnecessary-generics + evaluate( + pageFunction: PageFunctionOn, + arg?: Arg, + ): Promise; + + /** + * Evaluates the page function and returns its return value as a [JSHandle]. + * This method passes this locator's matching element as the first argument to the page function. + * Unlike `evaluate`, `evaluateHandle` returns the value as a `JSHandle` + * + * @param pageFunction Function to be evaluated in the page context. + * @param arg Optional argument to pass to `pageFunction`. + * @returns JSHandle of the return value of `pageFunction`. + */ + // eslint-disable-next-line @definitelytyped/no-unnecessary-generics + evaluateHandle( + pageFunction: PageFunctionOn, + arg?: Arg, + ): Promise>; + /** * Use this method to select an `input type="checkbox"`. * @param options Options to use. @@ -5424,6 +5456,16 @@ export interface Page { }, ): Promise; + /** + * Removes all existing routes for the `url`. + */ + unroute(url: string | RegExp): Promise; + + /** + * Removes all routes created with page.route(). + */ + unrouteAll(): Promise; + /** * Returns the page's URL. */ @@ -5621,6 +5663,36 @@ export interface Page { }, ): Promise; + /** + * Waits for the page to match against the URL for a Request object + * + * @example + * ```js + * const requestPromise = page.waitForRequest('https://example.com/resource'); + * await page.goto('https://example.com/resource'); + * const request = await requestPromise; + * ``` + * + * @param request Request URL string or regex to match against Request object. + * @param options Options to use. + */ + waitForRequest( + request: string | RegExp, + options?: { + /** + * Maximum operation time in milliseconds. Defaults to `30` seconds. + * The default value can be changed via the + * browserContext.setDefaultNavigationTimeout(timeout), + * browserContext.setDefaultTimeout(timeout), + * page.setDefaultNavigationTimeout(timeout) or + * page.setDefaultTimeout(timeout) methods. + * + * Setting the value to `0` will disable the timeout. + */ + timeout?: number; + }, + ): Promise; + /** * **NOTE** Use web assertions that assert visibility or a locator-based * locator.waitFor([options]) instead. diff --git a/types/k6/package.json b/types/k6/package.json index 06ebce9a9def0b..abda55ebde008b 100644 --- a/types/k6/package.json +++ b/types/k6/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/k6", - "version": "1.3.9999", + "version": "1.4.9999", "type": "module", "projects": [ "https://grafana.com/docs/k6/latest/" diff --git a/types/k6/test/browser.ts b/types/k6/test/browser.ts index 896c6319f0530e..e8a7c25a58613d 100644 --- a/types/k6/test/browser.ts +++ b/types/k6/test/browser.ts @@ -1045,6 +1045,15 @@ async function test() { // $ExpectType Promise page.waitForResponse("https://example.com", { timeout: 10000 }); + // @ts-expect-error + page.waitForRequest(); + // $ExpectType Promise + page.waitForRequest("https://example.com"); + // $ExpectType Promise + page.waitForRequest(/.*\/api\/pizza$/); + // $ExpectType Promise + page.waitForRequest("https://example.com", { timeout: 10000 }); + // @ts-expect-error page.waitForSelector(); // $ExpectType Promise @@ -1080,6 +1089,31 @@ async function test() { // $ExpectType Promise page.$$(selector); + // $ExpectType Promise + page.route("https://example.com/logo.png", () => {}); + // $ExpectType Promise + page.route(/.*\/logo.png/i, () => {}); + // @ts-expect-error + page.route(); + // @ts-expect-error + page.route(123, () => {}); + // @ts-expect-error + page.route("https://example.com/logo.png"); + + // $ExpectType Promise + page.unroute("https://example.com/logo.png"); + // $ExpectType Promise + page.unroute(/.*\/logo.png/i); + // @ts-expect-error + page.unroute(); + // @ts-expect-error + page.unroute(123); + + // $ExpectType Promise + page.unrouteAll(); + // @ts-expect-error + page.unrouteAll("https://example.com/logo.png"); + // // Keyboard // @@ -1549,6 +1583,44 @@ async function test() { // @ts-expect-error locator.getByPlaceholder("name@example.com", { exact: "true" }); + // @ts-expect-error + locator.evaluate(); + // @ts-expect-error + locator.evaluate(1); + // @ExpectType Promise + locator.evaluate(""); + // @ExpectType Promise + locator.evaluate(() => {}); + // @ExpectType Promise + locator.evaluate(() => { + ""; + }); + // @ExpectType Promise + locator.evaluate((elem: HTMLElement, a: string) => { + a; + }, ""); + // @ExpectType Promise + locator.evaluate((el: HTMLElement, a: string[]) => a, [""]); + + // @ts-expect-error + locator.evaluateHandle(); + // @ts-expect-error + locator.evaluateHandle(1); + // @ExpectType Promise + locator.evaluateHandle(""); + // @ExpectType Promise + locator.evaluateHandle(() => {}); + // @ExpectType Promise + locator.evaluateHandle(() => { + ""; + }); + // @ExpectType Promise + locator.evaluateHandle((el: HTMLElement, a: string) => { + a; + }, ""); + // @ExpectType Promise + locator.evaluateHandle((el: HTMLElement, a: string[]) => a, [""]); + // // JSHandle // diff --git a/types/k6/test/global.ts b/types/k6/test/global.ts index 83889d40581eb2..a2ce55f469ea6f 100644 --- a/types/k6/test/global.ts +++ b/types/k6/test/global.ts @@ -1,5 +1,4 @@ // open -// @ts-expect-error open(); // @ts-expect-error open(5); @@ -8,7 +7,6 @@ const text: string = open("file.txt"); open(5, "b"); // @ts-expect-error open("file.bin", 5); -// @ts-expect-error open("file.bin", "notamode"); const arrayBuffer: ArrayBuffer = open("file.bin", "b"); // @ts-expect-error