@vitest/browser 3.1.0-beta.1 → 3.1.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 +24 -1
- package/dist/client/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/index-B0KEk_KY.css +1 -0
- package/dist/client/__vitest__/assets/index-BLZJq7cG.js +52 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/tester-DiLSqOx4.js +3431 -0
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +109 -105
- package/dist/context.js +374 -390
- package/dist/expect-element.js +25 -0
- package/dist/index-DjDyxzt8.js +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +1991 -1887
- package/dist/locators/index.d.ts +64 -0
- package/dist/locators/index.js +1 -4
- package/dist/locators/playwright.js +1 -123
- package/dist/locators/preview.js +1 -85
- package/dist/locators/webdriverio.js +1 -157
- package/dist/providers.js +35 -37
- package/dist/public-utils-xf4CCUzp.js +6 -0
- package/dist/state.js +170 -1
- package/dist/utils.js +1 -3
- package/dist/webdriver-2iYWIzBv.js +403 -0
- package/jest-dom.d.ts +623 -712
- package/matchers.d.ts +4 -4
- package/package.json +14 -16
- package/dist/client/__vitest__/assets/index-Bne9c1R6.css +0 -1
- package/dist/client/__vitest__/assets/index-CsZqQx26.js +0 -52
- package/dist/client/__vitest_browser__/tester-lo_P6U-u.js +0 -15577
- package/dist/index-DrTP5i7N.js +0 -195
- package/dist/public-utils-J4vwTaki.js +0 -5561
- package/dist/utils-VCysLhWp.js +0 -115
- package/dist/webdriver-C5-VI7VH.js +0 -275
package/dist/index-DrTP5i7N.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { server, page } from '@vitest/browser/context';
|
|
2
|
-
import { I as Ivya, e as getByRoleSelector, c as getByAltTextSelector, f as getByLabelSelector, b as getByPlaceholderSelector, d as getByTestIdSelector, a as getByTextSelector, g as getByTitleSelector, h as getElementError } from './public-utils-J4vwTaki.js';
|
|
3
|
-
|
|
4
|
-
function ensureAwaited(promise) {
|
|
5
|
-
const test = (/* @__PURE__ */ getWorkerState()).current;
|
|
6
|
-
if (!test || test.type !== "test") {
|
|
7
|
-
return promise();
|
|
8
|
-
}
|
|
9
|
-
let awaited = false;
|
|
10
|
-
const sourceError = new Error("STACK_TRACE_ERROR");
|
|
11
|
-
test.onFinished ??= [];
|
|
12
|
-
test.onFinished.push(() => {
|
|
13
|
-
if (!awaited) {
|
|
14
|
-
const error = new Error(
|
|
15
|
-
`The call was not awaited. This method is asynchronous and must be awaited; otherwise, the call will not start to avoid unhandled rejections.`
|
|
16
|
-
);
|
|
17
|
-
error.stack = sourceError.stack?.replace(sourceError.message, error.message);
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
let promiseResult;
|
|
22
|
-
return {
|
|
23
|
-
then(onFulfilled, onRejected) {
|
|
24
|
-
awaited = true;
|
|
25
|
-
return (promiseResult ||= promise(sourceError)).then(onFulfilled, onRejected);
|
|
26
|
-
},
|
|
27
|
-
catch(onRejected) {
|
|
28
|
-
return (promiseResult ||= promise(sourceError)).catch(onRejected);
|
|
29
|
-
},
|
|
30
|
-
finally(onFinally) {
|
|
31
|
-
return (promiseResult ||= promise(sourceError)).finally(onFinally);
|
|
32
|
-
},
|
|
33
|
-
[Symbol.toStringTag]: "Promise"
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
// @__NO_SIDE_EFFECTS__
|
|
37
|
-
function getBrowserState() {
|
|
38
|
-
return window.__vitest_browser_runner__;
|
|
39
|
-
}
|
|
40
|
-
// @__NO_SIDE_EFFECTS__
|
|
41
|
-
function getWorkerState() {
|
|
42
|
-
const state = window.__vitest_worker__;
|
|
43
|
-
if (!state) {
|
|
44
|
-
throw new Error("Worker state is not found. This is an issue with Vitest. Please, open an issue.");
|
|
45
|
-
}
|
|
46
|
-
return state;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const selectorEngine = Ivya.create({
|
|
50
|
-
browser: ((name) => {
|
|
51
|
-
switch (name) {
|
|
52
|
-
case "edge":
|
|
53
|
-
case "chrome":
|
|
54
|
-
return "chromium";
|
|
55
|
-
case "safari":
|
|
56
|
-
return "webkit";
|
|
57
|
-
default:
|
|
58
|
-
return name;
|
|
59
|
-
}
|
|
60
|
-
})(server.config.browser.name),
|
|
61
|
-
testIdAttribute: server.config.browser.locators.testIdAttribute
|
|
62
|
-
});
|
|
63
|
-
class Locator {
|
|
64
|
-
_parsedSelector;
|
|
65
|
-
_container;
|
|
66
|
-
_pwSelector;
|
|
67
|
-
click(options = {}) {
|
|
68
|
-
return this.triggerCommand("__vitest_click", this.selector, options);
|
|
69
|
-
}
|
|
70
|
-
dblClick(options = {}) {
|
|
71
|
-
return this.triggerCommand("__vitest_dblClick", this.selector, options);
|
|
72
|
-
}
|
|
73
|
-
tripleClick(options = {}) {
|
|
74
|
-
return this.triggerCommand("__vitest_tripleClick", this.selector, options);
|
|
75
|
-
}
|
|
76
|
-
clear(options) {
|
|
77
|
-
return this.triggerCommand("__vitest_clear", this.selector, options);
|
|
78
|
-
}
|
|
79
|
-
hover(options) {
|
|
80
|
-
return this.triggerCommand("__vitest_hover", this.selector, options);
|
|
81
|
-
}
|
|
82
|
-
unhover(options) {
|
|
83
|
-
return this.triggerCommand("__vitest_hover", "html > body", options);
|
|
84
|
-
}
|
|
85
|
-
fill(text, options) {
|
|
86
|
-
return this.triggerCommand("__vitest_fill", this.selector, text, options);
|
|
87
|
-
}
|
|
88
|
-
async upload(files, options) {
|
|
89
|
-
const filesPromise = (Array.isArray(files) ? files : [files]).map(async (file) => {
|
|
90
|
-
if (typeof file === "string") {
|
|
91
|
-
return file;
|
|
92
|
-
}
|
|
93
|
-
const bas64String = await new Promise((resolve, reject) => {
|
|
94
|
-
const reader = new FileReader();
|
|
95
|
-
reader.onload = () => resolve(reader.result);
|
|
96
|
-
reader.onerror = () => reject(new Error(`Failed to read file: ${file.name}`));
|
|
97
|
-
reader.readAsDataURL(file);
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
name: file.name,
|
|
101
|
-
mimeType: file.type,
|
|
102
|
-
base64: bas64String
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
return this.triggerCommand("__vitest_upload", this.selector, await Promise.all(filesPromise), options);
|
|
106
|
-
}
|
|
107
|
-
dropTo(target, options = {}) {
|
|
108
|
-
return this.triggerCommand(
|
|
109
|
-
"__vitest_dragAndDrop",
|
|
110
|
-
this.selector,
|
|
111
|
-
target.selector,
|
|
112
|
-
options
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
selectOptions(value, options) {
|
|
116
|
-
const values = (Array.isArray(value) ? value : [value]).map((v) => {
|
|
117
|
-
if (typeof v !== "string") {
|
|
118
|
-
const selector = "element" in v ? v.selector : selectorEngine.generateSelectorSimple(v);
|
|
119
|
-
return { element: selector };
|
|
120
|
-
}
|
|
121
|
-
return v;
|
|
122
|
-
});
|
|
123
|
-
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
124
|
-
}
|
|
125
|
-
screenshot(options) {
|
|
126
|
-
return page.screenshot({
|
|
127
|
-
...options,
|
|
128
|
-
element: this
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
getByRole(role, options) {
|
|
132
|
-
return this.locator(getByRoleSelector(role, options));
|
|
133
|
-
}
|
|
134
|
-
getByAltText(text, options) {
|
|
135
|
-
return this.locator(getByAltTextSelector(text, options));
|
|
136
|
-
}
|
|
137
|
-
getByLabelText(text, options) {
|
|
138
|
-
return this.locator(getByLabelSelector(text, options));
|
|
139
|
-
}
|
|
140
|
-
getByPlaceholder(text, options) {
|
|
141
|
-
return this.locator(getByPlaceholderSelector(text, options));
|
|
142
|
-
}
|
|
143
|
-
getByTestId(testId) {
|
|
144
|
-
return this.locator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
145
|
-
}
|
|
146
|
-
getByText(text, options) {
|
|
147
|
-
return this.locator(getByTextSelector(text, options));
|
|
148
|
-
}
|
|
149
|
-
getByTitle(title, options) {
|
|
150
|
-
return this.locator(getByTitleSelector(title, options));
|
|
151
|
-
}
|
|
152
|
-
query() {
|
|
153
|
-
const parsedSelector = this._parsedSelector || (this._parsedSelector = selectorEngine.parseSelector(this._pwSelector || this.selector));
|
|
154
|
-
return selectorEngine.querySelector(parsedSelector, document.documentElement, true);
|
|
155
|
-
}
|
|
156
|
-
element() {
|
|
157
|
-
const element = this.query();
|
|
158
|
-
if (!element) {
|
|
159
|
-
throw getElementError(this._pwSelector || this.selector, this._container || document.body);
|
|
160
|
-
}
|
|
161
|
-
return element;
|
|
162
|
-
}
|
|
163
|
-
elements() {
|
|
164
|
-
const parsedSelector = this._parsedSelector || (this._parsedSelector = selectorEngine.parseSelector(this._pwSelector || this.selector));
|
|
165
|
-
return selectorEngine.querySelectorAll(parsedSelector, document.documentElement);
|
|
166
|
-
}
|
|
167
|
-
all() {
|
|
168
|
-
return this.elements().map((element) => this.elementLocator(element));
|
|
169
|
-
}
|
|
170
|
-
nth(index) {
|
|
171
|
-
return this.locator(`nth=${index}`);
|
|
172
|
-
}
|
|
173
|
-
first() {
|
|
174
|
-
return this.nth(0);
|
|
175
|
-
}
|
|
176
|
-
last() {
|
|
177
|
-
return this.nth(-1);
|
|
178
|
-
}
|
|
179
|
-
toString() {
|
|
180
|
-
return this.selector;
|
|
181
|
-
}
|
|
182
|
-
toJSON() {
|
|
183
|
-
return this.selector;
|
|
184
|
-
}
|
|
185
|
-
triggerCommand(command, ...args) {
|
|
186
|
-
const commands = getBrowserState().commands;
|
|
187
|
-
return ensureAwaited((error) => commands.triggerCommand(
|
|
188
|
-
command,
|
|
189
|
-
args,
|
|
190
|
-
error
|
|
191
|
-
));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export { Locator as L, getWorkerState as a, getBrowserState as g, selectorEngine as s };
|