@vitest/browser 3.0.7 → 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-BX_iUIjH.js → index-CsZqQx26.js} +25 -25
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-DeY4LJgz.js → orchestrator-CqPXjvQE.js} +2 -2
- package/dist/client/__vitest_browser__/{tester-Cqa_buNy.js → tester-lo_P6U-u.js} +87 -15
- package/dist/client/__vitest_browser__/{utils-CBFLDkwI.js → utils-CNTxSNQV.js} +2 -25
- package/dist/client/error-catcher.js +10 -0
- 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 -101
- package/dist/index.js +43 -11
- 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 +8 -8
- package/providers/playwright.d.ts +2 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { page, server } from '@vitest/browser/context';
|
|
2
2
|
import { g as getByTitleSelector, a as getByTextSelector, b as getByPlaceholderSelector, c as getByAltTextSelector, d as getByTestIdSelector, e as getByRoleSelector, f as getByLabelSelector } from '../public-utils-J4vwTaki.js';
|
|
3
|
-
import { s as selectorEngine, L as Locator } from '../index-
|
|
3
|
+
import { s as selectorEngine, L as Locator, g as getBrowserState } from '../index-DrTP5i7N.js';
|
|
4
|
+
import { p as processTimeoutOptions, g as getIframeScale } from '../utils-VCysLhWp.js';
|
|
4
5
|
import 'vitest/utils';
|
|
5
6
|
|
|
6
7
|
page.extend({
|
|
@@ -38,6 +39,35 @@ class PlaywrightLocator extends Locator {
|
|
|
38
39
|
this.selector = selector;
|
|
39
40
|
this._container = _container;
|
|
40
41
|
}
|
|
42
|
+
click(options) {
|
|
43
|
+
return super.click(processTimeoutOptions(processClickOptions(options)));
|
|
44
|
+
}
|
|
45
|
+
dblClick(options) {
|
|
46
|
+
return super.dblClick(processTimeoutOptions(processClickOptions(options)));
|
|
47
|
+
}
|
|
48
|
+
tripleClick(options) {
|
|
49
|
+
return super.tripleClick(processTimeoutOptions(processClickOptions(options)));
|
|
50
|
+
}
|
|
51
|
+
selectOptions(value, options) {
|
|
52
|
+
return super.selectOptions(value, processTimeoutOptions(options));
|
|
53
|
+
}
|
|
54
|
+
clear(options) {
|
|
55
|
+
return super.clear(processTimeoutOptions(options));
|
|
56
|
+
}
|
|
57
|
+
hover(options) {
|
|
58
|
+
return super.hover(processTimeoutOptions(processHoverOptions(options)));
|
|
59
|
+
}
|
|
60
|
+
upload(files, options) {
|
|
61
|
+
return super.upload(files, processTimeoutOptions(options));
|
|
62
|
+
}
|
|
63
|
+
fill(text, options) {
|
|
64
|
+
return super.fill(text, processTimeoutOptions(options));
|
|
65
|
+
}
|
|
66
|
+
dropTo(target, options) {
|
|
67
|
+
return super.dropTo(target, processTimeoutOptions(
|
|
68
|
+
processDragAndDropOptions(options)
|
|
69
|
+
));
|
|
70
|
+
}
|
|
41
71
|
locator(selector) {
|
|
42
72
|
return new PlaywrightLocator(`${this.selector} >> ${selector}`, this._container);
|
|
43
73
|
}
|
|
@@ -48,3 +78,46 @@ class PlaywrightLocator extends Locator {
|
|
|
48
78
|
);
|
|
49
79
|
}
|
|
50
80
|
}
|
|
81
|
+
function processDragAndDropOptions(options_) {
|
|
82
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
83
|
+
return options_;
|
|
84
|
+
}
|
|
85
|
+
const options = options_;
|
|
86
|
+
if (options.sourcePosition) {
|
|
87
|
+
options.sourcePosition = processPlaywrightPosition(options.sourcePosition);
|
|
88
|
+
}
|
|
89
|
+
if (options.targetPosition) {
|
|
90
|
+
options.targetPosition = processPlaywrightPosition(options.targetPosition);
|
|
91
|
+
}
|
|
92
|
+
return options_;
|
|
93
|
+
}
|
|
94
|
+
function processHoverOptions(options_) {
|
|
95
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
96
|
+
return options_;
|
|
97
|
+
}
|
|
98
|
+
const options = options_;
|
|
99
|
+
if (options.position) {
|
|
100
|
+
options.position = processPlaywrightPosition(options.position);
|
|
101
|
+
}
|
|
102
|
+
return options_;
|
|
103
|
+
}
|
|
104
|
+
function processClickOptions(options_) {
|
|
105
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
106
|
+
return options_;
|
|
107
|
+
}
|
|
108
|
+
const options = options_;
|
|
109
|
+
if (options.position) {
|
|
110
|
+
options.position = processPlaywrightPosition(options.position);
|
|
111
|
+
}
|
|
112
|
+
return options;
|
|
113
|
+
}
|
|
114
|
+
function processPlaywrightPosition(position) {
|
|
115
|
+
const scale = getIframeScale();
|
|
116
|
+
if (position.x != null) {
|
|
117
|
+
position.x *= scale;
|
|
118
|
+
}
|
|
119
|
+
if (position.y != null) {
|
|
120
|
+
position.y *= scale;
|
|
121
|
+
}
|
|
122
|
+
return position;
|
|
123
|
+
}
|
package/dist/locators/preview.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { page, server, userEvent } from '@vitest/browser/context';
|
|
2
2
|
import { g as getByTitleSelector, a as getByTextSelector, b as getByPlaceholderSelector, c as getByAltTextSelector, d as getByTestIdSelector, e as getByRoleSelector, f as getByLabelSelector, h as getElementError } from '../public-utils-J4vwTaki.js';
|
|
3
|
-
import {
|
|
3
|
+
import { c as convertElementToCssSelector } from '../utils-VCysLhWp.js';
|
|
4
|
+
import { s as selectorEngine, L as Locator } from '../index-DrTP5i7N.js';
|
|
4
5
|
import 'vitest/utils';
|
|
5
6
|
|
|
6
7
|
page.extend({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { page, server } from '@vitest/browser/context';
|
|
2
2
|
import { g as getByTitleSelector, a as getByTextSelector, b as getByPlaceholderSelector, c as getByAltTextSelector, d as getByTestIdSelector, e as getByRoleSelector, f as getByLabelSelector, h as getElementError } from '../public-utils-J4vwTaki.js';
|
|
3
|
-
import { s as selectorEngine, L as Locator,
|
|
3
|
+
import { s as selectorEngine, L as Locator, g as getBrowserState } from '../index-DrTP5i7N.js';
|
|
4
|
+
import { c as convertElementToCssSelector, g as getIframeScale } from '../utils-VCysLhWp.js';
|
|
4
5
|
import 'vitest/utils';
|
|
5
6
|
|
|
6
7
|
page.extend({
|
|
@@ -42,9 +43,24 @@ class WebdriverIOLocator extends Locator {
|
|
|
42
43
|
}
|
|
43
44
|
return selectors.join(", ");
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
click(options) {
|
|
47
|
+
return super.click(processClickOptions(options));
|
|
48
|
+
}
|
|
49
|
+
dblClick(options) {
|
|
50
|
+
return super.dblClick(processClickOptions(options));
|
|
51
|
+
}
|
|
52
|
+
tripleClick(options) {
|
|
53
|
+
return super.tripleClick(processClickOptions(options));
|
|
54
|
+
}
|
|
55
|
+
selectOptions(value, options) {
|
|
46
56
|
const values = getWebdriverioSelectOptions(this.element(), value);
|
|
47
|
-
return this.triggerCommand("__vitest_selectOptions", this.selector, values);
|
|
57
|
+
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
58
|
+
}
|
|
59
|
+
hover(options) {
|
|
60
|
+
return super.hover(processHoverOptions(options));
|
|
61
|
+
}
|
|
62
|
+
dropTo(target, options) {
|
|
63
|
+
return super.dropTo(target, processDragAndDropOptions(options));
|
|
48
64
|
}
|
|
49
65
|
locator(selector) {
|
|
50
66
|
return new WebdriverIOLocator(`${this._pwSelector} >> ${selector}`, this._container);
|
|
@@ -83,3 +99,59 @@ function getWebdriverioSelectOptions(element, value) {
|
|
|
83
99
|
}
|
|
84
100
|
return [{ index: labelIndex }];
|
|
85
101
|
}
|
|
102
|
+
function processClickOptions(options_) {
|
|
103
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
104
|
+
return options_;
|
|
105
|
+
}
|
|
106
|
+
const options = options_;
|
|
107
|
+
if (options.x != null || options.y != null) {
|
|
108
|
+
const cache = {};
|
|
109
|
+
if (options.x != null) {
|
|
110
|
+
options.x = scaleCoordinate(options.x, cache);
|
|
111
|
+
}
|
|
112
|
+
if (options.y != null) {
|
|
113
|
+
options.y = scaleCoordinate(options.y, cache);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return options_;
|
|
117
|
+
}
|
|
118
|
+
function processHoverOptions(options_) {
|
|
119
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
120
|
+
return options_;
|
|
121
|
+
}
|
|
122
|
+
const options = options_;
|
|
123
|
+
const cache = {};
|
|
124
|
+
if (options.xOffset != null) {
|
|
125
|
+
options.xOffset = scaleCoordinate(options.xOffset, cache);
|
|
126
|
+
}
|
|
127
|
+
if (options.yOffset != null) {
|
|
128
|
+
options.yOffset = scaleCoordinate(options.yOffset, cache);
|
|
129
|
+
}
|
|
130
|
+
return options_;
|
|
131
|
+
}
|
|
132
|
+
function processDragAndDropOptions(options_) {
|
|
133
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
134
|
+
return options_;
|
|
135
|
+
}
|
|
136
|
+
const cache = {};
|
|
137
|
+
const options = options_;
|
|
138
|
+
if (options.sourceX != null) {
|
|
139
|
+
options.sourceX = scaleCoordinate(options.sourceX, cache);
|
|
140
|
+
}
|
|
141
|
+
if (options.sourceY != null) {
|
|
142
|
+
options.sourceY = scaleCoordinate(options.sourceY, cache);
|
|
143
|
+
}
|
|
144
|
+
if (options.targetX != null) {
|
|
145
|
+
options.targetX = scaleCoordinate(options.targetX, cache);
|
|
146
|
+
}
|
|
147
|
+
if (options.targetY != null) {
|
|
148
|
+
options.targetY = scaleCoordinate(options.targetY, cache);
|
|
149
|
+
}
|
|
150
|
+
return options_;
|
|
151
|
+
}
|
|
152
|
+
function scaleCoordinate(coordinate, cache) {
|
|
153
|
+
return Math.round(coordinate * getCachedScale(cache));
|
|
154
|
+
}
|
|
155
|
+
function getCachedScale(cache) {
|
|
156
|
+
return cache.scale ??= getIframeScale();
|
|
157
|
+
}
|
|
@@ -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": {
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"sirv": "^3.0.1",
|
|
88
88
|
"tinyrainbow": "^2.0.0",
|
|
89
89
|
"ws": "^8.18.1",
|
|
90
|
-
"@vitest/mocker": "3.0.
|
|
91
|
-
"@vitest/utils": "3.0.
|
|
90
|
+
"@vitest/mocker": "3.0.9",
|
|
91
|
+
"@vitest/utils": "3.0.9"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -105,10 +105,10 @@
|
|
|
105
105
|
"playwright-core": "^1.50.1",
|
|
106
106
|
"safaridriver": "^1.0.0",
|
|
107
107
|
"webdriverio": "^9.10.0",
|
|
108
|
-
"@vitest/
|
|
109
|
-
"
|
|
110
|
-
"@vitest/ws-client": "3.0.
|
|
111
|
-
"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"
|
|
112
112
|
},
|
|
113
113
|
"scripts": {
|
|
114
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
|
|