@vitest/browser 2.0.4 → 2.1.0-beta.1
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/aria-role.d.ts +96 -0
- package/context.d.ts +232 -20
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/__vitest__/assets/index-JTfsnJeu.css +1 -0
- package/dist/client/__vitest__/assets/index-uh8h5Yzr.js +52 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/index.html +4 -3
- package/dist/client/__vitest_browser__/{orchestrator-CNOAigTE.js → orchestrator-BObhEEvc.js} +4 -4
- package/dist/client/__vitest_browser__/{tester-BSSDPE9E.js → tester-CRcWWhrn.js} +19 -5
- package/dist/client/error-catcher.js +10 -16
- package/dist/client/orchestrator.html +1 -1
- package/dist/client/tester/tester.html +3 -11
- package/dist/context.js +260 -111
- package/dist/index-BRfqvYVY.js +5722 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +100 -62
- package/dist/locators/index.d.ts +261 -0
- package/dist/locators/index.js +2 -0
- package/dist/locators/playwright.js +42 -0
- package/dist/locators/preview.js +86 -0
- package/dist/locators/webdriverio.js +83 -0
- package/jest-dom.d.ts +1 -97
- package/matchers.d.ts +2 -1
- package/package.json +19 -14
- package/providers/playwright.d.ts +2 -1
- package/providers/webdriverio.d.ts +10 -1
- package/dist/client/__vitest__/assets/index--tE7Z8jQ.js +0 -52
- package/dist/client/__vitest__/assets/index-C0SwoDYm.css +0 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { UserEventClickOptions, UserEventHoverOptions, UserEventFillOptions, UserEventDragAndDropOptions, LocatorScreenshotOptions, LocatorByRoleOptions, LocatorOptions } from '@vitest/browser/context';
|
|
2
|
+
|
|
3
|
+
type ClauseCombinator = '' | '>' | '+' | '~' | '>=';
|
|
4
|
+
type CSSFunctionArgument = CSSComplexSelector | number | string;
|
|
5
|
+
interface CSSFunction {
|
|
6
|
+
name: string;
|
|
7
|
+
args: CSSFunctionArgument[];
|
|
8
|
+
}
|
|
9
|
+
interface CSSSimpleSelector {
|
|
10
|
+
css?: string;
|
|
11
|
+
functions: CSSFunction[];
|
|
12
|
+
}
|
|
13
|
+
interface CSSComplexSelector {
|
|
14
|
+
simples: {
|
|
15
|
+
selector: CSSSimpleSelector;
|
|
16
|
+
combinator: ClauseCombinator;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
type CSSComplexSelectorList = CSSComplexSelector[];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Copyright (c) Microsoft Corporation.
|
|
23
|
+
*
|
|
24
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
25
|
+
* you may not use this file except in compliance with the License.
|
|
26
|
+
* You may obtain a copy of the License at
|
|
27
|
+
*
|
|
28
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
29
|
+
*
|
|
30
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
31
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
32
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
33
|
+
* See the License for the specific language governing permissions and
|
|
34
|
+
* limitations under the License.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
interface NestedSelectorBody {
|
|
38
|
+
parsed: ParsedSelector;
|
|
39
|
+
distance?: number;
|
|
40
|
+
}
|
|
41
|
+
interface ParsedSelectorPart {
|
|
42
|
+
name: string;
|
|
43
|
+
body: string | CSSComplexSelectorList | NestedSelectorBody;
|
|
44
|
+
source: string;
|
|
45
|
+
}
|
|
46
|
+
interface ParsedSelector {
|
|
47
|
+
parts: ParsedSelectorPart[];
|
|
48
|
+
capture?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Copyright (c) Microsoft Corporation.
|
|
53
|
+
*
|
|
54
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
55
|
+
* you may not use this file except in compliance with the License.
|
|
56
|
+
* You may obtain a copy of the License at
|
|
57
|
+
*
|
|
58
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
59
|
+
*
|
|
60
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
61
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
62
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
63
|
+
* See the License for the specific language governing permissions and
|
|
64
|
+
* limitations under the License.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
interface GenerateSelectorOptions {
|
|
68
|
+
testIdAttributeName: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Copyright (c) Microsoft Corporation.
|
|
73
|
+
*
|
|
74
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
75
|
+
* you may not use this file except in compliance with the License.
|
|
76
|
+
* You may obtain a copy of the License at
|
|
77
|
+
*
|
|
78
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
79
|
+
*
|
|
80
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
81
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
82
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
83
|
+
* See the License for the specific language governing permissions and
|
|
84
|
+
* limitations under the License.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
interface ElementText {
|
|
88
|
+
full: string;
|
|
89
|
+
normalized: string;
|
|
90
|
+
immediate: string[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Copyright (c) Microsoft Corporation.
|
|
95
|
+
*
|
|
96
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
97
|
+
* you may not use this file except in compliance with the License.
|
|
98
|
+
* You may obtain a copy of the License at
|
|
99
|
+
*
|
|
100
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
*
|
|
102
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
103
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
104
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
105
|
+
* See the License for the specific language governing permissions and
|
|
106
|
+
* limitations under the License.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
interface QueryContext {
|
|
110
|
+
scope: Element | Document;
|
|
111
|
+
pierceShadow: boolean;
|
|
112
|
+
originalScope?: Element | Document;
|
|
113
|
+
}
|
|
114
|
+
type Selector = any;
|
|
115
|
+
interface SelectorEvaluator {
|
|
116
|
+
query: (context: QueryContext, selector: Selector) => Element[];
|
|
117
|
+
matches: (element: Element, selector: Selector, context: QueryContext) => boolean;
|
|
118
|
+
}
|
|
119
|
+
interface SelectorEngine$1 {
|
|
120
|
+
matches?: (element: Element, args: (string | number | Selector)[], context: QueryContext, evaluator: SelectorEvaluator) => boolean;
|
|
121
|
+
query?: (context: QueryContext, args: (string | number | Selector)[], evaluator: SelectorEvaluator) => Element[];
|
|
122
|
+
}
|
|
123
|
+
declare class SelectorEvaluatorImpl implements SelectorEvaluator {
|
|
124
|
+
private _engines;
|
|
125
|
+
private _cacheQueryCSS;
|
|
126
|
+
private _cacheMatches;
|
|
127
|
+
private _cacheQuery;
|
|
128
|
+
private _cacheMatchesSimple;
|
|
129
|
+
private _cacheMatchesParents;
|
|
130
|
+
private _cacheCallMatches;
|
|
131
|
+
private _cacheCallQuery;
|
|
132
|
+
private _cacheQuerySimple;
|
|
133
|
+
_cacheText: Map<Element | ShadowRoot, ElementText>;
|
|
134
|
+
private _scoreMap;
|
|
135
|
+
private _retainCacheCounter;
|
|
136
|
+
constructor(extraEngines: Map<string, SelectorEngine$1>);
|
|
137
|
+
begin(): void;
|
|
138
|
+
end(): void;
|
|
139
|
+
private _cached;
|
|
140
|
+
private _checkSelector;
|
|
141
|
+
matches(element: Element, s: Selector, context: QueryContext): boolean;
|
|
142
|
+
query(context: QueryContext, s: any): Element[];
|
|
143
|
+
_markScore(element: Element, score: number): void;
|
|
144
|
+
private _hasScopeClause;
|
|
145
|
+
private _expandContextForScopeMatching;
|
|
146
|
+
private _matchesSimple;
|
|
147
|
+
private _querySimple;
|
|
148
|
+
private _matchesParents;
|
|
149
|
+
private _matchesEngine;
|
|
150
|
+
private _queryEngine;
|
|
151
|
+
private _callMatches;
|
|
152
|
+
private _callQuery;
|
|
153
|
+
private _matchesCSS;
|
|
154
|
+
_queryCSS(context: QueryContext, css: string): Element[];
|
|
155
|
+
private _getEngine;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Copyright (c) Microsoft Corporation.
|
|
160
|
+
*
|
|
161
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
162
|
+
* you may not use this file except in compliance with the License.
|
|
163
|
+
* You may obtain a copy of the License at
|
|
164
|
+
*
|
|
165
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
166
|
+
*
|
|
167
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
168
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
169
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
170
|
+
* See the License for the specific language governing permissions and
|
|
171
|
+
* limitations under the License.
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
interface IvyaOptions {
|
|
175
|
+
testIdAttribute: string;
|
|
176
|
+
browser: 'webkit' | 'chromium' | 'firefox';
|
|
177
|
+
}
|
|
178
|
+
interface IvyaConfiguration {
|
|
179
|
+
testIdAttribute?: string;
|
|
180
|
+
browser: 'webkit' | 'chromium' | 'firefox';
|
|
181
|
+
}
|
|
182
|
+
declare class Ivya {
|
|
183
|
+
/** @internal */
|
|
184
|
+
_engines: Map<string, SelectorEngine>;
|
|
185
|
+
/** @internal */
|
|
186
|
+
_evaluator: SelectorEvaluatorImpl;
|
|
187
|
+
static options: IvyaOptions;
|
|
188
|
+
private static singleton;
|
|
189
|
+
static create(options: IvyaConfiguration): Ivya;
|
|
190
|
+
private constructor();
|
|
191
|
+
queryLocatorSelector(locator: string, root?: Node, strict?: boolean): Element | null;
|
|
192
|
+
queryLocatorSelectorAll(locator: string, root?: Node): Element[];
|
|
193
|
+
querySelector(selector: ParsedSelector, root: Node, strict?: boolean): Element | null;
|
|
194
|
+
private strictModeViolationError;
|
|
195
|
+
generateSelectorSimple(targetElement: Element, options?: GenerateSelectorOptions): string;
|
|
196
|
+
parseSelector(selector: string): ParsedSelector;
|
|
197
|
+
previewNode(node: Node): string;
|
|
198
|
+
querySelectorAll(selector: ParsedSelector, root: Node): Element[];
|
|
199
|
+
private _queryEngineAll;
|
|
200
|
+
private _queryNth;
|
|
201
|
+
private _queryLayoutSelector;
|
|
202
|
+
private createStacklessError;
|
|
203
|
+
private _createTextEngine;
|
|
204
|
+
private _createAttributeEngine;
|
|
205
|
+
private _createCSSEngine;
|
|
206
|
+
private _createNamedAttributeEngine;
|
|
207
|
+
private _createVisibleEngine;
|
|
208
|
+
private _createHasEngine;
|
|
209
|
+
private _createHasNotEngine;
|
|
210
|
+
private _createInternalChainEngine;
|
|
211
|
+
private _createInternalLabelEngine;
|
|
212
|
+
private _createInternalHasTextEngine;
|
|
213
|
+
private _createInternalHasNotTextEngine;
|
|
214
|
+
}
|
|
215
|
+
type SelectorRoot = Element | ShadowRoot | Document;
|
|
216
|
+
interface SelectorEngine {
|
|
217
|
+
queryAll: (root: SelectorRoot, selector: string | any) => Element[];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
declare const selectorEngine: Ivya;
|
|
221
|
+
declare abstract class Locator {
|
|
222
|
+
abstract selector: string;
|
|
223
|
+
private _parsedSelector;
|
|
224
|
+
protected _pwSelector?: string | undefined;
|
|
225
|
+
protected _forceElement?: Element | undefined;
|
|
226
|
+
click(options?: UserEventClickOptions): Promise<void>;
|
|
227
|
+
dblClick(options?: UserEventClickOptions): Promise<void>;
|
|
228
|
+
tripleClick(options?: UserEventClickOptions): Promise<void>;
|
|
229
|
+
clear(): Promise<void>;
|
|
230
|
+
hover(options: UserEventHoverOptions): Promise<void>;
|
|
231
|
+
unhover(options: UserEventHoverOptions): Promise<void>;
|
|
232
|
+
fill(text: string, options?: UserEventFillOptions): Promise<void>;
|
|
233
|
+
dropTo(target: Locator, options?: UserEventDragAndDropOptions): Promise<void>;
|
|
234
|
+
selectOptions(value: HTMLElement | HTMLElement[] | Locator | Locator[] | string | string[]): Promise<void>;
|
|
235
|
+
screenshot(options: Omit<LocatorScreenshotOptions, 'base64'> & {
|
|
236
|
+
base64: true;
|
|
237
|
+
}): Promise<{
|
|
238
|
+
path: string;
|
|
239
|
+
base64: string;
|
|
240
|
+
}>;
|
|
241
|
+
screenshot(options?: LocatorScreenshotOptions): Promise<string>;
|
|
242
|
+
protected abstract locator(selector: string): Locator;
|
|
243
|
+
protected abstract elementLocator(element: Element): Locator;
|
|
244
|
+
getByRole(role: string, options?: LocatorByRoleOptions): Locator;
|
|
245
|
+
getByAltText(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
246
|
+
getByLabelText(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
247
|
+
getByPlaceholder(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
248
|
+
getByTestId(testId: string | RegExp): Locator;
|
|
249
|
+
getByText(text: string | RegExp, options?: LocatorOptions): Locator;
|
|
250
|
+
getByTitle(title: string | RegExp, options?: LocatorOptions): Locator;
|
|
251
|
+
query(): Element | null;
|
|
252
|
+
element(): Element;
|
|
253
|
+
elements(): Element[];
|
|
254
|
+
all(): Locator[];
|
|
255
|
+
private get state();
|
|
256
|
+
private get worker();
|
|
257
|
+
private get rpc();
|
|
258
|
+
protected triggerCommand<T>(command: string, ...args: any[]): Promise<T>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { Locator, selectorEngine };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { page, server } from '@vitest/browser/context';
|
|
2
|
+
import { g as getByLabelSelector, a as getByRoleSelector, b as getByTestIdSelector, c as getByAltTextSelector, d as getByPlaceholderSelector, e as getByTextSelector, f as getByTitleSelector, s as selectorEngine, L as Locator } from '../index-BRfqvYVY.js';
|
|
3
|
+
|
|
4
|
+
page.extend({
|
|
5
|
+
getByLabelText(text, options) {
|
|
6
|
+
return new PlaywrightLocator(getByLabelSelector(text, options));
|
|
7
|
+
},
|
|
8
|
+
getByRole(role, options) {
|
|
9
|
+
return new PlaywrightLocator(getByRoleSelector(role, options));
|
|
10
|
+
},
|
|
11
|
+
getByTestId(testId) {
|
|
12
|
+
return new PlaywrightLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
13
|
+
},
|
|
14
|
+
getByAltText(text, options) {
|
|
15
|
+
return new PlaywrightLocator(getByAltTextSelector(text, options));
|
|
16
|
+
},
|
|
17
|
+
getByPlaceholder(text, options) {
|
|
18
|
+
return new PlaywrightLocator(getByPlaceholderSelector(text, options));
|
|
19
|
+
},
|
|
20
|
+
getByText(text, options) {
|
|
21
|
+
return new PlaywrightLocator(getByTextSelector(text, options));
|
|
22
|
+
},
|
|
23
|
+
getByTitle(title, options) {
|
|
24
|
+
return new PlaywrightLocator(getByTitleSelector(title, options));
|
|
25
|
+
},
|
|
26
|
+
elementLocator(element) {
|
|
27
|
+
return new PlaywrightLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
class PlaywrightLocator extends Locator {
|
|
31
|
+
constructor(selector, _forceElement) {
|
|
32
|
+
super();
|
|
33
|
+
this.selector = selector;
|
|
34
|
+
this._forceElement = _forceElement;
|
|
35
|
+
}
|
|
36
|
+
locator(selector) {
|
|
37
|
+
return new PlaywrightLocator(`${this.selector} >> ${selector}`);
|
|
38
|
+
}
|
|
39
|
+
elementLocator(element) {
|
|
40
|
+
return new PlaywrightLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { page, server } from '@vitest/browser/context';
|
|
2
|
+
import { userEvent } from '@testing-library/user-event';
|
|
3
|
+
import { g as getByLabelSelector, a as getByRoleSelector, b as getByTestIdSelector, c as getByAltTextSelector, d as getByPlaceholderSelector, e as getByTextSelector, f as getByTitleSelector, s as selectorEngine, L as Locator, h as convertElementToCssSelector } from '../index-BRfqvYVY.js';
|
|
4
|
+
|
|
5
|
+
page.extend({
|
|
6
|
+
getByLabelText(text, options) {
|
|
7
|
+
return new PreviewLocator(getByLabelSelector(text, options));
|
|
8
|
+
},
|
|
9
|
+
getByRole(role, options) {
|
|
10
|
+
return new PreviewLocator(getByRoleSelector(role, options));
|
|
11
|
+
},
|
|
12
|
+
getByTestId(testId) {
|
|
13
|
+
return new PreviewLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
14
|
+
},
|
|
15
|
+
getByAltText(text, options) {
|
|
16
|
+
return new PreviewLocator(getByAltTextSelector(text, options));
|
|
17
|
+
},
|
|
18
|
+
getByPlaceholder(text, options) {
|
|
19
|
+
return new PreviewLocator(getByPlaceholderSelector(text, options));
|
|
20
|
+
},
|
|
21
|
+
getByText(text, options) {
|
|
22
|
+
return new PreviewLocator(getByTextSelector(text, options));
|
|
23
|
+
},
|
|
24
|
+
getByTitle(title, options) {
|
|
25
|
+
return new PreviewLocator(getByTitleSelector(title, options));
|
|
26
|
+
},
|
|
27
|
+
elementLocator(element) {
|
|
28
|
+
return new PreviewLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
class PreviewLocator extends Locator {
|
|
32
|
+
constructor(_pwSelector, _forceElement) {
|
|
33
|
+
super();
|
|
34
|
+
this._pwSelector = _pwSelector;
|
|
35
|
+
this._forceElement = _forceElement;
|
|
36
|
+
}
|
|
37
|
+
get selector() {
|
|
38
|
+
const selectors = this.elements().map((element) => convertElementToCssSelector(element));
|
|
39
|
+
if (!selectors.length) {
|
|
40
|
+
throw new Error(`element not found: ${this._pwSelector}`);
|
|
41
|
+
}
|
|
42
|
+
return selectors.join(", ");
|
|
43
|
+
}
|
|
44
|
+
click() {
|
|
45
|
+
return userEvent.click(this.element());
|
|
46
|
+
}
|
|
47
|
+
dblClick() {
|
|
48
|
+
return userEvent.dblClick(this.element());
|
|
49
|
+
}
|
|
50
|
+
tripleClick() {
|
|
51
|
+
return userEvent.tripleClick(this.element());
|
|
52
|
+
}
|
|
53
|
+
hover() {
|
|
54
|
+
return userEvent.hover(this.element());
|
|
55
|
+
}
|
|
56
|
+
unhover() {
|
|
57
|
+
return userEvent.unhover(this.element());
|
|
58
|
+
}
|
|
59
|
+
fill(text) {
|
|
60
|
+
return userEvent.type(this.element(), text);
|
|
61
|
+
}
|
|
62
|
+
selectOptions(options_) {
|
|
63
|
+
const options = (Array.isArray(options_) ? options_ : [options_]).map((option) => {
|
|
64
|
+
if (typeof option !== "string" && "element" in option) {
|
|
65
|
+
return option.element();
|
|
66
|
+
}
|
|
67
|
+
return option;
|
|
68
|
+
});
|
|
69
|
+
return userEvent.selectOptions(this.element(), options);
|
|
70
|
+
}
|
|
71
|
+
async dropTo() {
|
|
72
|
+
throw new Error('The "preview" provider doesn\'t support `dropTo` method.');
|
|
73
|
+
}
|
|
74
|
+
clear() {
|
|
75
|
+
return userEvent.clear(this.element());
|
|
76
|
+
}
|
|
77
|
+
async screenshot() {
|
|
78
|
+
throw new Error('The "preview" provider doesn\'t support `screenshot` method.');
|
|
79
|
+
}
|
|
80
|
+
locator(selector) {
|
|
81
|
+
return new PreviewLocator(`${this._pwSelector} >> ${selector}`);
|
|
82
|
+
}
|
|
83
|
+
elementLocator(element) {
|
|
84
|
+
return new PreviewLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { page, server } from '@vitest/browser/context';
|
|
2
|
+
import { g as getByLabelSelector, a as getByRoleSelector, b as getByTestIdSelector, c as getByAltTextSelector, d as getByPlaceholderSelector, e as getByTextSelector, f as getByTitleSelector, s as selectorEngine, L as Locator, h as convertElementToCssSelector } from '../index-BRfqvYVY.js';
|
|
3
|
+
|
|
4
|
+
page.extend({
|
|
5
|
+
getByLabelText(text, options) {
|
|
6
|
+
return new WebdriverIOLocator(getByLabelSelector(text, options));
|
|
7
|
+
},
|
|
8
|
+
getByRole(role, options) {
|
|
9
|
+
return new WebdriverIOLocator(getByRoleSelector(role, options));
|
|
10
|
+
},
|
|
11
|
+
getByTestId(testId) {
|
|
12
|
+
return new WebdriverIOLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
13
|
+
},
|
|
14
|
+
getByAltText(text, options) {
|
|
15
|
+
return new WebdriverIOLocator(getByAltTextSelector(text, options));
|
|
16
|
+
},
|
|
17
|
+
getByPlaceholder(text, options) {
|
|
18
|
+
return new WebdriverIOLocator(getByPlaceholderSelector(text, options));
|
|
19
|
+
},
|
|
20
|
+
getByText(text, options) {
|
|
21
|
+
return new WebdriverIOLocator(getByTextSelector(text, options));
|
|
22
|
+
},
|
|
23
|
+
getByTitle(title, options) {
|
|
24
|
+
return new WebdriverIOLocator(getByTitleSelector(title, options));
|
|
25
|
+
},
|
|
26
|
+
elementLocator(element) {
|
|
27
|
+
return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
class WebdriverIOLocator extends Locator {
|
|
31
|
+
constructor(_pwSelector, _forceElement) {
|
|
32
|
+
super();
|
|
33
|
+
this._pwSelector = _pwSelector;
|
|
34
|
+
this._forceElement = _forceElement;
|
|
35
|
+
}
|
|
36
|
+
get selector() {
|
|
37
|
+
const selectors = this.elements().map((element) => convertElementToCssSelector(element));
|
|
38
|
+
if (!selectors.length) {
|
|
39
|
+
throw new Error(`element not found: ${this._pwSelector}`);
|
|
40
|
+
}
|
|
41
|
+
return selectors.join(", ");
|
|
42
|
+
}
|
|
43
|
+
selectOptions(value) {
|
|
44
|
+
const values = getWebdriverioSelectOptions(this.element(), value);
|
|
45
|
+
return this.triggerCommand("__vitest_selectOptions", this.selector, values);
|
|
46
|
+
}
|
|
47
|
+
locator(selector) {
|
|
48
|
+
return new WebdriverIOLocator(`${this._pwSelector} >> ${selector}`);
|
|
49
|
+
}
|
|
50
|
+
elementLocator(element) {
|
|
51
|
+
return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function getWebdriverioSelectOptions(element, value) {
|
|
55
|
+
const options = [...element.querySelectorAll("option")];
|
|
56
|
+
const arrayValues = Array.isArray(value) ? value : [value];
|
|
57
|
+
if (!arrayValues.length) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
if (arrayValues.length > 1) {
|
|
61
|
+
throw new Error(`Provider "webdriverio" doesn't support selecting multiple values at once`);
|
|
62
|
+
}
|
|
63
|
+
const optionValue = arrayValues[0];
|
|
64
|
+
if (typeof optionValue !== "string") {
|
|
65
|
+
const element2 = "element" in optionValue ? optionValue.element() : optionValue;
|
|
66
|
+
const index = options.indexOf(element2);
|
|
67
|
+
if (index === -1) {
|
|
68
|
+
throw new Error(`The element ${selectorEngine.previewNode(element2)} was not found in the "select" options.`);
|
|
69
|
+
}
|
|
70
|
+
return [{ index }];
|
|
71
|
+
}
|
|
72
|
+
const valueIndex = options.findIndex((option) => option.value === optionValue);
|
|
73
|
+
if (valueIndex !== -1) {
|
|
74
|
+
return [{ index: valueIndex }];
|
|
75
|
+
}
|
|
76
|
+
const labelIndex = options.findIndex(
|
|
77
|
+
(option) => option.textContent?.trim() === optionValue || option.ariaLabel === optionValue
|
|
78
|
+
);
|
|
79
|
+
if (labelIndex === -1) {
|
|
80
|
+
throw new Error(`The option "${optionValue}" was not found in the "select" options.`);
|
|
81
|
+
}
|
|
82
|
+
return [{ index: labelIndex }];
|
|
83
|
+
}
|
package/jest-dom.d.ts
CHANGED
|
@@ -1,102 +1,6 @@
|
|
|
1
1
|
// Disable automatic exports.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
type ARIAWidgetRole =
|
|
5
|
-
| "button"
|
|
6
|
-
| "checkbox"
|
|
7
|
-
| "gridcell"
|
|
8
|
-
| "link"
|
|
9
|
-
| "menuitem"
|
|
10
|
-
| "menuitemcheckbox"
|
|
11
|
-
| "menuitemradio"
|
|
12
|
-
| "option"
|
|
13
|
-
| "progressbar"
|
|
14
|
-
| "radio"
|
|
15
|
-
| "scrollbar"
|
|
16
|
-
| "searchbox"
|
|
17
|
-
| "slider"
|
|
18
|
-
| "spinbutton"
|
|
19
|
-
| "switch"
|
|
20
|
-
| "tab"
|
|
21
|
-
| "tabpanel"
|
|
22
|
-
| "textbox"
|
|
23
|
-
| "treeitem";
|
|
24
|
-
|
|
25
|
-
type ARIACompositeWidgetRole =
|
|
26
|
-
| "combobox"
|
|
27
|
-
| "grid"
|
|
28
|
-
| "listbox"
|
|
29
|
-
| "menu"
|
|
30
|
-
| "menubar"
|
|
31
|
-
| "radiogroup"
|
|
32
|
-
| "tablist"
|
|
33
|
-
| "tree"
|
|
34
|
-
| "treegrid";
|
|
35
|
-
|
|
36
|
-
type ARIADocumentStructureRole =
|
|
37
|
-
| "application"
|
|
38
|
-
| "article"
|
|
39
|
-
| "blockquote"
|
|
40
|
-
| "caption"
|
|
41
|
-
| "cell"
|
|
42
|
-
| "columnheader"
|
|
43
|
-
| "definition"
|
|
44
|
-
| "deletion"
|
|
45
|
-
| "directory"
|
|
46
|
-
| "document"
|
|
47
|
-
| "emphasis"
|
|
48
|
-
| "feed"
|
|
49
|
-
| "figure"
|
|
50
|
-
| "generic"
|
|
51
|
-
| "group"
|
|
52
|
-
| "heading"
|
|
53
|
-
| "img"
|
|
54
|
-
| "insertion"
|
|
55
|
-
| "list"
|
|
56
|
-
| "listitem"
|
|
57
|
-
| "math"
|
|
58
|
-
| "meter"
|
|
59
|
-
| "none"
|
|
60
|
-
| "note"
|
|
61
|
-
| "paragraph"
|
|
62
|
-
| "presentation"
|
|
63
|
-
| "row"
|
|
64
|
-
| "rowgroup"
|
|
65
|
-
| "rowheader"
|
|
66
|
-
| "separator"
|
|
67
|
-
| "strong"
|
|
68
|
-
| "subscript"
|
|
69
|
-
| "superscript"
|
|
70
|
-
| "table"
|
|
71
|
-
| "term"
|
|
72
|
-
| "time"
|
|
73
|
-
| "toolbar"
|
|
74
|
-
| "tooltip";
|
|
75
|
-
|
|
76
|
-
type ARIALandmarkRole =
|
|
77
|
-
| "banner"
|
|
78
|
-
| "complementary"
|
|
79
|
-
| "contentinfo"
|
|
80
|
-
| "form"
|
|
81
|
-
| "main"
|
|
82
|
-
| "navigation"
|
|
83
|
-
| "region"
|
|
84
|
-
| "search";
|
|
85
|
-
|
|
86
|
-
type ARIALiveRegionRole = "alert" | "log" | "marquee" | "status" | "timer";
|
|
87
|
-
|
|
88
|
-
type ARIAWindowRole = "alertdialog" | "dialog";
|
|
89
|
-
|
|
90
|
-
type ARIAUncategorizedRole = "code";
|
|
91
|
-
|
|
92
|
-
type ARIARole =
|
|
93
|
-
| ARIAWidgetRole
|
|
94
|
-
| ARIACompositeWidgetRole
|
|
95
|
-
| ARIADocumentStructureRole
|
|
96
|
-
| ARIALandmarkRole
|
|
97
|
-
| ARIALiveRegionRole
|
|
98
|
-
| ARIAWindowRole
|
|
99
|
-
| ARIAUncategorizedRole;
|
|
3
|
+
import { ARIARole } from './aria-role.ts'
|
|
100
4
|
|
|
101
5
|
declare namespace matchers {
|
|
102
6
|
interface TestingLibraryMatchers<E, R> {
|
package/matchers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Locator } from '@vitest/browser/context'
|
|
1
2
|
import type jsdomMatchers from './jest-dom.js'
|
|
2
3
|
import type { Assertion } from 'vitest'
|
|
3
4
|
|
|
@@ -15,7 +16,7 @@ declare module 'vitest' {
|
|
|
15
16
|
type PromisifyDomAssertion<T> = Promisify<Assertion<T>>
|
|
16
17
|
|
|
17
18
|
interface ExpectStatic {
|
|
18
|
-
element: <T extends Element>(element: T, options?: ExpectPollOptions) => PromisifyDomAssertion<Awaited<
|
|
19
|
+
element: <T extends Element | Locator>(element: T, options?: ExpectPollOptions) => PromisifyDomAssertion<Awaited<Element>>
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.1.0-beta.1",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"./providers/playwright": {
|
|
41
41
|
"types": "./providers/playwright.d.ts"
|
|
42
42
|
},
|
|
43
|
+
"./locator": {
|
|
44
|
+
"types": "./dist/locators/index.d.ts",
|
|
45
|
+
"default": "./dist/locators/index.js"
|
|
46
|
+
},
|
|
43
47
|
"./*": "./*"
|
|
44
48
|
},
|
|
45
49
|
"main": "./dist/index.js",
|
|
@@ -54,7 +58,7 @@
|
|
|
54
58
|
"peerDependencies": {
|
|
55
59
|
"playwright": "*",
|
|
56
60
|
"webdriverio": "*",
|
|
57
|
-
"vitest": "2.0.
|
|
61
|
+
"vitest": "2.1.0-beta.1"
|
|
58
62
|
},
|
|
59
63
|
"peerDependenciesMeta": {
|
|
60
64
|
"playwright": {
|
|
@@ -68,30 +72,31 @@
|
|
|
68
72
|
}
|
|
69
73
|
},
|
|
70
74
|
"dependencies": {
|
|
71
|
-
"@testing-library/dom": "^10.
|
|
75
|
+
"@testing-library/dom": "^10.4.0",
|
|
72
76
|
"@testing-library/user-event": "^14.5.2",
|
|
73
|
-
"magic-string": "^0.30.
|
|
74
|
-
"msw": "^2.3.
|
|
77
|
+
"magic-string": "^0.30.11",
|
|
78
|
+
"msw": "^2.3.5",
|
|
75
79
|
"sirv": "^2.0.4",
|
|
76
80
|
"ws": "^8.18.0",
|
|
77
|
-
"@vitest/utils": "2.0.
|
|
81
|
+
"@vitest/utils": "2.1.0-beta.1"
|
|
78
82
|
},
|
|
79
83
|
"devDependencies": {
|
|
80
|
-
"@testing-library/jest-dom": "^6.4.
|
|
81
|
-
"@types/ws": "^8.5.
|
|
84
|
+
"@testing-library/jest-dom": "^6.4.8",
|
|
85
|
+
"@types/ws": "^8.5.12",
|
|
82
86
|
"@wdio/protocols": "^8.38.0",
|
|
83
87
|
"birpc": "0.2.17",
|
|
84
88
|
"flatted": "^3.3.1",
|
|
89
|
+
"ivya": "^1.1.0",
|
|
85
90
|
"pathe": "^1.1.2",
|
|
86
91
|
"periscopic": "^4.0.2",
|
|
87
|
-
"playwright": "^1.45.
|
|
88
|
-
"playwright-core": "^1.45.
|
|
92
|
+
"playwright": "^1.45.3",
|
|
93
|
+
"playwright-core": "^1.45.3",
|
|
89
94
|
"safaridriver": "^0.1.2",
|
|
90
95
|
"webdriverio": "^8.39.1",
|
|
91
|
-
"@vitest/
|
|
92
|
-
"@vitest/
|
|
93
|
-
"@vitest/ws-client": "2.0.
|
|
94
|
-
"vitest": "2.0.
|
|
96
|
+
"@vitest/runner": "2.1.0-beta.1",
|
|
97
|
+
"@vitest/ui": "2.1.0-beta.1",
|
|
98
|
+
"@vitest/ws-client": "2.1.0-beta.1",
|
|
99
|
+
"vitest": "2.1.0-beta.1"
|
|
95
100
|
},
|
|
96
101
|
"scripts": {
|
|
97
102
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|
|
@@ -39,9 +39,10 @@ declare module '@vitest/browser/context' {
|
|
|
39
39
|
export interface UserEventHoverOptions extends PWHoverOptions {}
|
|
40
40
|
export interface UserEventClickOptions extends PWClickOptions {}
|
|
41
41
|
export interface UserEventDoubleClickOptions extends PWDoubleClickOptions {}
|
|
42
|
+
export interface UserEventTripleClickOptions extends PWClickOptions {}
|
|
42
43
|
export interface UserEventFillOptions extends PWFillOptions {}
|
|
43
44
|
export interface UserEventSelectOptions extends PWSelectOptions {}
|
|
44
|
-
export interface
|
|
45
|
+
export interface UserEventDragAndDropOptions extends PWDragAndDropOptions {}
|
|
45
46
|
|
|
46
47
|
export interface ScreenshotOptions extends PWScreenshotOptions {}
|
|
47
48
|
|