@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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { g as getBrowserState, a as getWorkerState } from './index-DrTP5i7N.js';
|
|
2
|
+
|
|
3
|
+
const provider = getBrowserState().provider;
|
|
4
|
+
// @__NO_SIDE_EFFECTS__
|
|
5
|
+
function convertElementToCssSelector(element) {
|
|
6
|
+
if (!element || !(element instanceof Element)) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
`Expected DOM element to be an instance of Element, received ${typeof element}`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return getUniqueCssSelector(element);
|
|
12
|
+
}
|
|
13
|
+
function escapeIdForCSSSelector(id) {
|
|
14
|
+
return id.split("").map((char) => {
|
|
15
|
+
const code = char.charCodeAt(0);
|
|
16
|
+
if (char === " " || char === "#" || char === "." || char === ":" || char === "[" || char === "]" || char === ">" || char === "+" || char === "~" || char === "\\") {
|
|
17
|
+
return `\\${char}`;
|
|
18
|
+
} else if (code >= 65536) {
|
|
19
|
+
return `\\${code.toString(16).toUpperCase().padStart(6, "0")} `;
|
|
20
|
+
} else if (code < 32 || code === 127) {
|
|
21
|
+
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
22
|
+
} else if (code >= 128) {
|
|
23
|
+
return `\\${code.toString(16).toUpperCase().padStart(2, "0")} `;
|
|
24
|
+
} else {
|
|
25
|
+
return char;
|
|
26
|
+
}
|
|
27
|
+
}).join("");
|
|
28
|
+
}
|
|
29
|
+
function getUniqueCssSelector(el) {
|
|
30
|
+
const path = [];
|
|
31
|
+
let parent;
|
|
32
|
+
let hasShadowRoot = false;
|
|
33
|
+
while (parent = getParent(el)) {
|
|
34
|
+
if (parent.shadowRoot) {
|
|
35
|
+
hasShadowRoot = true;
|
|
36
|
+
}
|
|
37
|
+
const tag = el.tagName;
|
|
38
|
+
if (el.id) {
|
|
39
|
+
path.push(`#${escapeIdForCSSSelector(el.id)}`);
|
|
40
|
+
} else if (!el.nextElementSibling && !el.previousElementSibling) {
|
|
41
|
+
path.push(tag.toLowerCase());
|
|
42
|
+
} else {
|
|
43
|
+
let index = 0;
|
|
44
|
+
let sameTagSiblings = 0;
|
|
45
|
+
let elementIndex = 0;
|
|
46
|
+
for (const sibling of parent.children) {
|
|
47
|
+
index++;
|
|
48
|
+
if (sibling.tagName === tag) {
|
|
49
|
+
sameTagSiblings++;
|
|
50
|
+
}
|
|
51
|
+
if (sibling === el) {
|
|
52
|
+
elementIndex = index;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (sameTagSiblings > 1) {
|
|
56
|
+
path.push(`${tag.toLowerCase()}:nth-child(${elementIndex})`);
|
|
57
|
+
} else {
|
|
58
|
+
path.push(tag.toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
el = parent;
|
|
62
|
+
}
|
|
63
|
+
return `${getBrowserState().provider === "webdriverio" && hasShadowRoot ? ">>>" : ""}${path.reverse().join(" > ")}`;
|
|
64
|
+
}
|
|
65
|
+
function getParent(el) {
|
|
66
|
+
const parent = el.parentNode;
|
|
67
|
+
if (parent instanceof ShadowRoot) {
|
|
68
|
+
return parent.host;
|
|
69
|
+
}
|
|
70
|
+
return parent;
|
|
71
|
+
}
|
|
72
|
+
const now = Date.now;
|
|
73
|
+
function processTimeoutOptions(options_) {
|
|
74
|
+
if (
|
|
75
|
+
// if timeout is set, keep it
|
|
76
|
+
options_ && options_.timeout != null || provider !== "playwright"
|
|
77
|
+
) {
|
|
78
|
+
return options_;
|
|
79
|
+
}
|
|
80
|
+
if (getWorkerState().config.browser.providerOptions.actionTimeout != null) {
|
|
81
|
+
return options_;
|
|
82
|
+
}
|
|
83
|
+
const currentTest = getWorkerState().current;
|
|
84
|
+
const startTime = currentTest?.result?.startTime;
|
|
85
|
+
if (!currentTest || currentTest.type === "suite" || !startTime) {
|
|
86
|
+
return options_;
|
|
87
|
+
}
|
|
88
|
+
const timeout = currentTest.timeout;
|
|
89
|
+
if (timeout === 0 || timeout === Number.POSITIVE_INFINITY) {
|
|
90
|
+
return options_;
|
|
91
|
+
}
|
|
92
|
+
options_ = options_ || {};
|
|
93
|
+
const currentTime = now();
|
|
94
|
+
const endTime = startTime + timeout;
|
|
95
|
+
const remainingTime = endTime - currentTime;
|
|
96
|
+
if (remainingTime <= 0) {
|
|
97
|
+
return options_;
|
|
98
|
+
}
|
|
99
|
+
options_.timeout = remainingTime - 100;
|
|
100
|
+
return options_;
|
|
101
|
+
}
|
|
102
|
+
function getIframeScale() {
|
|
103
|
+
const testerUi = window.parent.document.querySelector("#tester-ui");
|
|
104
|
+
if (!testerUi) {
|
|
105
|
+
throw new Error(`Cannot find Tester element. This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
106
|
+
}
|
|
107
|
+
const scaleAttribute = testerUi.getAttribute("data-scale");
|
|
108
|
+
const scale = Number(scaleAttribute);
|
|
109
|
+
if (Number.isNaN(scale)) {
|
|
110
|
+
throw new TypeError(`Cannot parse scale value from Tester element (${scaleAttribute}). This is a bug in Vitest. Please, open a new issue with reproduction.`);
|
|
111
|
+
}
|
|
112
|
+
return scale;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { convertElementToCssSelector as c, getIframeScale as g, processTimeoutOptions as p };
|
package/matchers.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ declare module 'vitest' {
|
|
|
19
19
|
interface ExpectStatic {
|
|
20
20
|
/**
|
|
21
21
|
* `expect.element(locator)` is a shorthand for `expect.poll(() => locator.element())`.
|
|
22
|
-
* You can set default timeout via `expect.poll.timeout` config.
|
|
22
|
+
* You can set default timeout via `expect.poll.timeout` option in the config.
|
|
23
|
+
* @see {@link https://vitest.dev/api/expect#poll}
|
|
23
24
|
*/
|
|
24
25
|
element: <T extends Element | Locator>(element: T, options?: ExpectPollOptions) => PromisifyDomAssertion<Awaited<Element | null>>
|
|
25
26
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.9",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"playwright": "*",
|
|
68
68
|
"webdriverio": "^7.0.0 || ^8.0.0 || ^9.0.0",
|
|
69
|
-
"vitest": "3.0.
|
|
69
|
+
"vitest": "3.0.9"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"playwright": {
|
|
@@ -80,14 +80,15 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
+
"@testing-library/dom": "^10.4.0",
|
|
83
84
|
"@testing-library/user-event": "^14.6.1",
|
|
84
85
|
"magic-string": "^0.30.17",
|
|
85
86
|
"msw": "^2.7.3",
|
|
86
87
|
"sirv": "^3.0.1",
|
|
87
88
|
"tinyrainbow": "^2.0.0",
|
|
88
89
|
"ws": "^8.18.1",
|
|
89
|
-
"@vitest/
|
|
90
|
-
"@vitest/
|
|
90
|
+
"@vitest/mocker": "3.0.9",
|
|
91
|
+
"@vitest/utils": "3.0.9"
|
|
91
92
|
},
|
|
92
93
|
"devDependencies": {
|
|
93
94
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -104,10 +105,10 @@
|
|
|
104
105
|
"playwright-core": "^1.50.1",
|
|
105
106
|
"safaridriver": "^1.0.0",
|
|
106
107
|
"webdriverio": "^9.10.0",
|
|
107
|
-
"@vitest/
|
|
108
|
-
"
|
|
109
|
-
"@vitest/ws-client": "3.0.
|
|
110
|
-
"vitest": "3.0.
|
|
108
|
+
"@vitest/ui": "3.0.9",
|
|
109
|
+
"vitest": "3.0.9",
|
|
110
|
+
"@vitest/ws-client": "3.0.9",
|
|
111
|
+
"@vitest/runner": "3.0.9"
|
|
111
112
|
},
|
|
112
113
|
"scripts": {
|
|
113
114
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|
|
@@ -41,6 +41,7 @@ type PWFillOptions = NonNullable<Parameters<Page['fill']>[2]>
|
|
|
41
41
|
type PWScreenshotOptions = NonNullable<Parameters<Page['screenshot']>[0]>
|
|
42
42
|
type PWSelectOptions = NonNullable<Parameters<Page['selectOption']>[2]>
|
|
43
43
|
type PWDragAndDropOptions = NonNullable<Parameters<Page['dragAndDrop']>[2]>
|
|
44
|
+
type PWSetInputFiles = NonNullable<Parameters<Page['setInputFiles']>[2]>
|
|
44
45
|
|
|
45
46
|
declare module '@vitest/browser/context' {
|
|
46
47
|
export interface UserEventHoverOptions extends PWHoverOptions {}
|
|
@@ -50,6 +51,7 @@ declare module '@vitest/browser/context' {
|
|
|
50
51
|
export interface UserEventFillOptions extends PWFillOptions {}
|
|
51
52
|
export interface UserEventSelectOptions extends PWSelectOptions {}
|
|
52
53
|
export interface UserEventDragAndDropOptions extends PWDragAndDropOptions {}
|
|
54
|
+
export interface UserEventUploadOptions extends PWSetInputFiles {}
|
|
53
55
|
|
|
54
56
|
export interface ScreenshotOptions extends PWScreenshotOptions {}
|
|
55
57
|
|