@vitest/browser 3.1.0-beta.2 → 3.1.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/context.d.ts +2 -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 +18 -0
- package/dist/context.js +5 -5
- 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 +83 -8
- package/dist/locators/index.d.ts +61 -0
- package/dist/locators/index.js +1 -4
- package/dist/locators/playwright.js +1 -114
- package/dist/locators/preview.js +1 -78
- package/dist/locators/webdriverio.js +1 -154
- package/dist/providers.js +2 -1
- package/dist/public-utils-xf4CCUzp.js +6 -0
- package/dist/utils.js +1 -3
- package/dist/{webdriver-BP2w_ajA.js → webdriver-2iYWIzBv.js} +135 -3
- 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-C3wX9Cb1.js +0 -52
- package/dist/client/__vitest_browser__/tester-DRF-LncV.js +0 -16365
- package/dist/index-VvsEiykv.js +0 -327
- package/dist/public-utils-4WiYB3_6.js +0 -5559
package/dist/index-VvsEiykv.js
DELETED
|
@@ -1,327 +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-4WiYB3_6.js';
|
|
3
|
-
|
|
4
|
-
function ensureAwaited(promise) {
|
|
5
|
-
const test = 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(`The call was not awaited. This method is asynchronous and must be awaited; otherwise, the call will not start to avoid unhandled rejections.`);
|
|
15
|
-
error.stack = sourceError.stack?.replace(sourceError.message, error.message);
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
let promiseResult;
|
|
20
|
-
return {
|
|
21
|
-
then(onFulfilled, onRejected) {
|
|
22
|
-
awaited = true;
|
|
23
|
-
return (promiseResult ||= promise(sourceError)).then(onFulfilled, onRejected);
|
|
24
|
-
},
|
|
25
|
-
catch(onRejected) {
|
|
26
|
-
return (promiseResult ||= promise(sourceError)).catch(onRejected);
|
|
27
|
-
},
|
|
28
|
-
finally(onFinally) {
|
|
29
|
-
return (promiseResult ||= promise(sourceError)).finally(onFinally);
|
|
30
|
-
},
|
|
31
|
-
[Symbol.toStringTag]: "Promise"
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
35
|
-
function getBrowserState() {
|
|
36
|
-
return window.__vitest_browser_runner__;
|
|
37
|
-
}
|
|
38
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
39
|
-
function getWorkerState() {
|
|
40
|
-
const state = window.__vitest_worker__;
|
|
41
|
-
if (!state) {
|
|
42
|
-
throw new Error("Worker state is not found. This is an issue with Vitest. Please, open an issue.");
|
|
43
|
-
}
|
|
44
|
-
return state;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const provider = getBrowserState().provider;
|
|
48
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
49
|
-
function convertElementToCssSelector(element) {
|
|
50
|
-
if (!element || !(element instanceof Element)) {
|
|
51
|
-
throw new Error(`Expected DOM element to be an instance of Element, received ${typeof element}`);
|
|
52
|
-
}
|
|
53
|
-
return getUniqueCssSelector(element);
|
|
54
|
-
}
|
|
55
|
-
function escapeIdForCSSSelector(id) {
|
|
56
|
-
return id.split("").map((char) => {
|
|
57
|
-
const code = char.charCodeAt(0);
|
|
58
|
-
if (char === " " || char === "#" || char === "." || char === ":" || char === "[" || char === "]" || char === ">" || char === "+" || char === "~" || char === "\\") {
|
|
59
|
-
return `\\${char}`;
|
|
60
|
-
} else if (code >= 65536) {
|
|
61
|
-
return `\\${code.toString(16).toUpperCase().padStart(6, "0")} `;
|
|
62
|
-
} else if (code < 32 || code === 127) {
|
|
63
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
64
|
-
} else if (code >= 128) {
|
|
65
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
66
|
-
} else {
|
|
67
|
-
return char;
|
|
68
|
-
}
|
|
69
|
-
}).join("");
|
|
70
|
-
}
|
|
71
|
-
function getUniqueCssSelector(el) {
|
|
72
|
-
const path = [];
|
|
73
|
-
let parent;
|
|
74
|
-
let hasShadowRoot = false;
|
|
75
|
-
while (parent = getParent(el)) {
|
|
76
|
-
if (parent.shadowRoot) {
|
|
77
|
-
hasShadowRoot = true;
|
|
78
|
-
}
|
|
79
|
-
const tag = el.tagName;
|
|
80
|
-
if (el.id) {
|
|
81
|
-
path.push(`#${escapeIdForCSSSelector(el.id)}`);
|
|
82
|
-
} else if (!el.nextElementSibling && !el.previousElementSibling) {
|
|
83
|
-
path.push(tag.toLowerCase());
|
|
84
|
-
} else {
|
|
85
|
-
let index = 0;
|
|
86
|
-
let sameTagSiblings = 0;
|
|
87
|
-
let elementIndex = 0;
|
|
88
|
-
for (const sibling of parent.children) {
|
|
89
|
-
index++;
|
|
90
|
-
if (sibling.tagName === tag) {
|
|
91
|
-
sameTagSiblings++;
|
|
92
|
-
}
|
|
93
|
-
if (sibling === el) {
|
|
94
|
-
elementIndex = index;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (sameTagSiblings > 1) {
|
|
98
|
-
path.push(`${tag.toLowerCase()}:nth-child(${elementIndex})`);
|
|
99
|
-
} else {
|
|
100
|
-
path.push(tag.toLowerCase());
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
el = parent;
|
|
104
|
-
}
|
|
105
|
-
return `${getBrowserState().provider === "webdriverio" && hasShadowRoot ? ">>>" : ""}${path.reverse().join(" > ")}`;
|
|
106
|
-
}
|
|
107
|
-
function getParent(el) {
|
|
108
|
-
const parent = el.parentNode;
|
|
109
|
-
if (parent instanceof ShadowRoot) {
|
|
110
|
-
return parent.host;
|
|
111
|
-
}
|
|
112
|
-
return parent;
|
|
113
|
-
}
|
|
114
|
-
const now = Date.now;
|
|
115
|
-
function processTimeoutOptions(options_) {
|
|
116
|
-
if (options_ && options_.timeout != null || provider !== "playwright") {
|
|
117
|
-
return options_;
|
|
118
|
-
}
|
|
119
|
-
if (getWorkerState().config.browser.providerOptions.actionTimeout != null) {
|
|
120
|
-
return options_;
|
|
121
|
-
}
|
|
122
|
-
const currentTest = getWorkerState().current;
|
|
123
|
-
const startTime = currentTest?.result?.startTime;
|
|
124
|
-
if (!currentTest || currentTest.type === "suite" || !startTime) {
|
|
125
|
-
return options_;
|
|
126
|
-
}
|
|
127
|
-
const timeout = currentTest.timeout;
|
|
128
|
-
if (timeout === 0 || timeout === Number.POSITIVE_INFINITY) {
|
|
129
|
-
return options_;
|
|
130
|
-
}
|
|
131
|
-
options_ = options_ || {};
|
|
132
|
-
const currentTime = now();
|
|
133
|
-
const endTime = startTime + timeout;
|
|
134
|
-
const remainingTime = endTime - currentTime;
|
|
135
|
-
if (remainingTime <= 0) {
|
|
136
|
-
return options_;
|
|
137
|
-
}
|
|
138
|
-
options_.timeout = remainingTime - 100;
|
|
139
|
-
return options_;
|
|
140
|
-
}
|
|
141
|
-
function getIframeScale() {
|
|
142
|
-
const testerUi = window.parent.document.querySelector("#tester-ui");
|
|
143
|
-
if (!testerUi) {
|
|
144
|
-
throw new Error(`Cannot find Tester element. This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
145
|
-
}
|
|
146
|
-
const scaleAttribute = testerUi.getAttribute("data-scale");
|
|
147
|
-
const scale = Number(scaleAttribute);
|
|
148
|
-
if (Number.isNaN(scale)) {
|
|
149
|
-
throw new TypeError(`Cannot parse scale value from Tester element (${scaleAttribute}). This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
150
|
-
}
|
|
151
|
-
return scale;
|
|
152
|
-
}
|
|
153
|
-
function escapeRegexForSelector(re) {
|
|
154
|
-
if (re.unicode || re.unicodeSets) {
|
|
155
|
-
return String(re);
|
|
156
|
-
}
|
|
157
|
-
return String(re).replace(/(^|[^\\])(\\\\)*(["'`])/g, "$1$2\\$3").replace(/>>/g, "\\>\\>");
|
|
158
|
-
}
|
|
159
|
-
function escapeForTextSelector(text, exact) {
|
|
160
|
-
if (typeof text !== "string") {
|
|
161
|
-
return escapeRegexForSelector(text);
|
|
162
|
-
}
|
|
163
|
-
return `${JSON.stringify(text)}${"i"}`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const selectorEngine = Ivya.create({
|
|
167
|
-
browser: ((name) => {
|
|
168
|
-
switch (name) {
|
|
169
|
-
case "edge":
|
|
170
|
-
case "chrome": return "chromium";
|
|
171
|
-
case "safari": return "webkit";
|
|
172
|
-
default: return name;
|
|
173
|
-
}
|
|
174
|
-
})(server.config.browser.name),
|
|
175
|
-
testIdAttribute: server.config.browser.locators.testIdAttribute
|
|
176
|
-
});
|
|
177
|
-
class Locator {
|
|
178
|
-
_parsedSelector;
|
|
179
|
-
_container;
|
|
180
|
-
_pwSelector;
|
|
181
|
-
click(options = {}) {
|
|
182
|
-
return this.triggerCommand("__vitest_click", this.selector, options);
|
|
183
|
-
}
|
|
184
|
-
dblClick(options = {}) {
|
|
185
|
-
return this.triggerCommand("__vitest_dblClick", this.selector, options);
|
|
186
|
-
}
|
|
187
|
-
tripleClick(options = {}) {
|
|
188
|
-
return this.triggerCommand("__vitest_tripleClick", this.selector, options);
|
|
189
|
-
}
|
|
190
|
-
clear(options) {
|
|
191
|
-
return this.triggerCommand("__vitest_clear", this.selector, options);
|
|
192
|
-
}
|
|
193
|
-
hover(options) {
|
|
194
|
-
return this.triggerCommand("__vitest_hover", this.selector, options);
|
|
195
|
-
}
|
|
196
|
-
unhover(options) {
|
|
197
|
-
return this.triggerCommand("__vitest_hover", "html > body", options);
|
|
198
|
-
}
|
|
199
|
-
fill(text, options) {
|
|
200
|
-
return this.triggerCommand("__vitest_fill", this.selector, text, options);
|
|
201
|
-
}
|
|
202
|
-
async upload(files, options) {
|
|
203
|
-
const filesPromise = (Array.isArray(files) ? files : [files]).map(async (file) => {
|
|
204
|
-
if (typeof file === "string") {
|
|
205
|
-
return file;
|
|
206
|
-
}
|
|
207
|
-
const bas64String = await new Promise((resolve, reject) => {
|
|
208
|
-
const reader = new FileReader();
|
|
209
|
-
reader.onload = () => resolve(reader.result);
|
|
210
|
-
reader.onerror = () => reject(new Error(`Failed to read file: ${file.name}`));
|
|
211
|
-
reader.readAsDataURL(file);
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
name: file.name,
|
|
215
|
-
mimeType: file.type,
|
|
216
|
-
base64: bas64String
|
|
217
|
-
};
|
|
218
|
-
});
|
|
219
|
-
return this.triggerCommand("__vitest_upload", this.selector, await Promise.all(filesPromise), options);
|
|
220
|
-
}
|
|
221
|
-
dropTo(target, options = {}) {
|
|
222
|
-
return this.triggerCommand("__vitest_dragAndDrop", this.selector, target.selector, options);
|
|
223
|
-
}
|
|
224
|
-
selectOptions(value, options) {
|
|
225
|
-
const values = (Array.isArray(value) ? value : [value]).map((v) => {
|
|
226
|
-
if (typeof v !== "string") {
|
|
227
|
-
const selector = "element" in v ? v.selector : selectorEngine.generateSelectorSimple(v);
|
|
228
|
-
return { element: selector };
|
|
229
|
-
}
|
|
230
|
-
return v;
|
|
231
|
-
});
|
|
232
|
-
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
233
|
-
}
|
|
234
|
-
screenshot(options) {
|
|
235
|
-
return page.screenshot({
|
|
236
|
-
...options,
|
|
237
|
-
element: this
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
getByRole(role, options) {
|
|
241
|
-
return this.locator(getByRoleSelector(role, options));
|
|
242
|
-
}
|
|
243
|
-
getByAltText(text, options) {
|
|
244
|
-
return this.locator(getByAltTextSelector(text, options));
|
|
245
|
-
}
|
|
246
|
-
getByLabelText(text, options) {
|
|
247
|
-
return this.locator(getByLabelSelector(text, options));
|
|
248
|
-
}
|
|
249
|
-
getByPlaceholder(text, options) {
|
|
250
|
-
return this.locator(getByPlaceholderSelector(text, options));
|
|
251
|
-
}
|
|
252
|
-
getByTestId(testId) {
|
|
253
|
-
return this.locator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
254
|
-
}
|
|
255
|
-
getByText(text, options) {
|
|
256
|
-
return this.locator(getByTextSelector(text, options));
|
|
257
|
-
}
|
|
258
|
-
getByTitle(title, options) {
|
|
259
|
-
return this.locator(getByTitleSelector(title, options));
|
|
260
|
-
}
|
|
261
|
-
filter(filter) {
|
|
262
|
-
const selectors = [];
|
|
263
|
-
if (filter?.hasText) {
|
|
264
|
-
selectors.push(`internal:has-text=${escapeForTextSelector(filter.hasText)}`);
|
|
265
|
-
}
|
|
266
|
-
if (filter?.hasNotText) {
|
|
267
|
-
selectors.push(`internal:has-not-text=${escapeForTextSelector(filter.hasNotText)}`);
|
|
268
|
-
}
|
|
269
|
-
if (filter?.has) {
|
|
270
|
-
const locator = filter.has;
|
|
271
|
-
selectors.push(`internal:has=${JSON.stringify(locator._pwSelector || locator.selector)}`);
|
|
272
|
-
}
|
|
273
|
-
if (filter?.hasNot) {
|
|
274
|
-
const locator = filter.hasNot;
|
|
275
|
-
selectors.push(`internal:has-not=${JSON.stringify(locator._pwSelector || locator.selector)}`);
|
|
276
|
-
}
|
|
277
|
-
if (!selectors.length) {
|
|
278
|
-
throw new Error(`Locator.filter expects at least one filter. None provided.`);
|
|
279
|
-
}
|
|
280
|
-
return this.locator(selectors.join(" >> "));
|
|
281
|
-
}
|
|
282
|
-
and(locator) {
|
|
283
|
-
return this.locator(`internal:and=${JSON.stringify(locator._pwSelector || locator.selector)}`);
|
|
284
|
-
}
|
|
285
|
-
or(locator) {
|
|
286
|
-
return this.locator(`internal:or=${JSON.stringify(locator._pwSelector || locator.selector)}`);
|
|
287
|
-
}
|
|
288
|
-
query() {
|
|
289
|
-
const parsedSelector = this._parsedSelector || (this._parsedSelector = selectorEngine.parseSelector(this._pwSelector || this.selector));
|
|
290
|
-
return selectorEngine.querySelector(parsedSelector, document.documentElement, true);
|
|
291
|
-
}
|
|
292
|
-
element() {
|
|
293
|
-
const element = this.query();
|
|
294
|
-
if (!element) {
|
|
295
|
-
throw getElementError(this._pwSelector || this.selector, this._container || document.body);
|
|
296
|
-
}
|
|
297
|
-
return element;
|
|
298
|
-
}
|
|
299
|
-
elements() {
|
|
300
|
-
const parsedSelector = this._parsedSelector || (this._parsedSelector = selectorEngine.parseSelector(this._pwSelector || this.selector));
|
|
301
|
-
return selectorEngine.querySelectorAll(parsedSelector, document.documentElement);
|
|
302
|
-
}
|
|
303
|
-
all() {
|
|
304
|
-
return this.elements().map((element) => this.elementLocator(element));
|
|
305
|
-
}
|
|
306
|
-
nth(index) {
|
|
307
|
-
return this.locator(`nth=${index}`);
|
|
308
|
-
}
|
|
309
|
-
first() {
|
|
310
|
-
return this.nth(0);
|
|
311
|
-
}
|
|
312
|
-
last() {
|
|
313
|
-
return this.nth(-1);
|
|
314
|
-
}
|
|
315
|
-
toString() {
|
|
316
|
-
return this.selector;
|
|
317
|
-
}
|
|
318
|
-
toJSON() {
|
|
319
|
-
return this.selector;
|
|
320
|
-
}
|
|
321
|
-
triggerCommand(command, ...args) {
|
|
322
|
-
const commands = getBrowserState().commands;
|
|
323
|
-
return ensureAwaited((error) => commands.triggerCommand(command, args, error));
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
export { Locator as L, getIframeScale as a, convertElementToCssSelector as c, getBrowserState as g, processTimeoutOptions as p, selectorEngine as s };
|