@vitest/browser 2.0.0-beta.10 → 2.0.0-beta.12

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.
package/context.d.ts CHANGED
@@ -19,12 +19,9 @@ export interface FsOptions {
19
19
  flag?: string | number
20
20
  }
21
21
 
22
- export interface TypePayload { type: string }
23
- export interface PressPayload { press: string }
24
- export interface DownPayload { down: string }
25
- export interface UpPayload { up: string }
26
-
27
- export type SendKeysPayload = TypePayload | PressPayload | DownPayload | UpPayload
22
+ export interface CDPSession {
23
+ // methods are defined by the provider type augmentation
24
+ }
28
25
 
29
26
  export interface ScreenshotOptions {
30
27
  element?: Element
@@ -35,13 +32,20 @@ export interface ScreenshotOptions {
35
32
  }
36
33
 
37
34
  export interface BrowserCommands {
38
- readFile: (path: string, options?: BufferEncoding | FsOptions) => Promise<string>
39
- writeFile: (path: string, content: string, options?: BufferEncoding | FsOptions & { mode?: number | string }) => Promise<void>
35
+ readFile: (
36
+ path: string,
37
+ options?: BufferEncoding | FsOptions
38
+ ) => Promise<string>
39
+ writeFile: (
40
+ path: string,
41
+ content: string,
42
+ options?: BufferEncoding | (FsOptions & { mode?: number | string })
43
+ ) => Promise<void>
40
44
  removeFile: (path: string) => Promise<void>
41
- sendKeys: (payload: SendKeysPayload) => Promise<void>
42
45
  }
43
46
 
44
47
  export interface UserEvent {
48
+ setup: () => UserEvent
45
49
  /**
46
50
  * Click on an element. Uses provider's API under the hood and supports all its options.
47
51
  * @see {@link https://playwright.dev/docs/api/class-locator#locator-click} Playwright API
@@ -49,10 +53,127 @@ export interface UserEvent {
49
53
  * @see {@link https://testing-library.com/docs/user-event/convenience/#click} testing-library API
50
54
  */
51
55
  click: (element: Element, options?: UserEventClickOptions) => Promise<void>
56
+ /**
57
+ * Triggers a double click event on an element. Uses provider's API under the hood.
58
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-dblclick} Playwright API
59
+ * @see {@link https://webdriver.io/docs/api/element/doubleClick/} WebdriverIO API
60
+ * @see {@link https://testing-library.com/docs/user-event/convenience/#dblClick} testing-library API
61
+ */
62
+ dblClick: (element: Element, options?: UserEventDoubleClickOptions) => Promise<void>
63
+ /**
64
+ * Choose one or more values from a select element. Uses provider's API under the hood.
65
+ * If select doesn't have `multiple` attribute, only the first value will be selected.
66
+ * @example
67
+ * await userEvent.selectOptions(select, 'Option 1')
68
+ * expect(select).toHaveValue('option-1')
69
+ *
70
+ * await userEvent.selectOptions(select, 'option-1')
71
+ * expect(select).toHaveValue('option-1')
72
+ *
73
+ * await userEvent.selectOptions(select, [
74
+ * screen.getByRole('option', { name: 'Option 1' }),
75
+ * screen.getByRole('option', { name: 'Option 2' }),
76
+ * ])
77
+ * expect(select).toHaveValue(['option-1', 'option-2'])
78
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-select-option} Playwright API
79
+ * @see {@link https://webdriver.io/docs/api/element/doubleClick/} WebdriverIO API
80
+ * @see {@link https://testing-library.com/docs/user-event/utility/#-selectoptions-deselectoptions} testing-library API
81
+ */
82
+ selectOptions: (
83
+ element: Element,
84
+ values: HTMLElement | HTMLElement[] | string | string[],
85
+ options?: UserEventSelectOptions,
86
+ ) => Promise<void>
87
+ /**
88
+ * Type text on the keyboard. If any input is focused, it will receive the text,
89
+ * otherwise it will be typed on the document. Uses provider's API under the hood.
90
+ * **Supports** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (e.g., `{Shift}`) even with `playwright` and `webdriverio` providers.
91
+ * @example
92
+ * await userEvent.keyboard('foo') // translates to: f, o, o
93
+ * await userEvent.keyboard('{{a[[') // translates to: {, a, [
94
+ * await userEvent.keyboard('{Shift}{f}{o}{o}') // translates to: Shift, f, o, o
95
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-press} Playwright API
96
+ * @see {@link https://webdriver.io/docs/api/browser/keys} WebdriverIO API
97
+ * @see {@link https://testing-library.com/docs/user-event/keyboard} testing-library API
98
+ */
99
+ keyboard: (text: string) => Promise<void>
100
+ /**
101
+ * Types text into an element. Uses provider's API under the hood.
102
+ * **Supports** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (e.g., `{Shift}`) even with `playwright` and `webdriverio` providers.
103
+ * @example
104
+ * await userEvent.type(input, 'foo') // translates to: f, o, o
105
+ * await userEvent.type(input, '{{a[[') // translates to: {, a, [
106
+ * await userEvent.type(input, '{Shift}{f}{o}{o}') // translates to: Shift, f, o, o
107
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-press} Playwright API
108
+ * @see {@link https://webdriver.io/docs/api/browser/action#key-input-source} WebdriverIO API
109
+ * @see {@link https://testing-library.com/docs/user-event/utility/#type} testing-library API
110
+ */
111
+ type: (element: Element, text: string, options?: UserEventTypeOptions) => Promise<void>
112
+ /**
113
+ * Removes all text from an element. Uses provider's API under the hood.
114
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-clear} Playwright API
115
+ * @see {@link https://webdriver.io/docs/api/element/clearValue} WebdriverIO API
116
+ * @see {@link https://testing-library.com/docs/user-event/utility/#clear} testing-library API
117
+ */
118
+ clear: (element: Element) => Promise<void>
119
+ /**
120
+ * Sends a `Tab` key event. Uses provider's API under the hood.
121
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-press} Playwright API
122
+ * @see {@link https://webdriver.io/docs/api/element/keys} WebdriverIO API
123
+ * @see {@link https://testing-library.com/docs/user-event/convenience/#tab} testing-library API
124
+ */
125
+ tab: (options?: UserEventTabOptions) => Promise<void>
126
+ /**
127
+ * Hovers over an element. Uses provider's API under the hood.
128
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-hover} Playwright API
129
+ * @see {@link https://webdriver.io/docs/api/element/moveTo/} WebdriverIO API
130
+ * @see {@link https://testing-library.com/docs/user-event/convenience/#hover} testing-library API
131
+ */
132
+ hover: (element: Element, options?: UserEventHoverOptions) => Promise<void>
133
+ /**
134
+ * Moves cursor position to the body element. Uses provider's API under the hood.
135
+ * By default, the cursor position is in the center (in webdriverio) or in some visible place (in playwright)
136
+ * of the body element, so if the current element is already there, this will have no effect.
137
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-hover} Playwright API
138
+ * @see {@link https://webdriver.io/docs/api/element/moveTo/} WebdriverIO API
139
+ * @see {@link https://testing-library.com/docs/user-event/convenience/#hover} testing-library API
140
+ */
141
+ unhover: (element: Element, options?: UserEventHoverOptions) => Promise<void>
142
+ /**
143
+ * Fills an input element with text. This will remove any existing text in the input before typing the new text.
144
+ * Uses provider's API under the hood.
145
+ * This API is faster than using `userEvent.type` or `userEvent.keyboard`, but it **doesn't support** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (e.g., `{Shift}`).
146
+ * @example
147
+ * await userEvent.fill(input, 'foo') // translates to: f, o, o
148
+ * await userEvent.fill(input, '{{a[[') // translates to: {, {, a, [, [
149
+ * await userEvent.fill(input, '{Shift}') // translates to: {, S, h, i, f, t, }
150
+ * @see {@link https://playwright.dev/docs/api/class-locator#locator-fill} Playwright API
151
+ * @see {@link https://webdriver.io/docs/api/element/setValue} WebdriverIO API
152
+ * @see {@link https://testing-library.com/docs/user-event/utility/#type} testing-library API
153
+ */
154
+ fill: (element: Element, text: string, options?: UserEventFillOptions) => Promise<void>
155
+ /**
156
+ * Drags a source element on top of the target element. This API is not supported by "preview" provider.
157
+ * @see {@link https://playwright.dev/docs/api/class-frame#frame-drag-and-drop} Playwright API
158
+ * @see {@link https://webdriver.io/docs/api/element/dragAndDrop/} WebdriverIO API
159
+ */
160
+ dragAndDrop: (source: Element, target: Element, options?: UserEventDragAndDropOptions) => Promise<void>
161
+ }
162
+
163
+ export interface UserEventFillOptions {}
164
+ export interface UserEventHoverOptions {}
165
+ export interface UserEventSelectOptions {}
166
+ export interface UserEventClickOptions {}
167
+ export interface UserEventDoubleClickOptions {}
168
+ export interface UserEventDragAndDropOptions {}
169
+
170
+ export interface UserEventTabOptions {
171
+ shift?: boolean
52
172
  }
53
173
 
54
- export interface UserEventClickOptions {
55
- [key: string]: any
174
+ export interface UserEventTypeOptions {
175
+ skipClick?: boolean
176
+ skipAutoClose?: boolean
56
177
  }
57
178
 
58
179
  type Platform =
@@ -125,3 +246,4 @@ export interface BrowserPage {
125
246
  }
126
247
 
127
248
  export const page: BrowserPage
249
+ export const cdp: () => CDPSession
package/context.js ADDED
@@ -0,0 +1,2 @@
1
+ // empty file to not break bundling
2
+ // Vitest resolves "@vitest/browser/context" as a virtual module instead
@@ -1,24 +1,24 @@
1
1
  {
2
- "_rpc-CImfI7bO.js": {
3
- "file": "__vitest_browser__/rpc-CImfI7bO.js",
4
- "name": "rpc"
2
+ "_client-Dz5Ebwug.js": {
3
+ "file": "__vitest_browser__/client-Dz5Ebwug.js",
4
+ "name": "client"
5
5
  },
6
6
  "orchestrator.html": {
7
- "file": "__vitest_browser__/orchestrator-BCpOi5ot.js",
7
+ "file": "__vitest_browser__/orchestrator-DJ6H4qlM.js",
8
8
  "name": "orchestrator",
9
9
  "src": "orchestrator.html",
10
10
  "isEntry": true,
11
11
  "imports": [
12
- "_rpc-CImfI7bO.js"
12
+ "_client-Dz5Ebwug.js"
13
13
  ]
14
14
  },
15
- "tester.html": {
16
- "file": "__vitest_browser__/tester-e70VCOgC.js",
15
+ "tester/tester.html": {
16
+ "file": "__vitest_browser__/tester-DHXll_4H.js",
17
17
  "name": "tester",
18
- "src": "tester.html",
18
+ "src": "tester/tester.html",
19
19
  "isEntry": true,
20
20
  "imports": [
21
- "_rpc-CImfI7bO.js"
21
+ "_client-Dz5Ebwug.js"
22
22
  ]
23
23
  }
24
24
  }