@vitest/browser 2.0.0-beta.9 → 2.0.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.
- package/context.d.ts +167 -14
- package/context.js +2 -0
- package/dist/client/.vite/manifest.json +9 -9
- package/dist/client/__vitest__/assets/index-CE3UTfRN.js +52 -0
- package/dist/client/__vitest__/assets/index-DEM1IsBG.css +1 -0
- package/dist/client/__vitest__/index.html +16 -11
- package/dist/client/__vitest_browser__/{rpc-DBukiZYG.js → client-dLyjuL0K.js} +156 -174
- package/dist/client/__vitest_browser__/orchestrator-x0A1t8rC.js +369 -0
- package/dist/client/__vitest_browser__/tester-BdcP5piS.js +12070 -0
- package/dist/client/esm-client-injector.js +21 -18
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/{tester.html → tester/tester.html} +12 -3
- package/dist/context.js +206 -0
- package/dist/index.d.ts +128 -4
- package/dist/index.js +2074 -457
- package/dist/providers.js +16 -112
- package/dist/state.js +1 -0
- package/dist/webdriver-BdVqnfdE.js +249 -0
- package/jest-dom.d.ts +816 -0
- package/matchers.d.ts +22 -0
- package/package.json +20 -12
- package/providers/playwright.d.ts +60 -2
- package/providers/webdriverio.d.ts +5 -0
- package/dist/client/__vitest__/assets/index-BZPCs_Bg.js +0 -51
- package/dist/client/__vitest__/assets/index-DrQA2UkS.css +0 -1
- package/dist/client/__vitest_browser__/orchestrator-CTfJ7g35.js +0 -186
- package/dist/client/__vitest_browser__/tester-Bo1gw1oi.js +0 -696
package/context.d.ts
CHANGED
|
@@ -19,21 +19,37 @@ export interface FsOptions {
|
|
|
19
19
|
flag?: string | number
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export interface
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export interface UpPayload { up: string }
|
|
22
|
+
export interface CDPSession {
|
|
23
|
+
// methods are defined by the provider type augmentation
|
|
24
|
+
}
|
|
26
25
|
|
|
27
|
-
export
|
|
26
|
+
export interface ScreenshotOptions {
|
|
27
|
+
element?: Element
|
|
28
|
+
/**
|
|
29
|
+
* Path relative to the `screenshotDirectory` in the test config.
|
|
30
|
+
*/
|
|
31
|
+
path?: string
|
|
32
|
+
/**
|
|
33
|
+
* Will also return the base64 encoded screenshot alongside the path.
|
|
34
|
+
*/
|
|
35
|
+
base64?: boolean
|
|
36
|
+
}
|
|
28
37
|
|
|
29
38
|
export interface BrowserCommands {
|
|
30
|
-
readFile: (
|
|
31
|
-
|
|
39
|
+
readFile: (
|
|
40
|
+
path: string,
|
|
41
|
+
options?: BufferEncoding | FsOptions
|
|
42
|
+
) => Promise<string>
|
|
43
|
+
writeFile: (
|
|
44
|
+
path: string,
|
|
45
|
+
content: string,
|
|
46
|
+
options?: BufferEncoding | (FsOptions & { mode?: number | string })
|
|
47
|
+
) => Promise<void>
|
|
32
48
|
removeFile: (path: string) => Promise<void>
|
|
33
|
-
sendKeys: (payload: SendKeysPayload) => Promise<void>
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
export interface UserEvent {
|
|
52
|
+
setup: () => UserEvent
|
|
37
53
|
/**
|
|
38
54
|
* Click on an element. Uses provider's API under the hood and supports all its options.
|
|
39
55
|
* @see {@link https://playwright.dev/docs/api/class-locator#locator-click} Playwright API
|
|
@@ -41,10 +57,135 @@ export interface UserEvent {
|
|
|
41
57
|
* @see {@link https://testing-library.com/docs/user-event/convenience/#click} testing-library API
|
|
42
58
|
*/
|
|
43
59
|
click: (element: Element, options?: UserEventClickOptions) => Promise<void>
|
|
60
|
+
/**
|
|
61
|
+
* Triggers a double click event on an element. Uses provider's API under the hood.
|
|
62
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-dblclick} Playwright API
|
|
63
|
+
* @see {@link https://webdriver.io/docs/api/element/doubleClick/} WebdriverIO API
|
|
64
|
+
* @see {@link https://testing-library.com/docs/user-event/convenience/#dblClick} testing-library API
|
|
65
|
+
*/
|
|
66
|
+
dblClick: (element: Element, options?: UserEventDoubleClickOptions) => Promise<void>
|
|
67
|
+
/**
|
|
68
|
+
* Triggers a triple click event on an element. Uses provider's API under the hood.
|
|
69
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-click} Playwright API: using `click` with `clickCount: 3`
|
|
70
|
+
* @see {@link https://webdriver.io/docs/api/browser/actions/} WebdriverIO API: using actions api with `move` plus three `down + up + pause` events in a row
|
|
71
|
+
* @see {@link https://testing-library.com/docs/user-event/convenience/#tripleclick} testing-library API
|
|
72
|
+
*/
|
|
73
|
+
tripleClick: (element: Element, options?: UserEventTripleClickOptions) => Promise<void>
|
|
74
|
+
/**
|
|
75
|
+
* Choose one or more values from a select element. Uses provider's API under the hood.
|
|
76
|
+
* If select doesn't have `multiple` attribute, only the first value will be selected.
|
|
77
|
+
* @example
|
|
78
|
+
* await userEvent.selectOptions(select, 'Option 1')
|
|
79
|
+
* expect(select).toHaveValue('option-1')
|
|
80
|
+
*
|
|
81
|
+
* await userEvent.selectOptions(select, 'option-1')
|
|
82
|
+
* expect(select).toHaveValue('option-1')
|
|
83
|
+
*
|
|
84
|
+
* await userEvent.selectOptions(select, [
|
|
85
|
+
* screen.getByRole('option', { name: 'Option 1' }),
|
|
86
|
+
* screen.getByRole('option', { name: 'Option 2' }),
|
|
87
|
+
* ])
|
|
88
|
+
* expect(select).toHaveValue(['option-1', 'option-2'])
|
|
89
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-select-option} Playwright API
|
|
90
|
+
* @see {@link https://webdriver.io/docs/api/element/doubleClick/} WebdriverIO API
|
|
91
|
+
* @see {@link https://testing-library.com/docs/user-event/utility/#-selectoptions-deselectoptions} testing-library API
|
|
92
|
+
*/
|
|
93
|
+
selectOptions: (
|
|
94
|
+
element: Element,
|
|
95
|
+
values: HTMLElement | HTMLElement[] | string | string[],
|
|
96
|
+
options?: UserEventSelectOptions,
|
|
97
|
+
) => Promise<void>
|
|
98
|
+
/**
|
|
99
|
+
* Type text on the keyboard. If any input is focused, it will receive the text,
|
|
100
|
+
* otherwise it will be typed on the document. Uses provider's API under the hood.
|
|
101
|
+
* **Supports** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (e.g., `{Shift}`) even with `playwright` and `webdriverio` providers.
|
|
102
|
+
* @example
|
|
103
|
+
* await userEvent.keyboard('foo') // translates to: f, o, o
|
|
104
|
+
* await userEvent.keyboard('{{a[[') // translates to: {, a, [
|
|
105
|
+
* await userEvent.keyboard('{Shift}{f}{o}{o}') // translates to: Shift, f, o, o
|
|
106
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-press} Playwright API
|
|
107
|
+
* @see {@link https://webdriver.io/docs/api/browser/keys} WebdriverIO API
|
|
108
|
+
* @see {@link https://testing-library.com/docs/user-event/keyboard} testing-library API
|
|
109
|
+
*/
|
|
110
|
+
keyboard: (text: string) => Promise<void>
|
|
111
|
+
/**
|
|
112
|
+
* Types text into an element. Uses provider's API under the hood.
|
|
113
|
+
* **Supports** [user-event `keyboard` syntax](https://testing-library.com/docs/user-event/keyboard) (e.g., `{Shift}`) even with `playwright` and `webdriverio` providers.
|
|
114
|
+
* @example
|
|
115
|
+
* await userEvent.type(input, 'foo') // translates to: f, o, o
|
|
116
|
+
* await userEvent.type(input, '{{a[[') // translates to: {, a, [
|
|
117
|
+
* await userEvent.type(input, '{Shift}{f}{o}{o}') // translates to: Shift, f, o, o
|
|
118
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-press} Playwright API
|
|
119
|
+
* @see {@link https://webdriver.io/docs/api/browser/action#key-input-source} WebdriverIO API
|
|
120
|
+
* @see {@link https://testing-library.com/docs/user-event/utility/#type} testing-library API
|
|
121
|
+
*/
|
|
122
|
+
type: (element: Element, text: string, options?: UserEventTypeOptions) => Promise<void>
|
|
123
|
+
/**
|
|
124
|
+
* Removes all text from an element. Uses provider's API under the hood.
|
|
125
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-clear} Playwright API
|
|
126
|
+
* @see {@link https://webdriver.io/docs/api/element/clearValue} WebdriverIO API
|
|
127
|
+
* @see {@link https://testing-library.com/docs/user-event/utility/#clear} testing-library API
|
|
128
|
+
*/
|
|
129
|
+
clear: (element: Element) => Promise<void>
|
|
130
|
+
/**
|
|
131
|
+
* Sends a `Tab` key event. Uses provider's API under the hood.
|
|
132
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-press} Playwright API
|
|
133
|
+
* @see {@link https://webdriver.io/docs/api/element/keys} WebdriverIO API
|
|
134
|
+
* @see {@link https://testing-library.com/docs/user-event/convenience/#tab} testing-library API
|
|
135
|
+
*/
|
|
136
|
+
tab: (options?: UserEventTabOptions) => Promise<void>
|
|
137
|
+
/**
|
|
138
|
+
* Hovers over an element. Uses provider's API under the hood.
|
|
139
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-hover} Playwright API
|
|
140
|
+
* @see {@link https://webdriver.io/docs/api/element/moveTo/} WebdriverIO API
|
|
141
|
+
* @see {@link https://testing-library.com/docs/user-event/convenience/#hover} testing-library API
|
|
142
|
+
*/
|
|
143
|
+
hover: (element: Element, options?: UserEventHoverOptions) => Promise<void>
|
|
144
|
+
/**
|
|
145
|
+
* Moves cursor position to the body element. Uses provider's API under the hood.
|
|
146
|
+
* By default, the cursor position is in the center (in webdriverio) or in some visible place (in playwright)
|
|
147
|
+
* of the body element, so if the current element is already there, this will have no effect.
|
|
148
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-hover} Playwright API
|
|
149
|
+
* @see {@link https://webdriver.io/docs/api/element/moveTo/} WebdriverIO API
|
|
150
|
+
* @see {@link https://testing-library.com/docs/user-event/convenience/#hover} testing-library API
|
|
151
|
+
*/
|
|
152
|
+
unhover: (element: Element, options?: UserEventHoverOptions) => Promise<void>
|
|
153
|
+
/**
|
|
154
|
+
* Fills an input element with text. This will remove any existing text in the input before typing the new text.
|
|
155
|
+
* Uses provider's API under the hood.
|
|
156
|
+
* 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}`).
|
|
157
|
+
* @example
|
|
158
|
+
* await userEvent.fill(input, 'foo') // translates to: f, o, o
|
|
159
|
+
* await userEvent.fill(input, '{{a[[') // translates to: {, {, a, [, [
|
|
160
|
+
* await userEvent.fill(input, '{Shift}') // translates to: {, S, h, i, f, t, }
|
|
161
|
+
* @see {@link https://playwright.dev/docs/api/class-locator#locator-fill} Playwright API
|
|
162
|
+
* @see {@link https://webdriver.io/docs/api/element/setValue} WebdriverIO API
|
|
163
|
+
* @see {@link https://testing-library.com/docs/user-event/utility/#type} testing-library API
|
|
164
|
+
*/
|
|
165
|
+
fill: (element: Element, text: string, options?: UserEventFillOptions) => Promise<void>
|
|
166
|
+
/**
|
|
167
|
+
* Drags a source element on top of the target element. This API is not supported by "preview" provider.
|
|
168
|
+
* @see {@link https://playwright.dev/docs/api/class-frame#frame-drag-and-drop} Playwright API
|
|
169
|
+
* @see {@link https://webdriver.io/docs/api/element/dragAndDrop/} WebdriverIO API
|
|
170
|
+
*/
|
|
171
|
+
dragAndDrop: (source: Element, target: Element, options?: UserEventDragAndDropOptions) => Promise<void>
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface UserEventFillOptions {}
|
|
175
|
+
export interface UserEventHoverOptions {}
|
|
176
|
+
export interface UserEventSelectOptions {}
|
|
177
|
+
export interface UserEventClickOptions {}
|
|
178
|
+
export interface UserEventDoubleClickOptions {}
|
|
179
|
+
export interface UserEventTripleClickOptions {}
|
|
180
|
+
export interface UserEventDragAndDropOptions {}
|
|
181
|
+
|
|
182
|
+
export interface UserEventTabOptions {
|
|
183
|
+
shift?: boolean
|
|
44
184
|
}
|
|
45
185
|
|
|
46
|
-
export interface
|
|
47
|
-
|
|
186
|
+
export interface UserEventTypeOptions {
|
|
187
|
+
skipClick?: boolean
|
|
188
|
+
skipAutoClose?: boolean
|
|
48
189
|
}
|
|
49
190
|
|
|
50
191
|
type Platform =
|
|
@@ -81,7 +222,7 @@ export const server: {
|
|
|
81
222
|
browser: string
|
|
82
223
|
/**
|
|
83
224
|
* Available commands for the browser.
|
|
84
|
-
* @see {@link https://vitest.dev/guide/browser
|
|
225
|
+
* @see {@link https://vitest.dev/guide/browser/commands}
|
|
85
226
|
*/
|
|
86
227
|
commands: BrowserCommands
|
|
87
228
|
}
|
|
@@ -96,11 +237,11 @@ export const userEvent: UserEvent
|
|
|
96
237
|
/**
|
|
97
238
|
* Available commands for the browser.
|
|
98
239
|
* A shortcut to `server.commands`.
|
|
99
|
-
* @see {@link https://vitest.dev/guide/browser
|
|
240
|
+
* @see {@link https://vitest.dev/guide/browser/commands}
|
|
100
241
|
*/
|
|
101
242
|
export const commands: BrowserCommands
|
|
102
243
|
|
|
103
|
-
export
|
|
244
|
+
export interface BrowserPage {
|
|
104
245
|
/**
|
|
105
246
|
* Serialized test config.
|
|
106
247
|
*/
|
|
@@ -108,5 +249,17 @@ export const page: {
|
|
|
108
249
|
/**
|
|
109
250
|
* Change the size of iframe's viewport.
|
|
110
251
|
*/
|
|
111
|
-
viewport
|
|
252
|
+
viewport(width: number, height: number): Promise<void>
|
|
253
|
+
/**
|
|
254
|
+
* Make a screenshot of the test iframe or a specific element.
|
|
255
|
+
* @returns Path to the screenshot file or path and base64.
|
|
256
|
+
*/
|
|
257
|
+
screenshot(options: Omit<ScreenshotOptions, 'base64'> & { base64: true }): Promise<{
|
|
258
|
+
path: string
|
|
259
|
+
base64: string
|
|
260
|
+
}>
|
|
261
|
+
screenshot(options?: ScreenshotOptions): Promise<string>
|
|
112
262
|
}
|
|
263
|
+
|
|
264
|
+
export const page: BrowserPage
|
|
265
|
+
export const cdp: () => CDPSession
|
package/context.js
ADDED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"file": "__vitest_browser__/
|
|
4
|
-
"name": "
|
|
2
|
+
"_client-dLyjuL0K.js": {
|
|
3
|
+
"file": "__vitest_browser__/client-dLyjuL0K.js",
|
|
4
|
+
"name": "client"
|
|
5
5
|
},
|
|
6
6
|
"orchestrator.html": {
|
|
7
|
-
"file": "__vitest_browser__/orchestrator-
|
|
7
|
+
"file": "__vitest_browser__/orchestrator-x0A1t8rC.js",
|
|
8
8
|
"name": "orchestrator",
|
|
9
9
|
"src": "orchestrator.html",
|
|
10
10
|
"isEntry": true,
|
|
11
11
|
"imports": [
|
|
12
|
-
"
|
|
12
|
+
"_client-dLyjuL0K.js"
|
|
13
13
|
]
|
|
14
14
|
},
|
|
15
|
-
"tester.html": {
|
|
16
|
-
"file": "__vitest_browser__/tester-
|
|
15
|
+
"tester/tester.html": {
|
|
16
|
+
"file": "__vitest_browser__/tester-BdcP5piS.js",
|
|
17
17
|
"name": "tester",
|
|
18
|
-
"src": "tester.html",
|
|
18
|
+
"src": "tester/tester.html",
|
|
19
19
|
"isEntry": true,
|
|
20
20
|
"imports": [
|
|
21
|
-
"
|
|
21
|
+
"_client-dLyjuL0K.js"
|
|
22
22
|
]
|
|
23
23
|
}
|
|
24
24
|
}
|