@vitest/browser 3.0.8 → 3.0.9
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 +6 -4
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/{index-CV9H8iCm.css → index-Bne9c1R6.css} +1 -1
- package/dist/client/__vitest__/assets/{index-BAYvVM30.js → index-CsZqQx26.js} +5 -5
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-C0dFtnHa.js → orchestrator-CqPXjvQE.js} +1 -1
- package/dist/client/__vitest_browser__/{tester-CHxkAhrF.js → tester-lo_P6U-u.js} +60 -2
- package/dist/client/__vitest_browser__/{utils-CBFLDkwI.js → utils-CNTxSNQV.js} +2 -25
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/context.js +82 -153
- package/dist/{index-fqTesRIH.js → index-DrTP5i7N.js} +13 -80
- package/dist/index.d.ts +103 -103
- package/dist/index.js +7 -6
- package/dist/locators/index.d.ts +41 -41
- package/dist/locators/index.js +1 -1
- package/dist/locators/playwright.js +74 -1
- package/dist/locators/preview.js +2 -1
- package/dist/locators/webdriverio.js +75 -3
- package/dist/utils-VCysLhWp.js +115 -0
- package/matchers.d.ts +2 -1
- package/package.json +9 -8
- package/providers/playwright.d.ts +2 -0
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
})();
|
|
24
24
|
</script>
|
|
25
25
|
<!-- !LOAD_METADATA! -->
|
|
26
|
-
<script type="module" src="./assets/index-
|
|
27
|
-
<link rel="stylesheet" href="./assets/index-
|
|
26
|
+
<script type="module" src="./assets/index-CsZqQx26.js"></script>
|
|
27
|
+
<link rel="stylesheet" href="./assets/index-Bne9c1R6.css">
|
|
28
28
|
</head>
|
|
29
29
|
<body>
|
|
30
30
|
<div id="app"></div>
|
package/dist/client/__vitest_browser__/{orchestrator-C0dFtnHa.js → orchestrator-CqPXjvQE.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { g as getBrowserState, a as getConfig, r as relative } from "./utils-
|
|
4
|
+
import { g as getBrowserState, a as getConfig, r as relative } from "./utils-CNTxSNQV.js";
|
|
5
5
|
import { client, channel, globalChannel } from "@vitest/browser/client";
|
|
6
6
|
function generateHash(str) {
|
|
7
7
|
let hash = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import {
|
|
4
|
+
import { b as getWorkerState, g as getBrowserState, a as getConfig, c as resolve, e as executor } from "./utils-CNTxSNQV.js";
|
|
5
5
|
import { globalChannel, client, onCancel, channel } from "@vitest/browser/client";
|
|
6
6
|
import { userEvent, page, server } from "@vitest/browser/context";
|
|
7
7
|
import { loadDiffConfig, loadSnapshotSerializers, takeCoverageInsideWorker, setupCommonEnv, startCoverageInsideWorker, startTests, collectTests, stopCoverageInsideWorker, SpyModule } from "vitest/browser";
|
|
@@ -12891,6 +12891,64 @@ const matchers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
12891
12891
|
toHaveTextContent,
|
|
12892
12892
|
toHaveValue
|
|
12893
12893
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
12894
|
+
const provider = getBrowserState().provider;
|
|
12895
|
+
class CommandsManager {
|
|
12896
|
+
constructor() {
|
|
12897
|
+
__publicField(this, "_listeners", []);
|
|
12898
|
+
}
|
|
12899
|
+
onCommand(listener) {
|
|
12900
|
+
this._listeners.push(listener);
|
|
12901
|
+
}
|
|
12902
|
+
async triggerCommand(command, args, clientError = new Error("empty")) {
|
|
12903
|
+
var _a, _b;
|
|
12904
|
+
const state = getWorkerState();
|
|
12905
|
+
const rpc2 = state.rpc;
|
|
12906
|
+
const { sessionId } = getBrowserState();
|
|
12907
|
+
const filepath = state.filepath || ((_b = (_a = state.current) == null ? void 0 : _a.file) == null ? void 0 : _b.filepath);
|
|
12908
|
+
args = args.filter((arg) => arg !== void 0);
|
|
12909
|
+
if (this._listeners.length) {
|
|
12910
|
+
await Promise.all(this._listeners.map((listener) => listener(command, args)));
|
|
12911
|
+
}
|
|
12912
|
+
return rpc2.triggerCommand(sessionId, command, filepath, args).catch((err) => {
|
|
12913
|
+
var _a2;
|
|
12914
|
+
clientError.message = err.message;
|
|
12915
|
+
clientError.name = err.name;
|
|
12916
|
+
clientError.stack = (_a2 = clientError.stack) == null ? void 0 : _a2.replace(clientError.message, err.message);
|
|
12917
|
+
throw clientError;
|
|
12918
|
+
});
|
|
12919
|
+
}
|
|
12920
|
+
}
|
|
12921
|
+
const now$1 = Date.now;
|
|
12922
|
+
function processTimeoutOptions(options_) {
|
|
12923
|
+
var _a;
|
|
12924
|
+
if (
|
|
12925
|
+
// if timeout is set, keep it
|
|
12926
|
+
options_ && options_.timeout != null || provider !== "playwright"
|
|
12927
|
+
) {
|
|
12928
|
+
return options_;
|
|
12929
|
+
}
|
|
12930
|
+
if (getWorkerState().config.browser.providerOptions.actionTimeout != null) {
|
|
12931
|
+
return options_;
|
|
12932
|
+
}
|
|
12933
|
+
const currentTest = getWorkerState().current;
|
|
12934
|
+
const startTime = (_a = currentTest == null ? void 0 : currentTest.result) == null ? void 0 : _a.startTime;
|
|
12935
|
+
if (!currentTest || currentTest.type === "suite" || !startTime) {
|
|
12936
|
+
return options_;
|
|
12937
|
+
}
|
|
12938
|
+
const timeout = currentTest.timeout;
|
|
12939
|
+
if (timeout === 0 || timeout === Number.POSITIVE_INFINITY) {
|
|
12940
|
+
return options_;
|
|
12941
|
+
}
|
|
12942
|
+
options_ = options_ || {};
|
|
12943
|
+
const currentTime = now$1();
|
|
12944
|
+
const endTime = startTime + timeout;
|
|
12945
|
+
const remainingTime = endTime - currentTime;
|
|
12946
|
+
if (remainingTime <= 0) {
|
|
12947
|
+
return options_;
|
|
12948
|
+
}
|
|
12949
|
+
options_.timeout = remainingTime - 100;
|
|
12950
|
+
return options_;
|
|
12951
|
+
}
|
|
12894
12952
|
async function setupExpectDom() {
|
|
12895
12953
|
expect.extend(matchers);
|
|
12896
12954
|
expect.element = (elementOrLocator, options) => {
|
|
@@ -12916,7 +12974,7 @@ async function setupExpectDom() {
|
|
|
12916
12974
|
throw new Error(`Cannot find element with locator: ${JSON.stringify(elementOrLocator)}`);
|
|
12917
12975
|
}
|
|
12918
12976
|
return result;
|
|
12919
|
-
}, options);
|
|
12977
|
+
}, processTimeoutOptions(options));
|
|
12920
12978
|
};
|
|
12921
12979
|
}
|
|
12922
12980
|
const { get } = Reflect;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
1
|
(function polyfill() {
|
|
5
2
|
const relList = document.createElement("link").relList;
|
|
6
3
|
if (relList && relList.supports && relList.supports("modulepreload")) {
|
|
@@ -188,30 +185,10 @@ function getWorkerState() {
|
|
|
188
185
|
}
|
|
189
186
|
return state;
|
|
190
187
|
}
|
|
191
|
-
class CommandsManager {
|
|
192
|
-
constructor() {
|
|
193
|
-
__publicField(this, "_listeners", []);
|
|
194
|
-
}
|
|
195
|
-
onCommand(listener) {
|
|
196
|
-
this._listeners.push(listener);
|
|
197
|
-
}
|
|
198
|
-
async triggerCommand(command, args) {
|
|
199
|
-
var _a, _b;
|
|
200
|
-
const state = /* @__PURE__ */ getWorkerState();
|
|
201
|
-
const rpc = state.rpc;
|
|
202
|
-
const { sessionId } = /* @__PURE__ */ getBrowserState();
|
|
203
|
-
const filepath = state.filepath || ((_b = (_a = state.current) == null ? void 0 : _a.file) == null ? void 0 : _b.filepath);
|
|
204
|
-
if (this._listeners.length) {
|
|
205
|
-
await Promise.all(this._listeners.map((listener) => listener(command, args)));
|
|
206
|
-
}
|
|
207
|
-
return rpc.triggerCommand(sessionId, command, filepath, args);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
188
|
export {
|
|
211
|
-
CommandsManager as C,
|
|
212
189
|
getConfig as a,
|
|
213
|
-
|
|
214
|
-
|
|
190
|
+
getWorkerState as b,
|
|
191
|
+
resolve as c,
|
|
215
192
|
executor as e,
|
|
216
193
|
getBrowserState as g,
|
|
217
194
|
relative as r
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
{__VITEST_INJECTOR__}
|
|
27
27
|
{__VITEST_ERROR_CATCHER__}
|
|
28
28
|
{__VITEST_SCRIPTS__}
|
|
29
|
-
<script type="module" crossorigin src="/__vitest_browser__/orchestrator-
|
|
30
|
-
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-
|
|
29
|
+
<script type="module" crossorigin src="/__vitest_browser__/orchestrator-CqPXjvQE.js"></script>
|
|
30
|
+
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-CNTxSNQV.js">
|
|
31
31
|
</head>
|
|
32
32
|
<body>
|
|
33
33
|
<div id="vitest-tester"></div>
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<link rel="icon" href="{__VITEST_FAVICON__}" type="image/svg+xml">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Vitest Browser Tester</title>
|
|
8
|
-
<script type="module" crossorigin src="/__vitest_browser__/tester-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-
|
|
8
|
+
<script type="module" crossorigin src="/__vitest_browser__/tester-lo_P6U-u.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-CNTxSNQV.js">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
</body>
|
package/dist/context.js
CHANGED
|
@@ -19,13 +19,13 @@ function ensureAwaited(promise) {
|
|
|
19
19
|
return {
|
|
20
20
|
then(onFulfilled, onRejected) {
|
|
21
21
|
awaited = true;
|
|
22
|
-
return (promiseResult ||= promise()).then(onFulfilled, onRejected);
|
|
22
|
+
return (promiseResult ||= promise(sourceError)).then(onFulfilled, onRejected);
|
|
23
23
|
},
|
|
24
24
|
catch(onRejected) {
|
|
25
|
-
return (promiseResult ||= promise()).catch(onRejected);
|
|
25
|
+
return (promiseResult ||= promise(sourceError)).catch(onRejected);
|
|
26
26
|
},
|
|
27
27
|
finally(onFinally) {
|
|
28
|
-
return (promiseResult ||= promise()).finally(onFinally);
|
|
28
|
+
return (promiseResult ||= promise(sourceError)).finally(onFinally);
|
|
29
29
|
},
|
|
30
30
|
[Symbol.toStringTag]: "Promise"
|
|
31
31
|
};
|
|
@@ -42,6 +42,8 @@ function getWorkerState() {
|
|
|
42
42
|
}
|
|
43
43
|
return state;
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
const provider$1 = getBrowserState().provider;
|
|
45
47
|
// @__NO_SIDE_EFFECTS__
|
|
46
48
|
function convertElementToCssSelector(element) {
|
|
47
49
|
if (!element || !(element instanceof Element)) {
|
|
@@ -101,7 +103,7 @@ function getUniqueCssSelector(el) {
|
|
|
101
103
|
}
|
|
102
104
|
el = parent;
|
|
103
105
|
}
|
|
104
|
-
return `${
|
|
106
|
+
return `${getBrowserState().provider === "webdriverio" && hasShadowRoot ? ">>>" : ""}${path.reverse().join(" > ")}`;
|
|
105
107
|
}
|
|
106
108
|
function getParent(el) {
|
|
107
109
|
const parent = el.parentNode;
|
|
@@ -110,13 +112,42 @@ function getParent(el) {
|
|
|
110
112
|
}
|
|
111
113
|
return parent;
|
|
112
114
|
}
|
|
115
|
+
const now = Date.now;
|
|
116
|
+
function processTimeoutOptions(options_) {
|
|
117
|
+
if (
|
|
118
|
+
// if timeout is set, keep it
|
|
119
|
+
options_ && options_.timeout != null || provider$1 !== "playwright"
|
|
120
|
+
) {
|
|
121
|
+
return options_;
|
|
122
|
+
}
|
|
123
|
+
if (getWorkerState().config.browser.providerOptions.actionTimeout != null) {
|
|
124
|
+
return options_;
|
|
125
|
+
}
|
|
126
|
+
const currentTest = getWorkerState().current;
|
|
127
|
+
const startTime = currentTest?.result?.startTime;
|
|
128
|
+
if (!currentTest || currentTest.type === "suite" || !startTime) {
|
|
129
|
+
return options_;
|
|
130
|
+
}
|
|
131
|
+
const timeout = currentTest.timeout;
|
|
132
|
+
if (timeout === 0 || timeout === Number.POSITIVE_INFINITY) {
|
|
133
|
+
return options_;
|
|
134
|
+
}
|
|
135
|
+
options_ = options_ || {};
|
|
136
|
+
const currentTime = now();
|
|
137
|
+
const endTime = startTime + timeout;
|
|
138
|
+
const remainingTime = endTime - currentTime;
|
|
139
|
+
if (remainingTime <= 0) {
|
|
140
|
+
return options_;
|
|
141
|
+
}
|
|
142
|
+
options_.timeout = remainingTime - 100;
|
|
143
|
+
return options_;
|
|
144
|
+
}
|
|
113
145
|
|
|
114
|
-
const state = () => getWorkerState();
|
|
115
146
|
const provider = __vitest_browser_runner__.provider;
|
|
116
147
|
const sessionId = getBrowserState().sessionId;
|
|
117
148
|
const channel = new BroadcastChannel(`vitest:${sessionId}`);
|
|
118
|
-
function triggerCommand(command,
|
|
119
|
-
return getBrowserState().commands.triggerCommand(command, args);
|
|
149
|
+
function triggerCommand(command, args, error) {
|
|
150
|
+
return getBrowserState().commands.triggerCommand(command, args, error);
|
|
120
151
|
}
|
|
121
152
|
function createUserEvent(__tl_user_event_base__, options) {
|
|
122
153
|
if (__tl_user_event_base__) {
|
|
@@ -134,66 +165,69 @@ function createUserEvent(__tl_user_event_base__, options) {
|
|
|
134
165
|
if (!keyboard.unreleased.length) {
|
|
135
166
|
return;
|
|
136
167
|
}
|
|
137
|
-
return ensureAwaited(async () => {
|
|
138
|
-
await triggerCommand("__vitest_cleanup", keyboard);
|
|
168
|
+
return ensureAwaited(async (error) => {
|
|
169
|
+
await triggerCommand("__vitest_cleanup", [keyboard], error);
|
|
139
170
|
keyboard.unreleased = [];
|
|
140
171
|
});
|
|
141
172
|
},
|
|
142
|
-
click(element, options2
|
|
143
|
-
return convertToLocator(element).click(
|
|
173
|
+
click(element, options2) {
|
|
174
|
+
return convertToLocator(element).click(options2);
|
|
144
175
|
},
|
|
145
|
-
dblClick(element, options2
|
|
146
|
-
return convertToLocator(element).dblClick(
|
|
176
|
+
dblClick(element, options2) {
|
|
177
|
+
return convertToLocator(element).dblClick(options2);
|
|
147
178
|
},
|
|
148
|
-
tripleClick(element, options2
|
|
149
|
-
return convertToLocator(element).tripleClick(
|
|
179
|
+
tripleClick(element, options2) {
|
|
180
|
+
return convertToLocator(element).tripleClick(options2);
|
|
150
181
|
},
|
|
151
|
-
selectOptions(element, value) {
|
|
152
|
-
return convertToLocator(element).selectOptions(value);
|
|
182
|
+
selectOptions(element, value, options2) {
|
|
183
|
+
return convertToLocator(element).selectOptions(value, options2);
|
|
153
184
|
},
|
|
154
|
-
clear(element) {
|
|
155
|
-
return convertToLocator(element).clear();
|
|
185
|
+
clear(element, options2) {
|
|
186
|
+
return convertToLocator(element).clear(options2);
|
|
156
187
|
},
|
|
157
|
-
hover(element, options2
|
|
158
|
-
return convertToLocator(element).hover(
|
|
188
|
+
hover(element, options2) {
|
|
189
|
+
return convertToLocator(element).hover(options2);
|
|
159
190
|
},
|
|
160
|
-
unhover(element, options2
|
|
191
|
+
unhover(element, options2) {
|
|
161
192
|
return convertToLocator(element).unhover(options2);
|
|
162
193
|
},
|
|
163
|
-
upload(element, files) {
|
|
164
|
-
return convertToLocator(element).upload(files);
|
|
194
|
+
upload(element, files, options2) {
|
|
195
|
+
return convertToLocator(element).upload(files, options2);
|
|
165
196
|
},
|
|
166
197
|
// non userEvent events, but still useful
|
|
167
198
|
fill(element, text, options2) {
|
|
168
199
|
return convertToLocator(element).fill(text, options2);
|
|
169
200
|
},
|
|
170
|
-
dragAndDrop(source, target, options2
|
|
201
|
+
dragAndDrop(source, target, options2) {
|
|
171
202
|
const sourceLocator = convertToLocator(source);
|
|
172
203
|
const targetLocator = convertToLocator(target);
|
|
173
|
-
return sourceLocator.dropTo(targetLocator,
|
|
204
|
+
return sourceLocator.dropTo(targetLocator, options2);
|
|
174
205
|
},
|
|
175
206
|
// testing-library user-event
|
|
176
|
-
async type(element, text, options2
|
|
177
|
-
return ensureAwaited(async () => {
|
|
207
|
+
async type(element, text, options2) {
|
|
208
|
+
return ensureAwaited(async (error) => {
|
|
178
209
|
const selector = convertToSelector(element);
|
|
179
210
|
const { unreleased } = await triggerCommand(
|
|
180
211
|
"__vitest_type",
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
212
|
+
[
|
|
213
|
+
selector,
|
|
214
|
+
text,
|
|
215
|
+
{ ...options2, unreleased: keyboard.unreleased }
|
|
216
|
+
],
|
|
217
|
+
error
|
|
184
218
|
);
|
|
185
219
|
keyboard.unreleased = unreleased;
|
|
186
220
|
});
|
|
187
221
|
},
|
|
188
222
|
tab(options2 = {}) {
|
|
189
|
-
return ensureAwaited(() => triggerCommand("__vitest_tab", options2));
|
|
223
|
+
return ensureAwaited((error) => triggerCommand("__vitest_tab", [options2], error));
|
|
190
224
|
},
|
|
191
225
|
async keyboard(text) {
|
|
192
|
-
return ensureAwaited(async () => {
|
|
226
|
+
return ensureAwaited(async (error) => {
|
|
193
227
|
const { unreleased } = await triggerCommand(
|
|
194
228
|
"__vitest_keyboard",
|
|
195
|
-
text,
|
|
196
|
-
|
|
229
|
+
[text, keyboard],
|
|
230
|
+
error
|
|
197
231
|
);
|
|
198
232
|
keyboard.unreleased = unreleased;
|
|
199
233
|
});
|
|
@@ -258,7 +292,7 @@ function createPreviewUserEvent(userEventBase, options) {
|
|
|
258
292
|
if (typeof file !== "string") {
|
|
259
293
|
return file;
|
|
260
294
|
}
|
|
261
|
-
const { content: base64, basename, mime } = await triggerCommand("__vitest_fileInfo", file, "base64");
|
|
295
|
+
const { content: base64, basename, mime } = await triggerCommand("__vitest_fileInfo", [file, "base64"]);
|
|
262
296
|
const fileInstance = fetch(`data:${mime};base64,${base64}`).then((r) => r.blob()).then((blob) => new File([blob], basename, { type: mime }));
|
|
263
297
|
return fileInstance;
|
|
264
298
|
});
|
|
@@ -272,10 +306,10 @@ function createPreviewUserEvent(userEventBase, options) {
|
|
|
272
306
|
async dragAndDrop() {
|
|
273
307
|
throw new Error(`The "preview" provider doesn't support 'userEvent.dragAndDrop'`);
|
|
274
308
|
},
|
|
275
|
-
async type(element, text, options2
|
|
309
|
+
async type(element, text, options2) {
|
|
276
310
|
await userEvent.type(toElement(element), text, options2);
|
|
277
311
|
},
|
|
278
|
-
async tab(options2
|
|
312
|
+
async tab(options2) {
|
|
279
313
|
await userEvent.tab(options2);
|
|
280
314
|
},
|
|
281
315
|
async keyboard(text) {
|
|
@@ -337,34 +371,34 @@ const page = {
|
|
|
337
371
|
screenshotIds[repeatCount] ??= {};
|
|
338
372
|
screenshotIds[repeatCount][taskName] = number + 1;
|
|
339
373
|
const name = options.path || `${taskName.replace(/[^a-z0-9]/gi, "-")}-${number}.png`;
|
|
340
|
-
return ensureAwaited(() => triggerCommand("__vitest_screenshot", name, {
|
|
374
|
+
return ensureAwaited((error) => triggerCommand("__vitest_screenshot", [name, processTimeoutOptions({
|
|
341
375
|
...options,
|
|
342
376
|
element: options.element ? convertToSelector(options.element) : void 0
|
|
343
|
-
}));
|
|
377
|
+
})], error));
|
|
344
378
|
},
|
|
345
379
|
getByRole() {
|
|
346
|
-
throw new Error(
|
|
380
|
+
throw new Error(`Method "getByRole" is not implemented in the "${provider}" provider.`);
|
|
347
381
|
},
|
|
348
382
|
getByLabelText() {
|
|
349
|
-
throw new Error(
|
|
383
|
+
throw new Error(`Method "getByLabelText" is not implemented in the "${provider}" provider.`);
|
|
350
384
|
},
|
|
351
385
|
getByTestId() {
|
|
352
|
-
throw new Error(
|
|
386
|
+
throw new Error(`Method "getByTestId" is not implemented in the "${provider}" provider.`);
|
|
353
387
|
},
|
|
354
388
|
getByAltText() {
|
|
355
|
-
throw new Error(
|
|
389
|
+
throw new Error(`Method "getByAltText" is not implemented in the "${provider}" provider.`);
|
|
356
390
|
},
|
|
357
391
|
getByPlaceholder() {
|
|
358
|
-
throw new Error(
|
|
392
|
+
throw new Error(`Method "getByPlaceholder" is not implemented in the "${provider}" provider.`);
|
|
359
393
|
},
|
|
360
394
|
getByText() {
|
|
361
|
-
throw new Error(
|
|
395
|
+
throw new Error(`Method "getByText" is not implemented in the "${provider}" provider.`);
|
|
362
396
|
},
|
|
363
397
|
getByTitle() {
|
|
364
|
-
throw new Error(
|
|
398
|
+
throw new Error(`Method "getByTitle" is not implemented in the "${provider}" provider.`);
|
|
365
399
|
},
|
|
366
400
|
elementLocator() {
|
|
367
|
-
throw new Error(
|
|
401
|
+
throw new Error(`Method "elementLocator" is not implemented in the "${provider}" provider.`);
|
|
368
402
|
},
|
|
369
403
|
extend(methods) {
|
|
370
404
|
for (const key in methods) {
|
|
@@ -394,110 +428,5 @@ function convertToSelector(elementOrLocator) {
|
|
|
394
428
|
function getTaskFullName(task) {
|
|
395
429
|
return task.suite ? `${getTaskFullName(task.suite)} ${task.name}` : task.name;
|
|
396
430
|
}
|
|
397
|
-
function processClickOptions(options_) {
|
|
398
|
-
if (!options_ || !state().config.browser.ui) {
|
|
399
|
-
return options_;
|
|
400
|
-
}
|
|
401
|
-
if (provider === "playwright") {
|
|
402
|
-
const options = options_;
|
|
403
|
-
if (options.position) {
|
|
404
|
-
options.position = processPlaywrightPosition(options.position);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
if (provider === "webdriverio") {
|
|
408
|
-
const options = options_;
|
|
409
|
-
if (options.x != null || options.y != null) {
|
|
410
|
-
const cache = {};
|
|
411
|
-
if (options.x != null) {
|
|
412
|
-
options.x = scaleCoordinate(options.x, cache);
|
|
413
|
-
}
|
|
414
|
-
if (options.y != null) {
|
|
415
|
-
options.y = scaleCoordinate(options.y, cache);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
return options_;
|
|
420
|
-
}
|
|
421
|
-
function processHoverOptions(options_) {
|
|
422
|
-
if (!options_ || !state().config.browser.ui) {
|
|
423
|
-
return options_;
|
|
424
|
-
}
|
|
425
|
-
if (provider === "playwright") {
|
|
426
|
-
const options = options_;
|
|
427
|
-
if (options.position) {
|
|
428
|
-
options.position = processPlaywrightPosition(options.position);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
if (provider === "webdriverio") {
|
|
432
|
-
const options = options_;
|
|
433
|
-
const cache = {};
|
|
434
|
-
if (options.xOffset != null) {
|
|
435
|
-
options.xOffset = scaleCoordinate(options.xOffset, cache);
|
|
436
|
-
}
|
|
437
|
-
if (options.yOffset != null) {
|
|
438
|
-
options.yOffset = scaleCoordinate(options.yOffset, cache);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
return options_;
|
|
442
|
-
}
|
|
443
|
-
function processDragAndDropOptions(options_) {
|
|
444
|
-
if (!options_ || !state().config.browser.ui) {
|
|
445
|
-
return options_;
|
|
446
|
-
}
|
|
447
|
-
if (provider === "playwright") {
|
|
448
|
-
const options = options_;
|
|
449
|
-
if (options.sourcePosition) {
|
|
450
|
-
options.sourcePosition = processPlaywrightPosition(options.sourcePosition);
|
|
451
|
-
}
|
|
452
|
-
if (options.targetPosition) {
|
|
453
|
-
options.targetPosition = processPlaywrightPosition(options.targetPosition);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
if (provider === "webdriverio") {
|
|
457
|
-
const cache = {};
|
|
458
|
-
const options = options_;
|
|
459
|
-
if (options.sourceX != null) {
|
|
460
|
-
options.sourceX = scaleCoordinate(options.sourceX, cache);
|
|
461
|
-
}
|
|
462
|
-
if (options.sourceY != null) {
|
|
463
|
-
options.sourceY = scaleCoordinate(options.sourceY, cache);
|
|
464
|
-
}
|
|
465
|
-
if (options.targetX != null) {
|
|
466
|
-
options.targetX = scaleCoordinate(options.targetX, cache);
|
|
467
|
-
}
|
|
468
|
-
if (options.targetY != null) {
|
|
469
|
-
options.targetY = scaleCoordinate(options.targetY, cache);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
return options_;
|
|
473
|
-
}
|
|
474
|
-
function scaleCoordinate(coordinate, cache) {
|
|
475
|
-
return Math.round(coordinate * getCachedScale(cache));
|
|
476
|
-
}
|
|
477
|
-
function getCachedScale(cache) {
|
|
478
|
-
return cache.scale ??= getIframeScale();
|
|
479
|
-
}
|
|
480
|
-
function processPlaywrightPosition(position) {
|
|
481
|
-
const scale = getIframeScale();
|
|
482
|
-
if (position.x != null) {
|
|
483
|
-
position.x *= scale;
|
|
484
|
-
}
|
|
485
|
-
if (position.y != null) {
|
|
486
|
-
position.y *= scale;
|
|
487
|
-
}
|
|
488
|
-
return position;
|
|
489
|
-
}
|
|
490
|
-
function getIframeScale() {
|
|
491
|
-
const testerUi = window.parent.document.querySelector("#tester-ui");
|
|
492
|
-
if (!testerUi) {
|
|
493
|
-
throw new Error(`Cannot find Tester element. This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
494
|
-
}
|
|
495
|
-
const scaleAttribute = testerUi.getAttribute("data-scale");
|
|
496
|
-
const scale = Number(scaleAttribute);
|
|
497
|
-
if (Number.isNaN(scale)) {
|
|
498
|
-
throw new TypeError(`Cannot parse scale value from Tester element (${scaleAttribute}). This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
499
|
-
}
|
|
500
|
-
return scale;
|
|
501
|
-
}
|
|
502
431
|
|
|
503
432
|
export { cdp, createUserEvent, page };
|
|
@@ -22,13 +22,13 @@ function ensureAwaited(promise) {
|
|
|
22
22
|
return {
|
|
23
23
|
then(onFulfilled, onRejected) {
|
|
24
24
|
awaited = true;
|
|
25
|
-
return (promiseResult ||= promise()).then(onFulfilled, onRejected);
|
|
25
|
+
return (promiseResult ||= promise(sourceError)).then(onFulfilled, onRejected);
|
|
26
26
|
},
|
|
27
27
|
catch(onRejected) {
|
|
28
|
-
return (promiseResult ||= promise()).catch(onRejected);
|
|
28
|
+
return (promiseResult ||= promise(sourceError)).catch(onRejected);
|
|
29
29
|
},
|
|
30
30
|
finally(onFinally) {
|
|
31
|
-
return (promiseResult ||= promise()).finally(onFinally);
|
|
31
|
+
return (promiseResult ||= promise(sourceError)).finally(onFinally);
|
|
32
32
|
},
|
|
33
33
|
[Symbol.toStringTag]: "Promise"
|
|
34
34
|
};
|
|
@@ -45,74 +45,6 @@ function getWorkerState() {
|
|
|
45
45
|
}
|
|
46
46
|
return state;
|
|
47
47
|
}
|
|
48
|
-
// @__NO_SIDE_EFFECTS__
|
|
49
|
-
function convertElementToCssSelector(element) {
|
|
50
|
-
if (!element || !(element instanceof Element)) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`Expected DOM element to be an instance of Element, received ${typeof element}`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return getUniqueCssSelector(element);
|
|
56
|
-
}
|
|
57
|
-
function escapeIdForCSSSelector(id) {
|
|
58
|
-
return id.split("").map((char) => {
|
|
59
|
-
const code = char.charCodeAt(0);
|
|
60
|
-
if (char === " " || char === "#" || char === "." || char === ":" || char === "[" || char === "]" || char === ">" || char === "+" || char === "~" || char === "\\") {
|
|
61
|
-
return `\\${char}`;
|
|
62
|
-
} else if (code >= 65536) {
|
|
63
|
-
return `\\${code.toString(16).toUpperCase().padStart(6, "0")} `;
|
|
64
|
-
} else if (code < 32 || code === 127) {
|
|
65
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
66
|
-
} else if (code >= 128) {
|
|
67
|
-
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
68
|
-
} else {
|
|
69
|
-
return char;
|
|
70
|
-
}
|
|
71
|
-
}).join("");
|
|
72
|
-
}
|
|
73
|
-
function getUniqueCssSelector(el) {
|
|
74
|
-
const path = [];
|
|
75
|
-
let parent;
|
|
76
|
-
let hasShadowRoot = false;
|
|
77
|
-
while (parent = getParent(el)) {
|
|
78
|
-
if (parent.shadowRoot) {
|
|
79
|
-
hasShadowRoot = true;
|
|
80
|
-
}
|
|
81
|
-
const tag = el.tagName;
|
|
82
|
-
if (el.id) {
|
|
83
|
-
path.push(`#${escapeIdForCSSSelector(el.id)}`);
|
|
84
|
-
} else if (!el.nextElementSibling && !el.previousElementSibling) {
|
|
85
|
-
path.push(tag.toLowerCase());
|
|
86
|
-
} else {
|
|
87
|
-
let index = 0;
|
|
88
|
-
let sameTagSiblings = 0;
|
|
89
|
-
let elementIndex = 0;
|
|
90
|
-
for (const sibling of parent.children) {
|
|
91
|
-
index++;
|
|
92
|
-
if (sibling.tagName === tag) {
|
|
93
|
-
sameTagSiblings++;
|
|
94
|
-
}
|
|
95
|
-
if (sibling === el) {
|
|
96
|
-
elementIndex = index;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (sameTagSiblings > 1) {
|
|
100
|
-
path.push(`${tag.toLowerCase()}:nth-child(${elementIndex})`);
|
|
101
|
-
} else {
|
|
102
|
-
path.push(tag.toLowerCase());
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
el = parent;
|
|
106
|
-
}
|
|
107
|
-
return `${(/* @__PURE__ */ getBrowserState()).provider === "webdriverio" && hasShadowRoot ? ">>>" : ""}${path.reverse().join(" > ")}`;
|
|
108
|
-
}
|
|
109
|
-
function getParent(el) {
|
|
110
|
-
const parent = el.parentNode;
|
|
111
|
-
if (parent instanceof ShadowRoot) {
|
|
112
|
-
return parent.host;
|
|
113
|
-
}
|
|
114
|
-
return parent;
|
|
115
|
-
}
|
|
116
48
|
|
|
117
49
|
const selectorEngine = Ivya.create({
|
|
118
50
|
browser: ((name) => {
|
|
@@ -141,8 +73,8 @@ class Locator {
|
|
|
141
73
|
tripleClick(options = {}) {
|
|
142
74
|
return this.triggerCommand("__vitest_tripleClick", this.selector, options);
|
|
143
75
|
}
|
|
144
|
-
clear() {
|
|
145
|
-
return this.triggerCommand("__vitest_clear", this.selector);
|
|
76
|
+
clear(options) {
|
|
77
|
+
return this.triggerCommand("__vitest_clear", this.selector, options);
|
|
146
78
|
}
|
|
147
79
|
hover(options) {
|
|
148
80
|
return this.triggerCommand("__vitest_hover", this.selector, options);
|
|
@@ -153,7 +85,7 @@ class Locator {
|
|
|
153
85
|
fill(text, options) {
|
|
154
86
|
return this.triggerCommand("__vitest_fill", this.selector, text, options);
|
|
155
87
|
}
|
|
156
|
-
async upload(files) {
|
|
88
|
+
async upload(files, options) {
|
|
157
89
|
const filesPromise = (Array.isArray(files) ? files : [files]).map(async (file) => {
|
|
158
90
|
if (typeof file === "string") {
|
|
159
91
|
return file;
|
|
@@ -170,7 +102,7 @@ class Locator {
|
|
|
170
102
|
base64: bas64String
|
|
171
103
|
};
|
|
172
104
|
});
|
|
173
|
-
return this.triggerCommand("__vitest_upload", this.selector, await Promise.all(filesPromise));
|
|
105
|
+
return this.triggerCommand("__vitest_upload", this.selector, await Promise.all(filesPromise), options);
|
|
174
106
|
}
|
|
175
107
|
dropTo(target, options = {}) {
|
|
176
108
|
return this.triggerCommand(
|
|
@@ -180,7 +112,7 @@ class Locator {
|
|
|
180
112
|
options
|
|
181
113
|
);
|
|
182
114
|
}
|
|
183
|
-
selectOptions(value) {
|
|
115
|
+
selectOptions(value, options) {
|
|
184
116
|
const values = (Array.isArray(value) ? value : [value]).map((v) => {
|
|
185
117
|
if (typeof v !== "string") {
|
|
186
118
|
const selector = "element" in v ? v.selector : selectorEngine.generateSelectorSimple(v);
|
|
@@ -188,7 +120,7 @@ class Locator {
|
|
|
188
120
|
}
|
|
189
121
|
return v;
|
|
190
122
|
});
|
|
191
|
-
return this.triggerCommand("__vitest_selectOptions", this.selector, values);
|
|
123
|
+
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
192
124
|
}
|
|
193
125
|
screenshot(options) {
|
|
194
126
|
return page.screenshot({
|
|
@@ -252,11 +184,12 @@ class Locator {
|
|
|
252
184
|
}
|
|
253
185
|
triggerCommand(command, ...args) {
|
|
254
186
|
const commands = getBrowserState().commands;
|
|
255
|
-
return ensureAwaited(() => commands.triggerCommand(
|
|
187
|
+
return ensureAwaited((error) => commands.triggerCommand(
|
|
256
188
|
command,
|
|
257
|
-
args
|
|
189
|
+
args,
|
|
190
|
+
error
|
|
258
191
|
));
|
|
259
192
|
}
|
|
260
193
|
}
|
|
261
194
|
|
|
262
|
-
export { Locator as L,
|
|
195
|
+
export { Locator as L, getWorkerState as a, getBrowserState as g, selectorEngine as s };
|