@types/k6 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- k6/README.md +1 -1
- k6/browser/index.d.ts +220 -0
- k6/package.json +3 -3
- k6/{experimental/websockets → websockets}/index.d.ts +16 -17
k6/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package contains type definitions for k6 (https://grafana.com/docs/k6/lates
|
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/k6.
|
|
9
9
|
|
|
10
10
|
### Additional Details
|
|
11
|
-
* Last updated:
|
|
11
|
+
* Last updated: Tue, 10 Feb 2026 09:47:03 GMT
|
|
12
12
|
* Dependencies: none
|
|
13
13
|
|
|
14
14
|
# Credits
|
k6/browser/index.d.ts
CHANGED
|
@@ -3231,6 +3231,29 @@ export interface Locator {
|
|
|
3231
3231
|
*/
|
|
3232
3232
|
press(key: string, options?: KeyboardPressOptions): Promise<void>;
|
|
3233
3233
|
|
|
3234
|
+
/**
|
|
3235
|
+
* Focuses the element and then sends a `keydown`, `keypress`/`input`, and
|
|
3236
|
+
* `keyup` event for each character in the text.
|
|
3237
|
+
*
|
|
3238
|
+
* This method is useful for simulating real user typing behavior when the page
|
|
3239
|
+
* has special keyboard event handling, such as input validation or autocomplete.
|
|
3240
|
+
* For simple text input without special keyboard handling, use {@link fill | fill()}
|
|
3241
|
+
* instead as it's faster and more reliable.
|
|
3242
|
+
*
|
|
3243
|
+
* @example
|
|
3244
|
+
* ```js
|
|
3245
|
+
* // Type text instantly
|
|
3246
|
+
* await locator.pressSequentially('Hello World');
|
|
3247
|
+
*
|
|
3248
|
+
* // Type text with delay between keypresses (like a real user)
|
|
3249
|
+
* await locator.pressSequentially('Hello World', { delay: 100 });
|
|
3250
|
+
* ```
|
|
3251
|
+
*
|
|
3252
|
+
* @param text Text to type into the focused element character by character.
|
|
3253
|
+
* @param options Typing options.
|
|
3254
|
+
*/
|
|
3255
|
+
pressSequentially(text: string, options?: KeyboardPressOptions): Promise<void>;
|
|
3256
|
+
|
|
3234
3257
|
/**
|
|
3235
3258
|
* Type a text into the input field.
|
|
3236
3259
|
* @param text Text to type into the input field.
|
|
@@ -4868,6 +4891,39 @@ export interface Page {
|
|
|
4868
4891
|
*/
|
|
4869
4892
|
on(event: "response", listener: (response: Response) => void): void;
|
|
4870
4893
|
|
|
4894
|
+
/**
|
|
4895
|
+
* Registers a handler function to listen for network requests that
|
|
4896
|
+
* fail to reach the server (DNS errors, connection refused, timeouts, etc.).
|
|
4897
|
+
* The handler will receive an instance of {@link Request}, which includes
|
|
4898
|
+
* information about the failed request.
|
|
4899
|
+
*
|
|
4900
|
+
* **Usage**
|
|
4901
|
+
*
|
|
4902
|
+
* ```js
|
|
4903
|
+
* page.on('requestfailed', request => {
|
|
4904
|
+
* const failure = request.failure();
|
|
4905
|
+
* console.log(`Request failed: ${request.url()}`);
|
|
4906
|
+
* console.log(` Error: ${failure ? failure.errorText : 'unknown'}`);
|
|
4907
|
+
* });
|
|
4908
|
+
* ```
|
|
4909
|
+
*/
|
|
4910
|
+
on(event: "requestfailed", listener: (request: Request) => void): void;
|
|
4911
|
+
|
|
4912
|
+
/**
|
|
4913
|
+
* Registers a handler function to listen for network requests that
|
|
4914
|
+
* successfully complete (receive a response). The handler will receive an
|
|
4915
|
+
* instance of {@link Request}, which includes information about the request.
|
|
4916
|
+
*
|
|
4917
|
+
* **Usage**
|
|
4918
|
+
*
|
|
4919
|
+
* ```js
|
|
4920
|
+
* page.on('requestfinished', request => {
|
|
4921
|
+
* console.log(`Request finished: ${request.method()} ${request.url()}`);
|
|
4922
|
+
* });
|
|
4923
|
+
* ```
|
|
4924
|
+
*/
|
|
4925
|
+
on(event: "requestfinished", listener: (request: Request) => void): void;
|
|
4926
|
+
|
|
4871
4927
|
/**
|
|
4872
4928
|
* Returns the page that opened the current page. The first page that is
|
|
4873
4929
|
* navigated to will have a null opener.
|
|
@@ -4967,6 +5023,37 @@ export interface Page {
|
|
|
4967
5023
|
waitUntil?: "load" | "domcontentloaded" | "networkidle";
|
|
4968
5024
|
}): Promise<Response | null>;
|
|
4969
5025
|
|
|
5026
|
+
/**
|
|
5027
|
+
* Goes back to the previous page in the history.
|
|
5028
|
+
*
|
|
5029
|
+
* @example
|
|
5030
|
+
* ```js
|
|
5031
|
+
* await page.goto('https://example.com');
|
|
5032
|
+
* await page.goto('https://example.com/page2');
|
|
5033
|
+
* await page.goBack(); // Will navigate back to the first page
|
|
5034
|
+
* ```
|
|
5035
|
+
*
|
|
5036
|
+
* @param options Navigation options.
|
|
5037
|
+
* @returns A promise that resolves to the response of the requested navigation when it happens.
|
|
5038
|
+
* Returns null if there is no previous entry in the history.
|
|
5039
|
+
*/
|
|
5040
|
+
goBack(options?: NavigationOptions): Promise<Response | null>;
|
|
5041
|
+
|
|
5042
|
+
/**
|
|
5043
|
+
* Goes forward to the next page in the history.
|
|
5044
|
+
*
|
|
5045
|
+
* @example
|
|
5046
|
+
* ```js
|
|
5047
|
+
* await page.goBack(); // Navigate back first
|
|
5048
|
+
* await page.goForward(); // Then navigate forward
|
|
5049
|
+
* ```
|
|
5050
|
+
*
|
|
5051
|
+
* @param options Navigation options.
|
|
5052
|
+
* @returns A promise that resolves to the response of the requested navigation when it happens.
|
|
5053
|
+
* Returns null if there is no next entry in the history.
|
|
5054
|
+
*/
|
|
5055
|
+
goForward(options?: NavigationOptions): Promise<Response | null>;
|
|
5056
|
+
|
|
4970
5057
|
/**
|
|
4971
5058
|
* Adds a route to the page to modify network requests made by that page.
|
|
4972
5059
|
*
|
|
@@ -5693,6 +5780,120 @@ export interface Page {
|
|
|
5693
5780
|
},
|
|
5694
5781
|
): Promise<Request | null>;
|
|
5695
5782
|
|
|
5783
|
+
/**
|
|
5784
|
+
* Waits for the specified event to be emitted.
|
|
5785
|
+
*
|
|
5786
|
+
* This method blocks until the event is captured or the timeout is reached.
|
|
5787
|
+
* Supported event types are `console`, `request`, or `response`.
|
|
5788
|
+
*
|
|
5789
|
+
* @example
|
|
5790
|
+
* ```js
|
|
5791
|
+
* // Wait for a console message containing 'hello'
|
|
5792
|
+
* const msgPromise = page.waitForEvent('console', msg => msg.text().includes('hello'));
|
|
5793
|
+
* await page.evaluate(() => console.log('hello world'));
|
|
5794
|
+
* const msg = await msgPromise;
|
|
5795
|
+
* ```
|
|
5796
|
+
*
|
|
5797
|
+
* @param event Event name to wait for: `'console'`.
|
|
5798
|
+
* @param optionsOrPredicate Either a predicate function or an options object.
|
|
5799
|
+
*/
|
|
5800
|
+
waitForEvent(
|
|
5801
|
+
event: "console",
|
|
5802
|
+
optionsOrPredicate?:
|
|
5803
|
+
| ((msg: ConsoleMessage) => boolean)
|
|
5804
|
+
| {
|
|
5805
|
+
/**
|
|
5806
|
+
* Predicate function that returns `true` when the expected event is received.
|
|
5807
|
+
*/
|
|
5808
|
+
predicate?: (msg: ConsoleMessage) => boolean;
|
|
5809
|
+
/**
|
|
5810
|
+
* Maximum time to wait in milliseconds. Defaults to `30` seconds.
|
|
5811
|
+
* The default value can be changed via the
|
|
5812
|
+
* browserContext.setDefaultTimeout(timeout) or
|
|
5813
|
+
* page.setDefaultTimeout(timeout) methods.
|
|
5814
|
+
*
|
|
5815
|
+
* Setting the value to `0` will disable the timeout.
|
|
5816
|
+
*/
|
|
5817
|
+
timeout?: number;
|
|
5818
|
+
},
|
|
5819
|
+
): Promise<ConsoleMessage>;
|
|
5820
|
+
|
|
5821
|
+
/**
|
|
5822
|
+
* Waits for the specified event to be emitted.
|
|
5823
|
+
*
|
|
5824
|
+
* This method blocks until the event is captured or the timeout is reached.
|
|
5825
|
+
* It can wait for any page event such as `console`, `request`, or `response`.
|
|
5826
|
+
*
|
|
5827
|
+
* @example
|
|
5828
|
+
* ```js
|
|
5829
|
+
* // Wait for a request to a specific URL
|
|
5830
|
+
* const reqPromise = page.waitForEvent('request', req => req.url().includes('/api'));
|
|
5831
|
+
* await page.click('button');
|
|
5832
|
+
* const req = await reqPromise;
|
|
5833
|
+
* ```
|
|
5834
|
+
*
|
|
5835
|
+
* @param event Event name to wait for: `'request'`.
|
|
5836
|
+
* @param optionsOrPredicate Either a predicate function or an options object.
|
|
5837
|
+
*/
|
|
5838
|
+
waitForEvent(
|
|
5839
|
+
event: "request",
|
|
5840
|
+
optionsOrPredicate?:
|
|
5841
|
+
| ((req: Request) => boolean)
|
|
5842
|
+
| {
|
|
5843
|
+
/**
|
|
5844
|
+
* Predicate function that returns `true` when the expected event is received.
|
|
5845
|
+
*/
|
|
5846
|
+
predicate?: (req: Request) => boolean;
|
|
5847
|
+
/**
|
|
5848
|
+
* Maximum time to wait in milliseconds. Defaults to `30` seconds.
|
|
5849
|
+
* The default value can be changed via the
|
|
5850
|
+
* browserContext.setDefaultTimeout(timeout) or
|
|
5851
|
+
* page.setDefaultTimeout(timeout) methods.
|
|
5852
|
+
*
|
|
5853
|
+
* Setting the value to `0` will disable the timeout.
|
|
5854
|
+
*/
|
|
5855
|
+
timeout?: number;
|
|
5856
|
+
},
|
|
5857
|
+
): Promise<Request>;
|
|
5858
|
+
|
|
5859
|
+
/**
|
|
5860
|
+
* Waits for the specified event to be emitted.
|
|
5861
|
+
*
|
|
5862
|
+
* This method blocks until the event is captured or the timeout is reached.
|
|
5863
|
+
* It can wait for any page event such as `console`, `request`, or `response`.
|
|
5864
|
+
*
|
|
5865
|
+
* @example
|
|
5866
|
+
* ```js
|
|
5867
|
+
* // Wait for a response from a specific URL
|
|
5868
|
+
* const resPromise = page.waitForEvent('response', res => res.url().includes('/api'));
|
|
5869
|
+
* await page.click('button');
|
|
5870
|
+
* const res = await resPromise;
|
|
5871
|
+
* ```
|
|
5872
|
+
*
|
|
5873
|
+
* @param event Event name to wait for: `'response'`.
|
|
5874
|
+
* @param optionsOrPredicate Either a predicate function or an options object.
|
|
5875
|
+
*/
|
|
5876
|
+
waitForEvent(
|
|
5877
|
+
event: "response",
|
|
5878
|
+
optionsOrPredicate?:
|
|
5879
|
+
| ((res: Response) => boolean)
|
|
5880
|
+
| {
|
|
5881
|
+
/**
|
|
5882
|
+
* Predicate function that returns `true` when the expected event is received.
|
|
5883
|
+
*/
|
|
5884
|
+
predicate?: (res: Response) => boolean;
|
|
5885
|
+
/**
|
|
5886
|
+
* Maximum time to wait in milliseconds. Defaults to `30` seconds.
|
|
5887
|
+
* The default value can be changed via the
|
|
5888
|
+
* browserContext.setDefaultTimeout(timeout) or
|
|
5889
|
+
* page.setDefaultTimeout(timeout) methods.
|
|
5890
|
+
*
|
|
5891
|
+
* Setting the value to `0` will disable the timeout.
|
|
5892
|
+
*/
|
|
5893
|
+
timeout?: number;
|
|
5894
|
+
},
|
|
5895
|
+
): Promise<Response>;
|
|
5896
|
+
|
|
5696
5897
|
/**
|
|
5697
5898
|
* **NOTE** Use web assertions that assert visibility or a locator-based
|
|
5698
5899
|
* locator.waitFor([options]) instead.
|
|
@@ -5866,6 +6067,25 @@ export interface Request {
|
|
|
5866
6067
|
* @returns request URL
|
|
5867
6068
|
*/
|
|
5868
6069
|
url(): string;
|
|
6070
|
+
|
|
6071
|
+
/**
|
|
6072
|
+
* Returns the failure info for a failed request, or null if the request succeeded.
|
|
6073
|
+
* This method returns information about network failures such as DNS errors,
|
|
6074
|
+
* connection refused, timeouts, etc. It does not return information for HTTP
|
|
6075
|
+
* 4xx/5xx responses, which are successful network requests.
|
|
6076
|
+
* @returns The failure information or null if the request succeeded.
|
|
6077
|
+
*/
|
|
6078
|
+
failure(): RequestFailure | null;
|
|
6079
|
+
}
|
|
6080
|
+
|
|
6081
|
+
/**
|
|
6082
|
+
* RequestFailure contains information about a failed request.
|
|
6083
|
+
*/
|
|
6084
|
+
export interface RequestFailure {
|
|
6085
|
+
/**
|
|
6086
|
+
* The error text describing why the request failed.
|
|
6087
|
+
*/
|
|
6088
|
+
errorText: string;
|
|
5869
6089
|
}
|
|
5870
6090
|
|
|
5871
6091
|
/**
|
k6/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@types/k6",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "TypeScript definitions for k6",
|
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/k6",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"./experimental/fs": "./experimental/fs/index.d.ts",
|
|
64
64
|
"./experimental/redis": "./experimental/redis/index.d.ts",
|
|
65
65
|
"./experimental/streams": "./experimental/streams/index.d.ts",
|
|
66
|
-
"./
|
|
66
|
+
"./websockets": "./websockets/index.d.ts",
|
|
67
67
|
"./package.json": "./package.json"
|
|
68
68
|
},
|
|
69
69
|
"repository": {
|
|
@@ -74,6 +74,6 @@
|
|
|
74
74
|
"scripts": {},
|
|
75
75
|
"dependencies": {},
|
|
76
76
|
"peerDependencies": {},
|
|
77
|
-
"typesPublisherContentHash": "
|
|
77
|
+
"typesPublisherContentHash": "80b31eb39ecab6afca265e96b2a78fd11aa9904f1e43aca2188ce7631b0d7e2c",
|
|
78
78
|
"typeScriptVersion": "5.2"
|
|
79
79
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReadableStream } from "../experimental/streams/index.js";
|
|
2
|
+
import { CookieJar } from "../http/index.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* This module provides
|
|
6
|
-
* for k6.
|
|
5
|
+
* This module provides a WebSocket API for k6.
|
|
7
6
|
*
|
|
8
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
7
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -43,7 +42,7 @@ export class WebSocket {
|
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* The Websocket constructor returns a newly created WebSocket object.
|
|
46
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
45
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/
|
|
47
46
|
*
|
|
48
47
|
* @param url - The URL to which to connect; this should be the URL to which the WebSocket server will respond.
|
|
49
48
|
* @param protocols - Either a single protocol string or an array of protocol strings. The param is reserved for future use and will be presently ignored.
|
|
@@ -53,7 +52,7 @@ export class WebSocket {
|
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
54
|
* Enqueues data to be transmitted to the server over the WebSocket connection.
|
|
56
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
55
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-send/
|
|
57
56
|
*
|
|
58
57
|
* @param data - the data to send to the server
|
|
59
58
|
*/
|
|
@@ -62,7 +61,7 @@ export class WebSocket {
|
|
|
62
61
|
/**
|
|
63
62
|
* Bind event names to event handlers to be executed when their
|
|
64
63
|
* respective event is received by the server.
|
|
65
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
64
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-addeventlistener/
|
|
66
65
|
*
|
|
67
66
|
* @param event - the event to listen for
|
|
68
67
|
* @param listener - the callback to invoke when the event is emitted
|
|
@@ -71,7 +70,7 @@ export class WebSocket {
|
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
72
|
* Closes the WebSocket connection or connection attempt, if any.
|
|
74
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
73
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-close/
|
|
75
74
|
*
|
|
76
75
|
* @param code - An integer WebSocket connection close code value indicating a reason for closure.
|
|
77
76
|
* @param reason - A human-readable string WebSocket connection close reason. No longer than 123 bytes of UTF-8 text.
|
|
@@ -80,13 +79,13 @@ export class WebSocket {
|
|
|
80
79
|
|
|
81
80
|
/**
|
|
82
81
|
* Sends a ping message over the WebSocket connection.
|
|
83
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
82
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-ping/
|
|
84
83
|
*/
|
|
85
84
|
ping(): void;
|
|
86
85
|
|
|
87
86
|
/**
|
|
88
87
|
* Sets an event handler which is invoked when a message event happens.
|
|
89
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
88
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-onmessage/
|
|
90
89
|
*
|
|
91
90
|
* @param event - the message event
|
|
92
91
|
*/
|
|
@@ -94,19 +93,19 @@ export class WebSocket {
|
|
|
94
93
|
|
|
95
94
|
/**
|
|
96
95
|
* Sets an event handler which is invoked when the WebSocket connection's opens.
|
|
97
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
96
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-onopen/
|
|
98
97
|
*/
|
|
99
98
|
onopen: () => void;
|
|
100
99
|
|
|
101
100
|
/**
|
|
102
101
|
* Sets an event handler which is invoked when the WebSocket connection's closes.
|
|
103
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
102
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-onclose/
|
|
104
103
|
*/
|
|
105
104
|
onclose: () => void;
|
|
106
105
|
|
|
107
106
|
/**
|
|
108
107
|
* Sets an event handler which is invoked when errors occur.
|
|
109
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
108
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-onerror/
|
|
110
109
|
*
|
|
111
110
|
* @param event - the error event
|
|
112
111
|
*/
|
|
@@ -114,13 +113,13 @@ export class WebSocket {
|
|
|
114
113
|
|
|
115
114
|
/**
|
|
116
115
|
* Sets an event handler which is invoked when a ping message is received.
|
|
117
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
116
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-onping/
|
|
118
117
|
*/
|
|
119
118
|
onping: () => void;
|
|
120
119
|
|
|
121
120
|
/**
|
|
122
121
|
* Sets an event handler which is invoked when a pong message is received.
|
|
123
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
122
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/websocket/websocket-onpong/
|
|
124
123
|
*/
|
|
125
124
|
onpong: () => void;
|
|
126
125
|
}
|
|
@@ -147,7 +146,7 @@ export class Blob {
|
|
|
147
146
|
|
|
148
147
|
/**
|
|
149
148
|
* k6 specific WebSocket parameters.
|
|
150
|
-
* https://grafana.com/docs/k6/latest/javascript-api/k6-
|
|
149
|
+
* https://grafana.com/docs/k6/latest/javascript-api/k6-websockets/params/
|
|
151
150
|
*/
|
|
152
151
|
export interface Params {
|
|
153
152
|
/** Request headers. */
|