@vitest/browser 3.1.0-beta.1 → 3.1.0-beta.2
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 +22 -0
- package/dist/client/.vite/manifest.json +1 -1
- package/dist/client/__vitest__/assets/{index-CsZqQx26.js → index-C3wX9Cb1.js} +1 -1
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{tester-lo_P6U-u.js → tester-DRF-LncV.js} +1112 -324
- package/dist/client/tester/tester.html +1 -1
- package/dist/client.js +91 -105
- package/dist/context.js +374 -390
- package/dist/index-VvsEiykv.js +327 -0
- package/dist/index.js +1914 -1885
- package/dist/locators/index.d.ts +3 -0
- package/dist/locators/index.js +2 -2
- package/dist/locators/playwright.js +99 -108
- package/dist/locators/preview.js +71 -78
- package/dist/locators/webdriverio.js +135 -138
- package/dist/providers.js +34 -37
- package/dist/{public-utils-J4vwTaki.js → public-utils-4WiYB3_6.js} +38 -40
- package/dist/state.js +170 -1
- package/dist/utils.js +1 -1
- package/dist/webdriver-BP2w_ajA.js +271 -0
- package/package.json +8 -8
- package/dist/index-DrTP5i7N.js +0 -195
- package/dist/utils-VCysLhWp.js +0 -115
- package/dist/webdriver-C5-VI7VH.js +0 -275
|
@@ -1,157 +1,154 @@
|
|
|
1
1
|
import { page, server } from '@vitest/browser/context';
|
|
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-
|
|
3
|
-
import { s as selectorEngine, L as Locator, g as getBrowserState } from '../index-
|
|
4
|
-
import { c as convertElementToCssSelector, g as getIframeScale } from '../utils-VCysLhWp.js';
|
|
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-4WiYB3_6.js';
|
|
3
|
+
import { s as selectorEngine, L as Locator, c as convertElementToCssSelector, g as getBrowserState, a as getIframeScale } from '../index-VvsEiykv.js';
|
|
5
4
|
import 'vitest/utils';
|
|
6
5
|
|
|
7
6
|
page.extend({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
getByLabelText(text, options) {
|
|
8
|
+
return new WebdriverIOLocator(getByLabelSelector(text, options));
|
|
9
|
+
},
|
|
10
|
+
getByRole(role, options) {
|
|
11
|
+
return new WebdriverIOLocator(getByRoleSelector(role, options));
|
|
12
|
+
},
|
|
13
|
+
getByTestId(testId) {
|
|
14
|
+
return new WebdriverIOLocator(getByTestIdSelector(server.config.browser.locators.testIdAttribute, testId));
|
|
15
|
+
},
|
|
16
|
+
getByAltText(text, options) {
|
|
17
|
+
return new WebdriverIOLocator(getByAltTextSelector(text, options));
|
|
18
|
+
},
|
|
19
|
+
getByPlaceholder(text, options) {
|
|
20
|
+
return new WebdriverIOLocator(getByPlaceholderSelector(text, options));
|
|
21
|
+
},
|
|
22
|
+
getByText(text, options) {
|
|
23
|
+
return new WebdriverIOLocator(getByTextSelector(text, options));
|
|
24
|
+
},
|
|
25
|
+
getByTitle(title, options) {
|
|
26
|
+
return new WebdriverIOLocator(getByTitleSelector(title, options));
|
|
27
|
+
},
|
|
28
|
+
elementLocator(element) {
|
|
29
|
+
return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(element));
|
|
30
|
+
}
|
|
32
31
|
});
|
|
33
32
|
class WebdriverIOLocator extends Locator {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
33
|
+
constructor(_pwSelector, _container) {
|
|
34
|
+
super();
|
|
35
|
+
this._pwSelector = _pwSelector;
|
|
36
|
+
this._container = _container;
|
|
37
|
+
}
|
|
38
|
+
get selector() {
|
|
39
|
+
const selectors = this.elements().map((element) => convertElementToCssSelector(element));
|
|
40
|
+
if (!selectors.length) {
|
|
41
|
+
throw getElementError(this._pwSelector, this._container || document.body);
|
|
42
|
+
}
|
|
43
|
+
return selectors.join(", ");
|
|
44
|
+
}
|
|
45
|
+
click(options) {
|
|
46
|
+
return super.click(processClickOptions(options));
|
|
47
|
+
}
|
|
48
|
+
dblClick(options) {
|
|
49
|
+
return super.dblClick(processClickOptions(options));
|
|
50
|
+
}
|
|
51
|
+
tripleClick(options) {
|
|
52
|
+
return super.tripleClick(processClickOptions(options));
|
|
53
|
+
}
|
|
54
|
+
selectOptions(value, options) {
|
|
55
|
+
const values = getWebdriverioSelectOptions(this.element(), value);
|
|
56
|
+
return this.triggerCommand("__vitest_selectOptions", this.selector, values, options);
|
|
57
|
+
}
|
|
58
|
+
hover(options) {
|
|
59
|
+
return super.hover(processHoverOptions(options));
|
|
60
|
+
}
|
|
61
|
+
dropTo(target, options) {
|
|
62
|
+
return super.dropTo(target, processDragAndDropOptions(options));
|
|
63
|
+
}
|
|
64
|
+
locator(selector) {
|
|
65
|
+
return new WebdriverIOLocator(`${this._pwSelector} >> ${selector}`, this._container);
|
|
66
|
+
}
|
|
67
|
+
elementLocator(element) {
|
|
68
|
+
return new WebdriverIOLocator(selectorEngine.generateSelectorSimple(element), element);
|
|
69
|
+
}
|
|
71
70
|
}
|
|
72
71
|
function getWebdriverioSelectOptions(element, value) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
return [{ index: labelIndex }];
|
|
72
|
+
const options = [...element.querySelectorAll("option")];
|
|
73
|
+
const arrayValues = Array.isArray(value) ? value : [value];
|
|
74
|
+
if (!arrayValues.length) {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
if (arrayValues.length > 1) {
|
|
78
|
+
throw new Error("Provider \"webdriverio\" doesn't support selecting multiple values at once");
|
|
79
|
+
}
|
|
80
|
+
const optionValue = arrayValues[0];
|
|
81
|
+
if (typeof optionValue !== "string") {
|
|
82
|
+
const element = "element" in optionValue ? optionValue.element() : optionValue;
|
|
83
|
+
const index = options.indexOf(element);
|
|
84
|
+
if (index === -1) {
|
|
85
|
+
throw new Error(`The element ${selectorEngine.previewNode(element)} was not found in the "select" options.`);
|
|
86
|
+
}
|
|
87
|
+
return [{ index }];
|
|
88
|
+
}
|
|
89
|
+
const valueIndex = options.findIndex((option) => option.value === optionValue);
|
|
90
|
+
if (valueIndex !== -1) {
|
|
91
|
+
return [{ index: valueIndex }];
|
|
92
|
+
}
|
|
93
|
+
const labelIndex = options.findIndex((option) => option.textContent?.trim() === optionValue || option.ariaLabel === optionValue);
|
|
94
|
+
if (labelIndex === -1) {
|
|
95
|
+
throw new Error(`The option "${optionValue}" was not found in the "select" options.`);
|
|
96
|
+
}
|
|
97
|
+
return [{ index: labelIndex }];
|
|
101
98
|
}
|
|
102
99
|
function processClickOptions(options_) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
100
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
101
|
+
return options_;
|
|
102
|
+
}
|
|
103
|
+
const options = options_;
|
|
104
|
+
if (options.x != null || options.y != null) {
|
|
105
|
+
const cache = {};
|
|
106
|
+
if (options.x != null) {
|
|
107
|
+
options.x = scaleCoordinate(options.x, cache);
|
|
108
|
+
}
|
|
109
|
+
if (options.y != null) {
|
|
110
|
+
options.y = scaleCoordinate(options.y, cache);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return options_;
|
|
117
114
|
}
|
|
118
115
|
function processHoverOptions(options_) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
116
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
117
|
+
return options_;
|
|
118
|
+
}
|
|
119
|
+
const options = options_;
|
|
120
|
+
const cache = {};
|
|
121
|
+
if (options.xOffset != null) {
|
|
122
|
+
options.xOffset = scaleCoordinate(options.xOffset, cache);
|
|
123
|
+
}
|
|
124
|
+
if (options.yOffset != null) {
|
|
125
|
+
options.yOffset = scaleCoordinate(options.yOffset, cache);
|
|
126
|
+
}
|
|
127
|
+
return options_;
|
|
131
128
|
}
|
|
132
129
|
function processDragAndDropOptions(options_) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
130
|
+
if (!options_ || !getBrowserState().config.browser.ui) {
|
|
131
|
+
return options_;
|
|
132
|
+
}
|
|
133
|
+
const cache = {};
|
|
134
|
+
const options = options_;
|
|
135
|
+
if (options.sourceX != null) {
|
|
136
|
+
options.sourceX = scaleCoordinate(options.sourceX, cache);
|
|
137
|
+
}
|
|
138
|
+
if (options.sourceY != null) {
|
|
139
|
+
options.sourceY = scaleCoordinate(options.sourceY, cache);
|
|
140
|
+
}
|
|
141
|
+
if (options.targetX != null) {
|
|
142
|
+
options.targetX = scaleCoordinate(options.targetX, cache);
|
|
143
|
+
}
|
|
144
|
+
if (options.targetY != null) {
|
|
145
|
+
options.targetY = scaleCoordinate(options.targetY, cache);
|
|
146
|
+
}
|
|
147
|
+
return options_;
|
|
151
148
|
}
|
|
152
149
|
function scaleCoordinate(coordinate, cache) {
|
|
153
|
-
|
|
150
|
+
return Math.round(coordinate * getCachedScale(cache));
|
|
154
151
|
}
|
|
155
152
|
function getCachedScale(cache) {
|
|
156
|
-
|
|
153
|
+
return cache.scale ??= getIframeScale();
|
|
157
154
|
}
|
package/dist/providers.js
CHANGED
|
@@ -1,42 +1,39 @@
|
|
|
1
|
-
import { W as WebdriverBrowserProvider, P as PlaywrightBrowserProvider } from './webdriver-
|
|
1
|
+
import { W as WebdriverBrowserProvider, P as PlaywrightBrowserProvider } from './webdriver-BP2w_ajA.js';
|
|
2
2
|
|
|
3
3
|
class PreviewBrowserProvider {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
async close() {
|
|
39
|
-
}
|
|
4
|
+
name = "preview";
|
|
5
|
+
supportsParallelism = false;
|
|
6
|
+
project;
|
|
7
|
+
open = false;
|
|
8
|
+
getSupportedBrowsers() {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
isOpen() {
|
|
12
|
+
return this.open;
|
|
13
|
+
}
|
|
14
|
+
getCommandsContext() {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
async initialize(project) {
|
|
18
|
+
this.project = project;
|
|
19
|
+
this.open = false;
|
|
20
|
+
if (project.config.browser.headless) {
|
|
21
|
+
throw new Error("You've enabled headless mode for \"preview\" provider but it doesn't support it. Use \"playwright\" or \"webdriverio\" instead: https://vitest.dev/guide/browser/#configuration");
|
|
22
|
+
}
|
|
23
|
+
project.vitest.logger.printBrowserBanner(project);
|
|
24
|
+
}
|
|
25
|
+
async openPage(_sessionId, url) {
|
|
26
|
+
this.open = true;
|
|
27
|
+
if (!this.project.browser) {
|
|
28
|
+
throw new Error("Browser is not initialized");
|
|
29
|
+
}
|
|
30
|
+
const options = this.project.browser.vite.config.server;
|
|
31
|
+
const _open = options.open;
|
|
32
|
+
options.open = url;
|
|
33
|
+
this.project.browser.vite.openBrowser();
|
|
34
|
+
options.open = _open;
|
|
35
|
+
}
|
|
36
|
+
async close() {}
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
const webdriverio = WebdriverBrowserProvider;
|
|
@@ -5510,52 +5510,50 @@ function getByRoleSelector(role, options = {}) {
|
|
|
5510
5510
|
}
|
|
5511
5511
|
|
|
5512
5512
|
function getElementLocatorSelectors(element) {
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5513
|
+
const locator = page.elementLocator(element);
|
|
5514
|
+
return {
|
|
5515
|
+
getByAltText: (altText, options) => locator.getByAltText(altText, options),
|
|
5516
|
+
getByLabelText: (labelText, options) => locator.getByLabelText(labelText, options),
|
|
5517
|
+
getByPlaceholder: (placeholderText, options) => locator.getByPlaceholder(placeholderText, options),
|
|
5518
|
+
getByRole: (role, options) => locator.getByRole(role, options),
|
|
5519
|
+
getByTestId: (testId) => locator.getByTestId(testId),
|
|
5520
|
+
getByText: (text, options) => locator.getByText(text, options),
|
|
5521
|
+
getByTitle: (title, options) => locator.getByTitle(title, options)
|
|
5522
|
+
};
|
|
5523
5523
|
}
|
|
5524
5524
|
function debug(el, maxLength, options) {
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5525
|
+
if (Array.isArray(el)) {
|
|
5526
|
+
el.forEach((e) => console.log(prettyDOM(e, maxLength, options)));
|
|
5527
|
+
} else {
|
|
5528
|
+
console.log(prettyDOM(el, maxLength, options));
|
|
5529
|
+
}
|
|
5530
5530
|
}
|
|
5531
5531
|
function prettyDOM(dom, maxLength = Number(import.meta.env.DEBUG_PRINT_LIMIT ?? 7e3), prettyFormatOptions = {}) {
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5532
|
+
if (maxLength === 0) {
|
|
5533
|
+
return "";
|
|
5534
|
+
}
|
|
5535
|
+
if (!dom) {
|
|
5536
|
+
dom = document.body;
|
|
5537
|
+
}
|
|
5538
|
+
if ("element" in dom && "all" in dom) {
|
|
5539
|
+
dom = dom.element();
|
|
5540
|
+
}
|
|
5541
|
+
const type = typeof dom;
|
|
5542
|
+
if (type !== "object" || !dom.outerHTML) {
|
|
5543
|
+
const typeName = type === "object" ? dom.constructor.name : type;
|
|
5544
|
+
throw new TypeError(`Expecting a valid DOM element, but got ${typeName}.`);
|
|
5545
|
+
}
|
|
5546
|
+
const pretty = stringify(dom, Number.POSITIVE_INFINITY, {
|
|
5547
|
+
maxLength,
|
|
5548
|
+
highlight: true,
|
|
5549
|
+
...prettyFormatOptions
|
|
5550
|
+
});
|
|
5551
|
+
return dom.outerHTML.length > maxLength ? `${pretty.slice(0, maxLength)}...` : pretty;
|
|
5552
5552
|
}
|
|
5553
5553
|
function getElementError(selector, container) {
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
error.name = "VitestBrowserElementError";
|
|
5558
|
-
return error;
|
|
5554
|
+
const error = new Error(`Cannot find element with locator: ${asLocator("javascript", selector)}\n\n${prettyDOM(container)}`);
|
|
5555
|
+
error.name = "VitestBrowserElementError";
|
|
5556
|
+
return error;
|
|
5559
5557
|
}
|
|
5560
5558
|
|
|
5561
5559
|
export { Ivya as I, getByTextSelector as a, getByPlaceholderSelector as b, getByAltTextSelector as c, getByTestIdSelector as d, getByRoleSelector as e, getByLabelSelector as f, getByTitleSelector as g, getElementError as h, getElementLocatorSelectors as i, debug as j, prettyDOM as p };
|
package/dist/state.js
CHANGED
|
@@ -1 +1,170 @@
|
|
|
1
|
-
(function
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/// <reference types="../types/index.d.ts" />
|
|
5
|
+
|
|
6
|
+
// (c) 2020-present Andrea Giammarchi
|
|
7
|
+
|
|
8
|
+
const {parse: $parse} = JSON;
|
|
9
|
+
const {keys} = Object;
|
|
10
|
+
|
|
11
|
+
const Primitive = String; // it could be Number
|
|
12
|
+
const primitive = 'string'; // it could be 'number'
|
|
13
|
+
|
|
14
|
+
const ignore = {};
|
|
15
|
+
const object = 'object';
|
|
16
|
+
|
|
17
|
+
const noop = (_, value) => value;
|
|
18
|
+
|
|
19
|
+
const primitives = value => (
|
|
20
|
+
value instanceof Primitive ? Primitive(value) : value
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const Primitives = (_, value) => (
|
|
24
|
+
typeof value === primitive ? new Primitive(value) : value
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const revive = (input, parsed, output, $) => {
|
|
28
|
+
const lazy = [];
|
|
29
|
+
for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
|
|
30
|
+
const k = ke[y];
|
|
31
|
+
const value = output[k];
|
|
32
|
+
if (value instanceof Primitive) {
|
|
33
|
+
const tmp = input[value];
|
|
34
|
+
if (typeof tmp === object && !parsed.has(tmp)) {
|
|
35
|
+
parsed.add(tmp);
|
|
36
|
+
output[k] = ignore;
|
|
37
|
+
lazy.push({k, a: [input, parsed, tmp, $]});
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
output[k] = $.call(output, k, tmp);
|
|
41
|
+
}
|
|
42
|
+
else if (output[k] !== ignore)
|
|
43
|
+
output[k] = $.call(output, k, value);
|
|
44
|
+
}
|
|
45
|
+
for (let {length} = lazy, i = 0; i < length; i++) {
|
|
46
|
+
const {k, a} = lazy[i];
|
|
47
|
+
output[k] = $.call(output, k, revive.apply(null, a));
|
|
48
|
+
}
|
|
49
|
+
return output;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Converts a specialized flatted string into a JS value.
|
|
54
|
+
* @param {string} text
|
|
55
|
+
* @param {(this: any, key: string, value: any) => any} [reviver]
|
|
56
|
+
* @returns {any}
|
|
57
|
+
*/
|
|
58
|
+
const parse = (text, reviver) => {
|
|
59
|
+
const input = $parse(text, Primitives).map(primitives);
|
|
60
|
+
const value = input[0];
|
|
61
|
+
const $ = noop;
|
|
62
|
+
const tmp = typeof value === object && value ?
|
|
63
|
+
revive(input, new Set, value, $) :
|
|
64
|
+
value;
|
|
65
|
+
return $.call({'': tmp}, '', tmp);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
69
|
+
function getBrowserState() {
|
|
70
|
+
return window.__vitest_browser_runner__;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const config = getBrowserState().config;
|
|
74
|
+
const sessionId = getBrowserState().sessionId;
|
|
75
|
+
const providedContext = parse(getBrowserState().providedContext);
|
|
76
|
+
const state = {
|
|
77
|
+
ctx: {
|
|
78
|
+
pool: "browser",
|
|
79
|
+
worker: "./browser.js",
|
|
80
|
+
workerId: 1,
|
|
81
|
+
config,
|
|
82
|
+
projectName: config.name || "",
|
|
83
|
+
files: [],
|
|
84
|
+
environment: {
|
|
85
|
+
name: "browser",
|
|
86
|
+
options: null
|
|
87
|
+
},
|
|
88
|
+
providedContext,
|
|
89
|
+
invalidates: []
|
|
90
|
+
},
|
|
91
|
+
onCancel: null,
|
|
92
|
+
config,
|
|
93
|
+
environment: {
|
|
94
|
+
name: "browser",
|
|
95
|
+
transformMode: "web",
|
|
96
|
+
setup() {
|
|
97
|
+
throw new Error("Not called in the browser");
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
moduleCache: getBrowserState().moduleCache,
|
|
101
|
+
rpc: null,
|
|
102
|
+
durations: {
|
|
103
|
+
environment: 0,
|
|
104
|
+
prepare: performance.now()
|
|
105
|
+
},
|
|
106
|
+
providedContext
|
|
107
|
+
};
|
|
108
|
+
globalThis.__vitest_browser__ = true;
|
|
109
|
+
globalThis.__vitest_worker__ = state;
|
|
110
|
+
getBrowserState().cdp = createCdp();
|
|
111
|
+
function rpc() {
|
|
112
|
+
return state.rpc;
|
|
113
|
+
}
|
|
114
|
+
function createCdp() {
|
|
115
|
+
const listenersMap = new WeakMap();
|
|
116
|
+
function getId(listener) {
|
|
117
|
+
const id = listenersMap.get(listener) || crypto.randomUUID();
|
|
118
|
+
listenersMap.set(listener, id);
|
|
119
|
+
return id;
|
|
120
|
+
}
|
|
121
|
+
const listeners = {};
|
|
122
|
+
const cdp = {
|
|
123
|
+
send(method, params) {
|
|
124
|
+
return rpc().sendCdpEvent(sessionId, method, params);
|
|
125
|
+
},
|
|
126
|
+
on(event, listener) {
|
|
127
|
+
const listenerId = getId(listener);
|
|
128
|
+
listeners[event] = listeners[event] || [];
|
|
129
|
+
listeners[event].push(listener);
|
|
130
|
+
rpc().trackCdpEvent(sessionId, "on", event, listenerId).catch(error);
|
|
131
|
+
return cdp;
|
|
132
|
+
},
|
|
133
|
+
once(event, listener) {
|
|
134
|
+
const listenerId = getId(listener);
|
|
135
|
+
const handler = (data) => {
|
|
136
|
+
listener(data);
|
|
137
|
+
cdp.off(event, listener);
|
|
138
|
+
};
|
|
139
|
+
listeners[event] = listeners[event] || [];
|
|
140
|
+
listeners[event].push(handler);
|
|
141
|
+
rpc().trackCdpEvent(sessionId, "once", event, listenerId).catch(error);
|
|
142
|
+
return cdp;
|
|
143
|
+
},
|
|
144
|
+
off(event, listener) {
|
|
145
|
+
const listenerId = getId(listener);
|
|
146
|
+
if (listeners[event]) {
|
|
147
|
+
listeners[event] = listeners[event].filter((l) => l !== listener);
|
|
148
|
+
}
|
|
149
|
+
rpc().trackCdpEvent(sessionId, "off", event, listenerId).catch(error);
|
|
150
|
+
return cdp;
|
|
151
|
+
},
|
|
152
|
+
emit(event, payload) {
|
|
153
|
+
if (listeners[event]) {
|
|
154
|
+
listeners[event].forEach((l) => {
|
|
155
|
+
try {
|
|
156
|
+
l(payload);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
error(err);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return cdp;
|
|
165
|
+
}
|
|
166
|
+
function error(err) {
|
|
167
|
+
window.dispatchEvent(new ErrorEvent("error", { error: err }));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
})();
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '@vitest/browser/context';
|
|
2
|
-
export { j as debug, h as getElementError, i as getElementLocatorSelectors, p as prettyDOM } from './public-utils-
|
|
2
|
+
export { j as debug, h as getElementError, i as getElementLocatorSelectors, p as prettyDOM } from './public-utils-4WiYB3_6.js';
|
|
3
3
|
import 'vitest/utils';
|