Skip to content

Commit ed44b07

Browse files
ankur22AgnesTouletinancgumus
authored
🤖 Merge PR DefinitelyTyped#74019 Type updates for v1.4.0 k6 release by @ankur22
Co-authored-by: AgnesToulet <[email protected]> Co-authored-by: İnanç Gümüş <[email protected]>
1 parent 8cf0676 commit ed44b07

File tree

4 files changed

+145
-3
lines changed

4 files changed

+145
-3
lines changed

‎types/k6/browser/index.d.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference lib="dom" />
2+
13
/**
24
* Represents event-specific properties. Refer to the events documentation for
35
* the lists of initial properties:
@@ -12,6 +14,7 @@
1214
export type EvaluationArgument = object;
1315

1416
export type PageFunction<Arg, R> = string | ((arg: Unboxed<Arg>) => R);
17+
export type PageFunctionOn<On, Arg2, R> = string | ((on: On, arg2: Unboxed<Arg2>) => R);
1518

1619
export type Unboxed<Arg> = Arg extends [infer A0, infer A1] ? [Unboxed<A0>, Unboxed<A1>]
1720
: Arg extends [infer A0, infer A1, infer A2] ? [Unboxed<A0>, Unboxed<A1>, Unboxed<A2>]
@@ -2997,6 +3000,35 @@ export interface Locator {
29973000
*/
29983001
dblclick(options?: MouseMoveOptions & MouseMultiClickOptions): Promise<void>;
29993002

3003+
/**
3004+
* Evaluates the page function and returns its return value.
3005+
* This method passes this locator's matching element as the first argument to the page function.
3006+
*
3007+
* @param pageFunction Function to be evaluated in the page context.
3008+
* @param arg Optional argument to pass to `pageFunction`.
3009+
* @returns Return value of `pageFunction`.
3010+
*/
3011+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
3012+
evaluate<R, E extends SVGElement | HTMLElement, Arg>(
3013+
pageFunction: PageFunctionOn<E, Arg, R>,
3014+
arg?: Arg,
3015+
): Promise<R>;
3016+
3017+
/**
3018+
* Evaluates the page function and returns its return value as a [JSHandle].
3019+
* This method passes this locator's matching element as the first argument to the page function.
3020+
* Unlike `evaluate`, `evaluateHandle` returns the value as a `JSHandle`
3021+
*
3022+
* @param pageFunction Function to be evaluated in the page context.
3023+
* @param arg Optional argument to pass to `pageFunction`.
3024+
* @returns JSHandle of the return value of `pageFunction`.
3025+
*/
3026+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
3027+
evaluateHandle<R, E extends SVGElement | HTMLElement, Arg>(
3028+
pageFunction: PageFunctionOn<E, Arg, R>,
3029+
arg?: Arg,
3030+
): Promise<JSHandle<R>>;
3031+
30003032
/**
30013033
* Use this method to select an `input type="checkbox"`.
30023034
* @param options Options to use.
@@ -5424,6 +5456,16 @@ export interface Page {
54245456
},
54255457
): Promise<void>;
54265458

5459+
/**
5460+
* Removes all existing routes for the `url`.
5461+
*/
5462+
unroute(url: string | RegExp): Promise<void>;
5463+
5464+
/**
5465+
* Removes all routes created with page.route().
5466+
*/
5467+
unrouteAll(): Promise<void>;
5468+
54275469
/**
54285470
* Returns the page's URL.
54295471
*/
@@ -5621,6 +5663,36 @@ export interface Page {
56215663
},
56225664
): Promise<Response | null>;
56235665

5666+
/**
5667+
* Waits for the page to match against the URL for a Request object
5668+
*
5669+
* @example
5670+
* ```js
5671+
* const requestPromise = page.waitForRequest('https://example.com/resource');
5672+
* await page.goto('https://example.com/resource');
5673+
* const request = await requestPromise;
5674+
* ```
5675+
*
5676+
* @param request Request URL string or regex to match against Request object.
5677+
* @param options Options to use.
5678+
*/
5679+
waitForRequest(
5680+
request: string | RegExp,
5681+
options?: {
5682+
/**
5683+
* Maximum operation time in milliseconds. Defaults to `30` seconds.
5684+
* The default value can be changed via the
5685+
* browserContext.setDefaultNavigationTimeout(timeout),
5686+
* browserContext.setDefaultTimeout(timeout),
5687+
* page.setDefaultNavigationTimeout(timeout) or
5688+
* page.setDefaultTimeout(timeout) methods.
5689+
*
5690+
* Setting the value to `0` will disable the timeout.
5691+
*/
5692+
timeout?: number;
5693+
},
5694+
): Promise<Request | null>;
5695+
56245696
/**
56255697
* **NOTE** Use web assertions that assert visibility or a locator-based
56265698
* locator.waitFor([options]) instead.

‎types/k6/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/k6",
4-
"version": "1.3.9999",
4+
"version": "1.4.9999",
55
"type": "module",
66
"projects": [
77
"https://grafana.com/docs/k6/latest/"

‎types/k6/test/browser.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,15 @@ async function test() {
10451045
// $ExpectType Promise<Response | null>
10461046
page.waitForResponse("https://example.com", { timeout: 10000 });
10471047

1048+
// @ts-expect-error
1049+
page.waitForRequest();
1050+
// $ExpectType Promise<Request | null>
1051+
page.waitForRequest("https://example.com");
1052+
// $ExpectType Promise<Request | null>
1053+
page.waitForRequest(/.*\/api\/pizza$/);
1054+
// $ExpectType Promise<Request | null>
1055+
page.waitForRequest("https://example.com", { timeout: 10000 });
1056+
10481057
// @ts-expect-error
10491058
page.waitForSelector();
10501059
// $ExpectType Promise<ElementHandle>
@@ -1080,6 +1089,31 @@ async function test() {
10801089
// $ExpectType Promise<ElementHandle[]>
10811090
page.$$(selector);
10821091

1092+
// $ExpectType Promise<void>
1093+
page.route("https://example.com/logo.png", () => {});
1094+
// $ExpectType Promise<void>
1095+
page.route(/.*\/logo.png/i, () => {});
1096+
// @ts-expect-error
1097+
page.route();
1098+
// @ts-expect-error
1099+
page.route(123, () => {});
1100+
// @ts-expect-error
1101+
page.route("https://example.com/logo.png");
1102+
1103+
// $ExpectType Promise<void>
1104+
page.unroute("https://example.com/logo.png");
1105+
// $ExpectType Promise<void>
1106+
page.unroute(/.*\/logo.png/i);
1107+
// @ts-expect-error
1108+
page.unroute();
1109+
// @ts-expect-error
1110+
page.unroute(123);
1111+
1112+
// $ExpectType Promise<void>
1113+
page.unrouteAll();
1114+
// @ts-expect-error
1115+
page.unrouteAll("https://example.com/logo.png");
1116+
10831117
//
10841118
// Keyboard
10851119
//
@@ -1549,6 +1583,44 @@ async function test() {
15491583
// @ts-expect-error
15501584
locator.getByPlaceholder("[email protected]", { exact: "true" });
15511585

1586+
// @ts-expect-error
1587+
locator.evaluate();
1588+
// @ts-expect-error
1589+
locator.evaluate(1);
1590+
// @ExpectType Promise<void>
1591+
locator.evaluate("");
1592+
// @ExpectType Promise<void>
1593+
locator.evaluate(() => {});
1594+
// @ExpectType Promise<string>
1595+
locator.evaluate(() => {
1596+
"";
1597+
});
1598+
// @ExpectType Promise<string>
1599+
locator.evaluate((elem: HTMLElement, a: string) => {
1600+
a;
1601+
}, "");
1602+
// @ExpectType Promise<string[]>
1603+
locator.evaluate((el: HTMLElement, a: string[]) => a, [""]);
1604+
1605+
// @ts-expect-error
1606+
locator.evaluateHandle();
1607+
// @ts-expect-error
1608+
locator.evaluateHandle(1);
1609+
// @ExpectType Promise<JSHandle>
1610+
locator.evaluateHandle("");
1611+
// @ExpectType Promise<JSHandle>
1612+
locator.evaluateHandle(() => {});
1613+
// @ExpectType Promise<JSHandle>
1614+
locator.evaluateHandle(() => {
1615+
"";
1616+
});
1617+
// @ExpectType Promise<JSHandle>
1618+
locator.evaluateHandle((el: HTMLElement, a: string) => {
1619+
a;
1620+
}, "");
1621+
// @ExpectType Promise<JSHandle>
1622+
locator.evaluateHandle((el: HTMLElement, a: string[]) => a, [""]);
1623+
15521624
//
15531625
// JSHandle
15541626
//

‎types/k6/test/global.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// open
2-
// @ts-expect-error
32
open();
43
// @ts-expect-error
54
open(5);
@@ -8,7 +7,6 @@ const text: string = open("file.txt");
87
open(5, "b");
98
// @ts-expect-error
109
open("file.bin", 5);
11-
// @ts-expect-error
1210
open("file.bin", "notamode");
1311
const arrayBuffer: ArrayBuffer = open("file.bin", "b");
1412
// @ts-expect-error

0 commit comments

Comments
 (0)