Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions types/k6/browser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,139 @@ export interface ElementStateFilter {
state?: ElementState;
}

/**
* The `devices` named export defines emulation settings for many end-user
* devices that can be used to simulate browser behavior on a mobile device.
*
* @example
* ```js
* import { browser, devices } from 'k6/browser';
* ... // redacted
* const iphoneX = devices['iPhone X'];
* const context = await browser.newContext(iphoneX);
* ... // redacted
* ```
*/
export const devices: Record<
| "Blackberry PlayBook"
| "Blackberry PlayBook landscape"
| "BlackBerry Z30"
| "BlackBerry Z30 landscape"
| "Galaxy Note 3"
| "Galaxy Note 3 landscape"
| "Galaxy Note II"
| "Galaxy Note II landscape"
| "Galaxy S III"
| "Galaxy S III landscape"
| "Galaxy S5"
| "Galaxy S5 landscape"
| "iPad"
| "iPad landscape"
| "iPad Mini"
| "iPad Mini landscape"
| "iPad Pro"
| "iPad Pro landscape"
| "iPhone 4"
| "iPhone 4 landscape"
| "iPhone 5"
| "iPhone 5 landscape"
| "iPhone 6"
| "iPhone 6 landscape"
| "iPhone 6 Plus"
| "iPhone 6 Plus landscape"
| "iPhone 7"
| "iPhone 7 landscape"
| "iPhone 7 Plus"
| "iPhone 7 Plus landscape"
| "iPhone 8"
| "iPhone 8 landscape"
| "iPhone 8 Plus"
| "iPhone 8 Plus landscape"
| "iPhone SE"
| "iPhone SE landscape"
| "iPhone X"
| "iPhone X landscape"
| "iPhone XR"
| "iPhone XR landscape"
| "JioPhone 2"
| "JioPhone 2 landscape"
| "Kindle Fire HDX"
| "Kindle Fire HDX landscape"
| "LG Optimus L70"
| "LG Optimus L70 landscape"
| "Microsoft Lumia 550"
| "Microsoft Lumia 950"
| "Microsoft Lumia 950 landscape"
| "Nexus 10"
| "Nexus 10 landscape"
| "Nexus 4"
| "Nexus 4 landscape"
| "Nexus 5"
| "Nexus 5 landscape"
| "Nexus 5X"
| "Nexus 5X landscape"
| "Nexus 6"
| "Nexus 6 landscape"
| "Nexus 6P"
| "Nexus 6P landscape"
| "Nexus 7"
| "Nexus 7 landscape"
| "Nokia Lumia 520"
| "Nokia Lumia 520 landscape"
| "Nokia N9"
| "Nokia N9 landscape"
| "Pixel 2"
| "Pixel 2 landscape"
| "Pixel 2 XL"
| "Pixel 2 XL landscape",
Device
>;

/**
* Device represents an end-user device (computer, tablet, phone etc.).
*/
export interface Device {
/**
* Name of the device.
*/
name: string;

/**
* User agent of the device.
*/
userAgent: string;

/**
* Viewport size of the device.
*/
viewport: {
/**
* page width in pixels.
*/
width: number;

/**
* page height in pixels.
*/
height: number;
};

/**
* Device viewport scale factor.
*/
deviceScaleFactor: number;

/**
* Indicates whether the device is a mobile device.
*/
isMobile: boolean;

/**
* Indicates whether the device support touch events.
*/
hasTouch: boolean;
}

/**
* BrowserPermissions defines all the possible permissions that can be granted
* to the browser application.
Expand Down
7 changes: 6 additions & 1 deletion types/k6/test/browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser } from "k6/browser";
import { browser, devices } from "k6/browser";

const url = "http://example.com";
const selector = "a[href=\"http://example.com\"]";
Expand Down Expand Up @@ -63,6 +63,11 @@ async function test() {
// $ExpectType Promise<BrowserContext>
browser.newContext({ viewport: { width: 1280, height: 720 } });

// $ExpectType Device
const iphoneX = devices["iPhone X"];
// $ExpectType Promise<BrowserContext>
browser.newContext(iphoneX);

// $ExpectType Promise<Page>
browser.newPage();
// $ExpectType Promise<Page>
Expand Down
36 changes: 36 additions & 0 deletions types/react-dom/canary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,39 @@ import React = require("react");
import ReactDOM = require(".");

export {};

declare module "react" {
// @enableViewTransition
interface ViewTransitionPseudoElement extends Animatable {
getComputedStyle: () => CSSStyleDeclaration;
}

interface ViewTransitionInstance {
group: ViewTransitionPseudoElement;
imagePair: ViewTransitionPseudoElement;
old: ViewTransitionPseudoElement;
new: ViewTransitionPseudoElement;
}

// @enableFragmentRefs
interface FragmentInstance {
blur: () => void;
focus: (focusOptions?: FocusOptions | undefined) => void;
focusLast: (focusOptions?: FocusOptions | undefined) => void;
observeUsing(observer: IntersectionObserver | ResizeObserver): void;
unobserveUsing(observer: IntersectionObserver | ResizeObserver): void;
getClientRects(): Array<DOMRect>;
getRootNode(getRootNodeOptions?: GetRootNodeOptions | undefined): Document | ShadowRoot | FragmentInstance;
addEventListener(
type: string,
listener: EventListener,
optionsOrUseCapture?: Parameters<Element["addEventListener"]>[2],
): void;
removeEventListener(
type: string,
listener: EventListener,
optionsOrUseCapture?: Parameters<Element["removeEventListener"]>[2],
): void;
scrollIntoView(alignToTop?: boolean): void;
}
}
33 changes: 0 additions & 33 deletions types/react-dom/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,8 @@ declare module "." {
}

declare module "react" {
interface ViewTransitionPseudoElement extends Animatable {
getComputedStyle: () => CSSStyleDeclaration;
}

interface ViewTransitionInstance {
group: ViewTransitionPseudoElement;
imagePair: ViewTransitionPseudoElement;
old: ViewTransitionPseudoElement;
new: ViewTransitionPseudoElement;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface GestureProvider extends AnimationTimeline {}

// @enableFragmentRefs
interface FragmentInstance {
blur: () => void;
focus: (focusOptions?: FocusOptions | undefined) => void;
focusLast: (focusOptions?: FocusOptions | undefined) => void;
observeUsing(observer: IntersectionObserver | ResizeObserver): void;
unobserveUsing(observer: IntersectionObserver | ResizeObserver): void;
getClientRects(): Array<DOMRect>;
getRootNode(getRootNodeOptions?: GetRootNodeOptions | undefined): Document | ShadowRoot | FragmentInstance;
addEventListener(
type: string,
listener: EventListener,
optionsOrUseCapture?: Parameters<Element["addEventListener"]>[2],
): void;
removeEventListener(
type: string,
listener: EventListener,
optionsOrUseCapture?: Parameters<Element["removeEventListener"]>[2],
): void;
experimental_scrollIntoView(alignToTop?: boolean): void;
}
}

declare module "./client" {
Expand Down
95 changes: 95 additions & 0 deletions types/react-dom/test/canary-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,98 @@ import ReactDOM = require("react-dom");
import ReactDOMClient = require("react-dom/client");
import ReactDOMServer = require("react-dom/server");
import ReactDOMStatic = require("react-dom/static");

// @enableViewTransition
function viewTransitionTests() {
const ViewTransition = React.ViewTransition;

<ViewTransition
ref={current => {
if (current !== null) {
// $ExpectType string
current.name;

// $ExpectType ViewTransitionPseudoElement
current.group;
// $ExpectType ViewTransitionPseudoElement
current.imagePair;
// $ExpectType ViewTransitionPseudoElement
current.old;
// $ExpectType ViewTransitionPseudoElement
current.new;

// $ExpectType CSSStyleDeclaration
current.old.getComputedStyle();
// @ts-expect-error -- Implemented on the pseudo elements.
current.getComputedStyle();
}
}}
>
<div />
</ViewTransition>;
}

// @enableFragmentRefs
function fragmentRefTest() {
<React.Fragment
ref={maybeInstance => {
// $ExpectType FragmentInstance | null
maybeInstance;

// See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/69022/commits/57825689c7abb50a79395d1266226cfa1b31a4e1
const instance = maybeInstance!;

instance.focus();
instance.blur();
instance.focusLast();
instance.observeUsing(new IntersectionObserver(() => {}));
instance.unobserveUsing(new IntersectionObserver(() => {}));
instance.observeUsing(new ResizeObserver(() => {}));
instance.unobserveUsing(new ResizeObserver(() => {}));
instance.getClientRects();
instance.getRootNode();
instance.getRootNode({ composed: true });
instance.addEventListener("click", () => {});
instance.addEventListener("click", () => {}, true);
instance.addEventListener("click", () => {}, { capture: true });
instance.addEventListener("click", () => {}, true);
instance.removeEventListener("click", () => {});
instance.removeEventListener("click", () => {}, { capture: true });
instance.removeEventListener("click", () => {}, true);
instance.addEventListener("click", () => {}, { passive: true });
instance.addEventListener("click", () => {}, { once: true });
instance.addEventListener("click", () => {}, { signal: new AbortController().signal });
instance.addEventListener("click", () => {}, { signal: new AbortSignal() });
instance.addEventListener("click", () => {}, { signal: new AbortSignal(), once: true });
instance.addEventListener("click", () => {}, { signal: new AbortSignal(), passive: true });
instance.addEventListener("click", () => {}, { signal: new AbortSignal(), capture: true });
instance.addEventListener("click", () => {}, { signal: new AbortSignal(), capture: true, once: true });
instance.addEventListener("click", () => {}, { signal: new AbortSignal(), capture: true, passive: true });
instance.addEventListener("click", () => {}, { signal: new AbortSignal(), once: true, passive: true });
instance.addEventListener("click", () => {}, {
signal: new AbortSignal(),
capture: true,
once: true,
passive: true,
});
instance.removeEventListener("click", () => {}, { capture: true });
instance.removeEventListener("click", () => {}, true);
instance.removeEventListener("click", () => {}, {
// @ts-expect-error -- Not the same options as addEventListener
passive: true,
});
instance.scrollIntoView(false);
instance.scrollIntoView(true);
instance.scrollIntoView(undefined);

instance.scrollIntoView(
// @ts-expect-error -- options are not supported yet
{},
);
return () => {};
}}
>
<div />
<div />
</React.Fragment>;
}
Loading