@types/k6 0.47.2 → 0.48.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 CHANGED
@@ -2,14 +2,14 @@
2
2
  > `npm install --save @types/k6`
3
3
 
4
4
  # Summary
5
- This package contains type definitions for k6 (https://k6.io/docs/).
5
+ This package contains type definitions for k6 (https://grafana.com/docs/k6/latest/).
6
6
 
7
7
  # Details
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/k6.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Tue, 07 Nov 2023 03:09:37 GMT
11
+ * Last updated: Wed, 06 Dec 2023 11:07:02 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
15
- These definitions were written by [Mihail Stoykov](https://github.com/MStoykov), [Ivan](https://github.com/codebien), [Théo Crevon](https://github.com/oleiade), [Oleg Bespalov](https://github.com/olegbespalov), [Pepe Cano](https://github.com/ppcano), [Nicole van der Hoeven](https://github.com/nicolevanderhoeven), [Ankur Agarwal](https://github.com/ankur22), [İnanç Gümüş](https://github.com/inancgumus), and [Daniel Jiménez](https://github.com/ka3de).
15
+ These definitions were written by [Mihail Stoykov](https://github.com/MStoykov), [Ivan](https://github.com/codebien), [Théo Crevon](https://github.com/oleiade), [Oleg Bespalov](https://github.com/olegbespalov), [Pepe Cano](https://github.com/ppcano), [Nicole van der Hoeven](https://github.com/nicolevanderhoeven), [Ankur Agarwal](https://github.com/ankur22), [İnanç Gümüş](https://github.com/inancgumus), [Daniel Jiménez](https://github.com/ka3de), and [Joan López de la Franca Beltran](https://github.com/joanlopez).
k6/crypto.d.ts CHANGED
@@ -13,7 +13,7 @@ export function randomBytes(size: number): ArrayBuffer;
13
13
 
14
14
  /**
15
15
  * Produce HMAC.
16
- * https://k6.io/docs/javascript-api/k6-crypto/hmac-algorithm-secret-data-outputencoding/
16
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/hmac/
17
17
  * @param algorithm - Hash algorithm.
18
18
  * @param secret - Shared secret.
19
19
  * @param input - Input data.
@@ -31,7 +31,7 @@ export function hmac<OE extends OutputEncoding>(
31
31
 
32
32
  /**
33
33
  * Hash with MD4.
34
- * https://k6.io/docs/javascript-api/k6-crypto/md4-input-outputencoding/
34
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/md4/
35
35
  * @param input - Data to hash.
36
36
  * @param outputEncoding - Output encoding.
37
37
  * @returns MD4 digest.
@@ -42,7 +42,7 @@ export function md4<OE extends OutputEncoding>(input: string | ArrayBuffer, outp
42
42
 
43
43
  /**
44
44
  * Hash with MD5.
45
- * https://k6.io/docs/javascript-api/k6-crypto/md5-input-outputencoding/
45
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/md5/
46
46
  * @param input - Data to hash.
47
47
  * @param outputEncoding - Output encoding.
48
48
  * @returns MD5 digest.
@@ -53,7 +53,7 @@ export function md5<OE extends OutputEncoding>(input: string | ArrayBuffer, outp
53
53
 
54
54
  /**
55
55
  * Hash with SHA-1.
56
- * https://k6.io/docs/javascript-api/k6-crypto/sha1-input-outputencoding/
56
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha1/
57
57
  * @param input - Data to hash.
58
58
  * @param outputEncoding - Output encoding.
59
59
  * @returns SHA-1 digest.
@@ -64,7 +64,7 @@ export function sha1<OE extends OutputEncoding>(input: string | ArrayBuffer, out
64
64
 
65
65
  /**
66
66
  * Hash with SHA-256.
67
- * https://k6.io/docs/javascript-api/k6-crypto/sha256-input-outputencoding/
67
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha256/
68
68
  * @param input - Data to hash.
69
69
  * @param outputEncoding - Output encoding.
70
70
  * @returns SHA-256 digest.
@@ -75,7 +75,7 @@ export function sha256<OE extends OutputEncoding>(input: string | ArrayBuffer, o
75
75
 
76
76
  /**
77
77
  * Hash with SHA-384.
78
- * https://k6.io/docs/javascript-api/k6-crypto/sha384-input-outputencoding/
78
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha384/
79
79
  * @param input - Data to hash.
80
80
  * @param outputEncoding - Output encoding.
81
81
  * @returns SHA-384 digest.
@@ -86,7 +86,7 @@ export function sha384<OE extends OutputEncoding>(input: string | ArrayBuffer, o
86
86
 
87
87
  /**
88
88
  * Hash with SHA-512.
89
- * https://k6.io/docs/javascript-api/k6-crypto/sha512-input-outputencoding/
89
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha512/
90
90
  * @param input - Data to hash.
91
91
  * @param outputEncoding - Output encoding.
92
92
  * @returns SHA-512 digest.
@@ -97,7 +97,7 @@ export function sha512<OE extends OutputEncoding>(input: string | ArrayBuffer, o
97
97
 
98
98
  /**
99
99
  * Hash with SHA-512/224.
100
- * https://k6.io/docs/javascript-api/k6-crypto/sha512_224-input-outputencoding/
100
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha512_224/
101
101
  * @param input - Data to hash.
102
102
  * @param outputEncoding - Output encoding.
103
103
  * @returns SHA-512/224 digest.
@@ -108,7 +108,7 @@ export function sha512_224<OE extends OutputEncoding>(input: string | ArrayBuffe
108
108
 
109
109
  /**
110
110
  * Hash with SHA-512/256.
111
- * https://k6.io/docs/javascript-api/k6-crypto/sha512_256-input-outputencoding/
111
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha512_256/
112
112
  * @param input - Data to hash.
113
113
  * @param outputEncoding - Output encoding.
114
114
  * @returns SHA-512/256 digest.
@@ -119,7 +119,7 @@ export function sha512_256<OE extends OutputEncoding>(input: string | ArrayBuffe
119
119
 
120
120
  /**
121
121
  * Hash with RIPEMD-160.
122
- * https://k6.io/docs/javascript-api/k6-crypto/ripemd160-input-outputencoding/
122
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/ripemd160/
123
123
  * @param input - Data to hash.
124
124
  * @param outputEncoding - Output encoding.
125
125
  * @returns RIPEMD-160 digest.
@@ -130,7 +130,7 @@ export function ripemd160<OE extends OutputEncoding>(input: string | ArrayBuffer
130
130
 
131
131
  /**
132
132
  * Create a hashing object.
133
- * https://k6.io/docs/javascript-api/k6-crypto/createhash-algorithm/
133
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/createhash/
134
134
  * @param algorithm - Hash algorithm.
135
135
  * @returns Hashing object.
136
136
  * @example
@@ -139,7 +139,7 @@ export function createHash(algorithm: Algorithm): Hasher;
139
139
 
140
140
  /**
141
141
  * Create an HMAC hashing object.
142
- * https://k6.io/docs/javascript-api/k6-crypto/createhmac-algorithm-secret/
142
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/createhmac/
143
143
  * @param algorithm - Hash algorithm.
144
144
  * @param secret - Shared secret.
145
145
  * @returns HMAC hashing object.
@@ -186,14 +186,14 @@ export type Output<OE extends OutputEncoding> = OE extends StringEncoding ? stri
186
186
 
187
187
  /**
188
188
  * Hashing object.
189
- * https://k6.io/docs/javascript-api/k6-crypto/hasher/
189
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/hasher/
190
190
  */
191
191
  export abstract class Hasher {
192
192
  protected __brand: never;
193
193
 
194
194
  /**
195
195
  * Add more data to the string we want to create a hash of.
196
- * https://k6.io/docs/javascript-api/k6-crypto/hasher/
196
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/hasher/
197
197
  * @param input - Data to add.
198
198
  * @example
199
199
  * let hasher = crypto.createHMAC('sha256', 'a secret');
@@ -205,7 +205,7 @@ export abstract class Hasher {
205
205
 
206
206
  /**
207
207
  * Return a digest from the data added so far.
208
- * https://k6.io/docs/javascript-api/k6-crypto/hasher/
208
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/hasher/
209
209
  * @param outputEncoding - Output encoding.
210
210
  * @returns Digest of data added so far.
211
211
  * @example
@@ -219,7 +219,7 @@ export abstract class Hasher {
219
219
 
220
220
  /**
221
221
  * This module provides common hashing functionality available in the GoLang crypto package.
222
- * https://k6.io/docs/javascript-api/k6-crypto/
222
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/
223
223
  */
224
224
  declare namespace crypto {
225
225
  /**
@@ -235,7 +235,7 @@ declare namespace crypto {
235
235
 
236
236
  /**
237
237
  * Produce HMAC.
238
- * https://k6.io/docs/javascript-api/k6-crypto/hmac-algorithm-secret-data-outputencoding/
238
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/hmac/
239
239
  * @param algorithm - Hash algorithm.
240
240
  * @param secret - Shared secret.
241
241
  * @param input - Input data.
@@ -253,7 +253,7 @@ declare namespace crypto {
253
253
 
254
254
  /**
255
255
  * Hash with MD4.
256
- * https://k6.io/docs/javascript-api/k6-crypto/md4-input-outputencoding/
256
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/md4/
257
257
  * @param input - Data to hash.
258
258
  * @param outputEncoding - Output encoding.
259
259
  * @returns MD4 digest.
@@ -264,7 +264,7 @@ declare namespace crypto {
264
264
 
265
265
  /**
266
266
  * Hash with MD5.
267
- * https://k6.io/docs/javascript-api/k6-crypto/md5-input-outputencoding/
267
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/md5/
268
268
  * @param input - Data to hash.
269
269
  * @param outputEncoding - Output encoding.
270
270
  * @returns MD5 digest.
@@ -275,7 +275,7 @@ declare namespace crypto {
275
275
 
276
276
  /**
277
277
  * Hash with SHA-1.
278
- * https://k6.io/docs/javascript-api/k6-crypto/sha1-input-outputencoding/
278
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha1/
279
279
  * @param input - Data to hash.
280
280
  * @param outputEncoding - Output encoding.
281
281
  * @returns SHA-1 digest.
@@ -286,7 +286,7 @@ declare namespace crypto {
286
286
 
287
287
  /**
288
288
  * Hash with SHA-256.
289
- * https://k6.io/docs/javascript-api/k6-crypto/sha256-input-outputencoding/
289
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha256/
290
290
  * @param input - Data to hash.
291
291
  * @param outputEncoding - Output encoding.
292
292
  * @returns SHA-256 digest.
@@ -297,7 +297,7 @@ declare namespace crypto {
297
297
 
298
298
  /**
299
299
  * Hash with SHA-384.
300
- * https://k6.io/docs/javascript-api/k6-crypto/sha384-input-outputencoding/
300
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha384/
301
301
  * @param input - Data to hash.
302
302
  * @param outputEncoding - Output encoding.
303
303
  * @returns SHA-384 digest.
@@ -308,7 +308,7 @@ declare namespace crypto {
308
308
 
309
309
  /**
310
310
  * Hash with SHA-512.
311
- * https://k6.io/docs/javascript-api/k6-crypto/sha512-input-outputencoding/
311
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha512/
312
312
  * @param input - Data to hash.
313
313
  * @param outputEncoding - Output encoding.
314
314
  * @returns SHA-512 digest.
@@ -319,7 +319,7 @@ declare namespace crypto {
319
319
 
320
320
  /**
321
321
  * Hash with SHA-512/224.
322
- * https://k6.io/docs/javascript-api/k6-crypto/sha512_224-input-outputencoding/
322
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha512_224/
323
323
  * @param input - Data to hash.
324
324
  * @param outputEncoding - Output encoding.
325
325
  * @returns SHA-512/224 digest.
@@ -330,7 +330,7 @@ declare namespace crypto {
330
330
 
331
331
  /**
332
332
  * Hash with SHA-512/256.
333
- * https://k6.io/docs/javascript-api/k6-crypto/sha512_256-input-outputencoding/
333
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/sha512_256/
334
334
  * @param input - Data to hash.
335
335
  * @param outputEncoding - Output encoding.
336
336
  * @returns SHA-512/256 digest.
@@ -341,7 +341,7 @@ declare namespace crypto {
341
341
 
342
342
  /**
343
343
  * Hash with RIPEMD-160.
344
- * https://k6.io/docs/javascript-api/k6-crypto/ripemd160-input-outputencoding/
344
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/ripemd160/
345
345
  * @param input - Data to hash.
346
346
  * @param outputEncoding - Output encoding.
347
347
  * @returns RIPEMD-160 digest.
@@ -352,7 +352,7 @@ declare namespace crypto {
352
352
 
353
353
  /**
354
354
  * Create a hashing object.
355
- * https://k6.io/docs/javascript-api/k6-crypto/createhash-algorithm/
355
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/createhash/
356
356
  * @param algorithm - Hash algorithm.
357
357
  * @returns Hashing object.
358
358
  * @example
@@ -365,7 +365,7 @@ declare namespace crypto {
365
365
 
366
366
  /**
367
367
  * Create an HMAC hashing object.
368
- * https://k6.io/docs/javascript-api/k6-crypto/createhmac-algorithm-secret/
368
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-crypto/createhmac/
369
369
  * @param algorithm - Hash algorithm.
370
370
  * @param secret - Shared secret.
371
371
  * @returns HMAC hashing object.
k6/data.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * Given a name and a function that returns an array, the SharedArray constructor returns the same array but sharing the array memory between VUs.
3
- * https://k6.io/docs/javascript-api/k6-data/sharedarray/
3
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-data/sharedarray/
4
4
  */
5
5
  export const SharedArray: {
6
6
  /**
7
7
  * Given a name and a function that returns an array, the SharedArray constructor returns the same array but sharing the array memory between VUs.
8
- * https://k6.io/docs/javascript-api/k6-data/sharedarray/
8
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-data/sharedarray/
9
9
  */
10
10
  new(name: string, callback: () => []): [];
11
11
  /**
12
12
  * Given a name and a function that returns an array, the SharedArray constructor returns the same array but sharing the array memory between VUs.
13
- * https://k6.io/docs/javascript-api/k6-data/sharedarray/
13
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-data/sharedarray/
14
14
  */
15
15
  new<T>(name: string, callback: () => T[]): T[];
16
16
  };
k6/encoding.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Base64 decode a string.
3
- * https://k6.io/docs/javascript-api/k6-encoding/b64decode-input-encoding-format/
3
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-encoding/b64decode/
4
4
  * @param input - The string to base64 decode.
5
5
  * @param encoding - Base64 variant.
6
6
  * @returns The base64 decoded version of the input string in either string or ArrayBuffer format, depending on the `format` parameter.
@@ -14,7 +14,7 @@ export function b64decode(input: string, encoding?: Base64Variant): ArrayBuffer;
14
14
 
15
15
  /**
16
16
  * Base64 decode a string.
17
- * https://k6.io/docs/javascript-api/k6-encoding/b64decode-input-encoding-format/
17
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-encoding/b64decode/
18
18
  * @param input - The string to base64 decode.
19
19
  * @param encoding - Base64 variant.
20
20
  * @param format - If 's' return the data as a string, otherwise an ArrayBuffer object .
@@ -28,7 +28,7 @@ export function b64decode(input: string, encoding: Base64Variant, format: "s"):
28
28
 
29
29
  /**
30
30
  * Base64 encode a string.
31
- * https://k6.io/docs/javascript-api/k6-encoding/b64encode-input-encoding/
31
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-encoding/b64encode/
32
32
  * @param input - String to encode or ArrayBuffer object.
33
33
  * @param encoding - Base64 variant.
34
34
  * @returns Base64 encoded string.
@@ -45,12 +45,12 @@ export type Base64Variant = "std" | "rawstd" | "url" | "rawurl";
45
45
 
46
46
  /**
47
47
  * The encoding module provides base64 encoding/decoding.
48
- * https://k6.io/docs/javascript-api/k6-encoding/
48
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-encoding/
49
49
  */
50
50
  declare namespace encoding {
51
51
  /**
52
52
  * Base64 decode a string.
53
- * https://k6.io/docs/javascript-api/k6-encoding/b64decode-input-encoding-format/
53
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-encoding/b64decode/
54
54
  * @param input - The string to base64 decode.
55
55
  * @param encoding - Base64 variant.
56
56
  * @returns The base64 decoded version of the input string in either string or ArrayBuffer format, depending on the `format` parameter.
@@ -63,7 +63,7 @@ declare namespace encoding {
63
63
  function b64decode(input: string, encoding?: Base64Variant): ArrayBuffer;
64
64
  /**
65
65
  * Base64 decode a string.
66
- * https://k6.io/docs/javascript-api/k6-encoding/b64decode-input-encoding-format/
66
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-encoding/b64decode/
67
67
  * @param input - The string to base64 decode.
68
68
  * @param encoding - Base64 variant.
69
69
  * @param format - If 's' return the data as a string, otherwise an ArrayBuffer object .
@@ -76,7 +76,7 @@ declare namespace encoding {
76
76
  function b64decode(input: string, encoding: Base64Variant, format: "s"): string;
77
77
  /**
78
78
  * Base64 decode a string.
79
- * https://k6.io/docs/javascript-api/k6-encoding/b64decode-input-encoding/
79
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-encoding/b64decode/
80
80
  * @param input - Base64 encoded string or ArrayBuffer object.
81
81
  * @param encoding - Base64 variant.
82
82
  * @returns Decoded string.
k6/execution.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Options } from "./options";
2
2
 
3
3
  /*
4
4
  * The execution module provides information about the current test execution state.
5
- * https://k6.io/docs/javascript-api/k6-execution/
5
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-execution/
6
6
  */
7
7
  declare namespace execution {
8
8
  /**
@@ -67,7 +67,7 @@ declare namespace execution {
67
67
  const test: {
68
68
  /**
69
69
  * Aborts the test run with the exit code 108.
70
- * https://k6.io/docs/javascript-api/k6-execution/#test
70
+ * https://grafana.com/docs/k6/latest/javascript-api/k6-execution/#test
71
71
  * @param input - Aborted message.
72
72
  * @example
73
73
  * import exec from "k6/execution";
@@ -20,6 +20,40 @@ export type Unboxed<Arg> = Arg extends [infer A0, infer A1] ? [Unboxed<A0>, Unbo
20
20
  : Arg extends object ? { [Key in keyof Arg]: Unboxed<Arg[Key]> }
21
21
  : Arg;
22
22
 
23
+ /*
24
+ * CPUProfile is the mandatory input to be passed into {@link Page}'s
25
+ * `throttleCPU` method.
26
+ */
27
+ export interface CPUProfile {
28
+ /*
29
+ * rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
30
+ */
31
+ rate: number;
32
+ }
33
+
34
+ /*
35
+ * NetworkProfile is the mandatory input to be passed into {@link Page}'s
36
+ * `throttleNetwork` method.
37
+ */
38
+ export interface NetworkProfile {
39
+ /*
40
+ * Minimum latency from request sent to response headers received (ms).
41
+ */
42
+ latency: number;
43
+
44
+ /*
45
+ * Maximal aggregated download throughput (bytes/sec). -1 disables download
46
+ * throttling.
47
+ */
48
+ download: number;
49
+
50
+ /*
51
+ * Maximal aggregated upload throughput (bytes/sec). -1 disables upload
52
+ * throttling.
53
+ */
54
+ upload: number;
55
+ }
56
+
23
57
  export interface SelectOptionsObject {
24
58
  /**
25
59
  * Matches by `option.value`.
@@ -545,6 +579,12 @@ export const browser: Browser;
545
579
  * `Browser` represents the main web browser instance.
546
580
  */
547
581
  export interface Browser {
582
+ /**
583
+ * Closes the current `BrowserContext`. If there is no active
584
+ * `BrowserContext`, this method will throw an error.
585
+ */
586
+ closeContext(): void;
587
+
548
588
  /**
549
589
  * Returns the current `BrowserContext`. There is a 1-to-1 mapping between
550
590
  * `Browser` and `BrowserContext`. If no `BrowserContext` has been
@@ -650,7 +690,10 @@ export interface BrowserContext {
650
690
  cookies(...urls: string[]): Cookie[];
651
691
 
652
692
  /**
653
- * Clears all permission overrides for the `BrowserContext`.
693
+ * Clears all permission overrides for the {@link BrowserContext}.
694
+ * ```js
695
+ * context.clearPermissions();
696
+ * ```
654
697
  */
655
698
  clearPermissions(): void;
656
699
 
@@ -660,7 +703,10 @@ export interface BrowserContext {
660
703
  close(): void;
661
704
 
662
705
  /**
663
- * Grants specified permissions to the `BrowserContext`.
706
+ * Grants specified permissions to the {@link BrowserContext}.
707
+ * ```js
708
+ * context.grantPermissions(['geolocation']);
709
+ * ```
664
710
  */
665
711
  grantPermissions(
666
712
  /**
@@ -741,40 +787,55 @@ export interface BrowserContext {
741
787
 
742
788
  /**
743
789
  * Waits for the event to fire and passes its value into the predicate
744
- * function.
790
+ * function. Currently the only supported event is 'page' which when used will
791
+ * return the new {@link Page} that was created after `waitForEvent` was called.
792
+ *
793
+ * @example
794
+ * ```js
795
+ * // Call waitForEvent with a predicate which will return true once at least
796
+ * // one page has been created.
797
+ * const promise = context.waitForEvent("page", { predicate: page => {
798
+ * if (++counter >= 1) {
799
+ * return true
800
+ * }
801
+ * return false
802
+ * } })
803
+ *
804
+ * // Now we create a page.
805
+ * const page = context.newPage()
806
+ *
807
+ * // Wait for the predicate to pass.
808
+ * await promise
809
+ * ```
745
810
  */
746
811
  waitForEvent(
747
812
  /**
748
- * Name of event to wait for.
749
- *
750
- * NOTE: Currently this argument is disregarded, and waitForEvent will
751
- * always wait for 'close' or 'page' events.
813
+ * Name of event to wait for. The only supported event is 'page'. If any
814
+ * other value is used an error will be thrown.
752
815
  */
753
- event: string,
816
+ event: "page",
754
817
  /**
755
- * The `Page` or null event data will be passed to it and it must
756
- * return true to continue.
818
+ * This is an optional argument. It can either be a predicate function or
819
+ * an options object.
757
820
  */
758
- optionsOrPredicate: {
821
+ optionsOrPredicate?: {
759
822
  /**
760
- * Function that will be called when the 'Page' event is emitted.
761
- * The event data will be passed to it and it must return true
823
+ * Optional function that will be called when the {@link Page} event is
824
+ * emitted. The event data will be passed to it and it must return true
762
825
  * to continue.
763
826
  *
764
- * If `Page` is passed to predicate, this signals that a new page
827
+ * If {@link Page} is passed to predicate, this signals that a new page
765
828
  * has been created.
766
- * If null is passed to predicate, this signals that the page is
767
- * closing.
768
829
  */
769
- predicate: (page: Page | null) => boolean;
830
+ predicate?: (page: Page) => boolean;
770
831
 
771
832
  /**
772
- * Maximum time to wait in milliseconds. Pass 0 to disable timeout.
773
- * Defaults to 30000 milliseconds.
833
+ * Maximum time to wait in milliseconds. Defaults to 30000 milliseconds or
834
+ * the timeout set by setDefaultTimeout on the {@link BrowserContext}.
774
835
  */
775
836
  timeout?: number;
776
- },
777
- ): Page | null;
837
+ } | ((page: Page) => boolean),
838
+ ): Promise<Page>;
778
839
  }
779
840
 
780
841
  /**
@@ -2992,6 +3053,55 @@ export interface Page {
2992
3053
  },
2993
3054
  ): string;
2994
3055
 
3056
+ /**
3057
+ * Throttles the CPU in Chrome/Chromium to slow it down by the specified
3058
+ * `rate` in {@link CPUProfile}. {@link CPUProfile} is a mandatory
3059
+ * input argument. The default `rate` is `1`.
3060
+ *
3061
+ * **Usage**
3062
+ *
3063
+ * ```js
3064
+ * page.throttleCPU({ rate: 4 });
3065
+ * ```
3066
+ */
3067
+ throttleCPU(profile: CPUProfile): void;
3068
+
3069
+ /**
3070
+ * Throttles the network in Chrome/Chromium to slow it down by the specified
3071
+ * fields in {@link NetworkProfile}. {@link NetworkProfile} is a mandatory
3072
+ * input argument.
3073
+ *
3074
+ * **Usage**
3075
+ *
3076
+ * ```js
3077
+ * page.throttleNetwork({
3078
+ * latency: 750,
3079
+ * download: 250,
3080
+ * upload: 250,
3081
+ * });
3082
+ * ```
3083
+ *
3084
+ * To work with the most commonly tested network profiles, import `networkProfiles`
3085
+ * from the browser module. There are three profiles available:
3086
+ * - `'No Throttling'` (default)
3087
+ * - `'Fast 3G'`
3088
+ * - `'Slow 3G'`
3089
+ *
3090
+ * **Usage**
3091
+ *
3092
+ * ```js
3093
+ * import { browser, networkProfiles } from 'k6/experimental/browser';
3094
+ * ... // redacted
3095
+ * const context = browser.newContext();
3096
+ * const page = context.newPage();
3097
+ *
3098
+ * try {
3099
+ * page.throttleNetwork(networkProfiles['Slow 3G']);
3100
+ * ... // redacted
3101
+ * ```
3102
+ */
3103
+ throttleNetwork(profile: NetworkProfile): void;
3104
+
2995
3105
  /**
2996
3106
  * Returns the page's title.
2997
3107
  */
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The k6 experimental filesystem module provides an API for handling file operations
3
+ * in your k6 tests. It allows you to read files within your test scripts.
4
+ */
5
+
6
+ /**
7
+ * Opens a file and returns a promise that resolves to an instance of the `File` class.
8
+ *
9
+ * Note: As the k6 init context doesn't support 'await', use the following pattern:
10
+ *
11
+ * Example:
12
+ * ```
13
+ * let fileHandle;
14
+ * (async function() {
15
+ * fileHandle = await open("example.txt");
16
+ * }());
17
+ * ```
18
+ *
19
+ * @param path - The file path as a string. Relative paths are resolved relative to the k6 script.
20
+ * @returns Promise<File> - A promise that resolves to a `File` instance.
21
+ */
22
+ export function open(path: string): Promise<File>;
23
+
24
+ /**
25
+ * Represents a file and provides methods to interact with file data.
26
+ * This class offers read-only access to file contents.
27
+ */
28
+ export class File {
29
+ /**
30
+ * The absolute path of the file.
31
+ *
32
+ * This is resolved relative to the k6 script.
33
+ */
34
+ path: string;
35
+
36
+ /**
37
+ * Reads the file into a specified buffer type and returns the number of bytes read.
38
+ * Resolves to `null` if there's nothing to read (EOF or empty file).
39
+ *
40
+ * Example:
41
+ * ```
42
+ * const buffer = new Uint8Array(100);
43
+ * const bytesRead = await file.read(buffer);
44
+ * console.log(`Read ${bytesRead} bytes`);
45
+ * ```
46
+ *
47
+ * @param p - A Uint8Array buffer to read the file into.
48
+ * @returns Promise<number> - Number of bytes read or `null`.
49
+ */
50
+ read(p: Uint8Array): Promise<number>;
51
+
52
+ /**
53
+ * Moves the file pointer to a new location, based on `offset` and `whence`.
54
+ * Resolves to the new position within the file (in bytes).
55
+ *
56
+ * When using `SeekMode.Start`, the offset must be greater than or equal to zero.
57
+ * When using `SeekMode.Current`, the offset can be positive or negative.
58
+ * When using `SeekMode.End`, the offset must be less than or equal to zero.
59
+ *
60
+ * Example:
61
+ * ```
62
+ * const newOffset = await file.seek(10, SeekMode.Start);
63
+ * console.log(`Pointer moved to position ${newOffset}`);
64
+ * ```
65
+ *
66
+ * @param offset - The offset to seek to.
67
+ * @param whence - The position from where offset is added (Start, Current, or End).
68
+ * @returns Promise<number> - The new position in the file.
69
+ */
70
+ seek(offset: number, whence: SeekMode): Promise<number>;
71
+
72
+ /**
73
+ * Retrieves information about the file.
74
+ * Resolves to a `FileInfo` object describing the file.
75
+ *
76
+ * Example:
77
+ * ```
78
+ * const fileInfo = await file.stat();
79
+ * console.log(`File size: ${fileInfo.size} bytes`);
80
+ * ```
81
+ *
82
+ * @returns Promise<FileInfo> - Information about the file.
83
+ */
84
+ stat(): Promise<FileInfo>;
85
+ }
86
+
87
+ /**
88
+ * Contains information about a file, including its name and size.
89
+ */
90
+ export interface FileInfo {
91
+ name: string; // The name of the file
92
+ size: number; // The size of the file in bytes
93
+ }
94
+
95
+ /**
96
+ * Enumeration for file seek modes.
97
+ */
98
+ export enum SeekMode {
99
+ Start = 0, // Seek from the start of the file
100
+ Current = 1, // Seek from the current file position.
101
+ End = 2, // Seek from the end of the file
102
+ }