Skip to content

Commit

Permalink
Merge pull request #45 from grafana/async/mouse-and-keyboard
Browse files Browse the repository at this point in the history
Update Mouse and Keyboard interface to return Promises
  • Loading branch information
allansson committed May 24, 2024
2 parents 9c5917f + e2b18eb commit 3c5382f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
20 changes: 10 additions & 10 deletions types/k6/experimental/browser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1840,22 +1840,22 @@ export interface Keyboard {
* A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
* @param key Name of key to press, such as `ArrowLeft`.
*/
down(key: string): void;
down(key: string): Promise<void>;

/**
* Dispatches an `input` event with the given `text`.
* This method does not emit `keyDown`, `keyUp` or `keyPress` events.
* @param text Event text.
*/
insertText(text: string): void;
insertText(text: string): Promise<void>;

/**
* Sends a key press message to a session target.
* A press message consists of successive key down and up messages.
* @param key Sequence of keys to press.
* @param options Specifies the typing options.
*/
press(key: string, options?: { delay?: number }): void;
press(key: string, options?: { delay?: number }): Promise<void>;

/**
* Type sends a `press` message to a session target for each character in text.
Expand All @@ -1865,14 +1865,14 @@ export interface Keyboard {
* @param text A text to type into a focused element.
* @param options Specifies the typing options.
*/
type(text: string, options?: { delay?: number }): void;
type(text: string, options?: { delay?: number }): Promise<void>;

/**
* Sends a key up message to a session target.
* A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
* @param key Name of key to release, such as `ArrowLeft`.
*/
up(key: string): void;
up(key: string): Promise<void>;
}

/**
Expand Down Expand Up @@ -2078,7 +2078,7 @@ export interface Mouse {
* @param y The y position.
* @param options The click options.
*/
click(x: number, y: number, options?: MouseMultiClickOptions): void;
click(x: number, y: number, options?: MouseMultiClickOptions): Promise<void>;

/**
* Shortcut for `mouse.move(x, y)`, `mouse.down()`, `mouse.up()`, `mouse.down()`,
Expand All @@ -2087,27 +2087,27 @@ export interface Mouse {
* @param y The y position.
* @param options The click options.
*/
dblclick(x: number, y: number, options?: MouseClickOptions): void;
dblclick(x: number, y: number, options?: MouseClickOptions): Promise<void>;

/**
* Dispatches a `mousedown` event.
* @param options The mouse down options.
*/
down(options?: MouseDownUpOptions): void;
down(options?: MouseDownUpOptions): Promise<void>;

/**
* Dispatches a `mousemove` event.
* @param x The x position.
* @param y The y position.
* @param options The mouse move options.
*/
move(x: number, y: number, options?: { steps?: number }): void;
move(x: number, y: number, options?: { steps?: number }): Promise<void>;

/**
* Dispatches a `mouseup` event.
* @param options The mouse up options.
*/
up(options?: MouseDownUpOptions): void;
up(options?: MouseDownUpOptions): Promise<void>;
}

/**
Expand Down
44 changes: 22 additions & 22 deletions types/k6/test/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,31 +837,31 @@ async function test() {

// @ts-expect-error
keyboard.down();
// $ExpectType void
// $ExpectType Promise<void>
keyboard.down("a");

// @ts-expect-error
keyboard.insertText();
// $ExpectType void
// $ExpectType Promise<void>
keyboard.insertText("a");

// @ts-expect-error
keyboard.press();
// $ExpectType void
// $ExpectType Promise<void>
keyboard.press("a");
// $ExpectType void
// $ExpectType Promise<void>
keyboard.press("a", { delay: 1000 });

// @ts-expect-error
keyboard.type();
// $ExpectType void
// $ExpectType Promise<void>
keyboard.type("a");
// $ExpectType void
// $ExpectType Promise<void>
keyboard.type("a", { delay: 1000 });

// @ts-expect-error
keyboard.up();
// $ExpectType void
// $ExpectType Promise<void>
keyboard.up("a");

//
Expand All @@ -874,47 +874,47 @@ async function test() {
mouse.click();
// @ts-expect-error
mouse.click(0);
// $ExpectType void
// $ExpectType Promise<void>
mouse.click(0, 0);
// $ExpectType void
// $ExpectType Promise<void>
mouse.click(0, 0, { button: "right" });
// $ExpectType void
// $ExpectType Promise<void>
mouse.click(0, 0, { clickCount: 2 });
// $ExpectType void
// $ExpectType Promise<void>
mouse.click(0, 0, { delay: 1000 });

// @ts-expect-error
mouse.dblclick();
// @ts-expect-error
mouse.dblclick(0);
// $ExpectType void
// $ExpectType Promise<void>
mouse.dblclick(0, 0);
// $ExpectType void
// $ExpectType Promise<void>
mouse.dblclick(0, 0, { button: "right" });
// $ExpectType void
// $ExpectType Promise<void>
mouse.dblclick(0, 0, { delay: 1000 });

// $ExpectType void
// $ExpectType Promise<void>
mouse.down();
// $ExpectType void
// $ExpectType Promise<void>
mouse.down({ button: "right" });
// $ExpectType void
// $ExpectType Promise<void>
mouse.down({ clickCount: 2 });

// @ts-expect-error
mouse.move();
// @ts-expect-error
mouse.move(0);
// $ExpectType void
// $ExpectType Promise<void>
mouse.move(0, 0);
// $ExpectType void
// $ExpectType Promise<void>
mouse.move(0, 0, { steps: 10 });

// $ExpectType void
// $ExpectType Promise<void>
mouse.up();
// $ExpectType void
// $ExpectType Promise<void>
mouse.up({ button: "right" });
// $ExpectType void
// $ExpectType Promise<void>
mouse.up({ clickCount: 2 });

//
Expand Down

0 comments on commit 3c5382f

Please sign in to comment.