@vitest/browser 2.1.4 → 2.1.5
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/README.md +7 -21
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-NReaboR_.js → orchestrator-DnP17K36.js} +5 -117
- package/dist/client/__vitest_browser__/{tester-CAAquV6P.js → tester-BaiNqOPw.js} +1251 -2
- package/dist/client/__vitest_browser__/utils-Owv5OOOf.js +195 -0
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -13
- package/dist/context.js +74 -34
- package/dist/{index-Cgg35wOd.js → index-CKtADM3n.js} +35 -3
- package/dist/index.js +55 -16
- package/dist/locators/index.js +1 -1
- package/dist/locators/playwright.js +1 -1
- package/dist/locators/preview.js +10 -10
- package/dist/locators/webdriverio.js +1 -1
- package/dist/providers.js +8 -7
- package/package.json +13 -13
- package/dist/client/__vitest_browser__/utils-CUwLt_eT.js +0 -81
package/README.md
CHANGED
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
# @vitest/browser
|
|
2
2
|
|
|
3
|
-
Browser runner for Vitest.
|
|
3
|
+
[Browser runner](https://vitest.dev/guide/browser/) for Vitest.
|
|
4
4
|
|
|
5
5
|
> ⚠️ This package is **experimental**. While this package will be released along with other packages, it will not follow SemVer for breaking changes until we mark it as ready.
|
|
6
6
|
|
|
7
|
-
## Progress
|
|
8
|
-
|
|
9
|
-
Current Status: **Working in progress**
|
|
10
|
-
|
|
11
|
-
- [x] Init package and integration
|
|
12
|
-
- [x] Stub node packages for Vitest runtime
|
|
13
|
-
- [x] Works in development mode
|
|
14
|
-
- [x] Better log in terminal
|
|
15
|
-
- [x] Fulfill tests (using Browser only APIs, Vue and React components)
|
|
16
|
-
- [ ] Show progress and error on the browser page
|
|
17
|
-
- [x] Headless mode in CI
|
|
18
|
-
- [x] Docs
|
|
19
|
-
|
|
20
|
-
Related PRs
|
|
21
|
-
|
|
22
|
-
- [#1302](https://github.com/vitest-dev/vitest/pull/1302)
|
|
23
|
-
|
|
24
7
|
## Development Setup
|
|
25
8
|
|
|
26
9
|
At project root:
|
|
27
10
|
|
|
28
11
|
```bash
|
|
29
|
-
pnpm dev
|
|
30
|
-
|
|
31
12
|
cd test/browser
|
|
32
|
-
|
|
13
|
+
# runs relevant tests for the browser mode
|
|
14
|
+
# useful to confirm everything works fine
|
|
15
|
+
pnpm test
|
|
16
|
+
# runs tests as the browser mode
|
|
17
|
+
# useful during development
|
|
18
|
+
pnpm test-fixtures
|
|
33
19
|
```
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_utils-
|
|
3
|
-
"file": "__vitest_browser__/utils-
|
|
2
|
+
"_utils-Owv5OOOf.js": {
|
|
3
|
+
"file": "__vitest_browser__/utils-Owv5OOOf.js",
|
|
4
4
|
"name": "utils"
|
|
5
5
|
},
|
|
6
6
|
"orchestrator.html": {
|
|
7
|
-
"file": "__vitest_browser__/orchestrator-
|
|
7
|
+
"file": "__vitest_browser__/orchestrator-DnP17K36.js",
|
|
8
8
|
"name": "orchestrator",
|
|
9
9
|
"src": "orchestrator.html",
|
|
10
10
|
"isEntry": true,
|
|
11
11
|
"imports": [
|
|
12
|
-
"_utils-
|
|
12
|
+
"_utils-Owv5OOOf.js"
|
|
13
13
|
]
|
|
14
14
|
},
|
|
15
15
|
"tester/tester.html": {
|
|
16
|
-
"file": "__vitest_browser__/tester-
|
|
16
|
+
"file": "__vitest_browser__/tester-BaiNqOPw.js",
|
|
17
17
|
"name": "tester",
|
|
18
18
|
"src": "tester/tester.html",
|
|
19
19
|
"isEntry": true,
|
|
20
20
|
"imports": [
|
|
21
|
-
"_utils-
|
|
21
|
+
"_utils-Owv5OOOf.js"
|
|
22
22
|
]
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
})();
|
|
24
24
|
</script>
|
|
25
25
|
<!-- !LOAD_METADATA! -->
|
|
26
|
-
<script type="module"
|
|
27
|
-
<link rel="stylesheet"
|
|
26
|
+
<script type="module" src="./assets/index-DWjHzG4O.js"></script>
|
|
27
|
+
<link rel="stylesheet" href="./assets/index-CGSAdLIf.css">
|
|
28
28
|
</head>
|
|
29
29
|
<body>
|
|
30
30
|
<div id="app"></div>
|
package/dist/client/__vitest_browser__/{orchestrator-NReaboR_.js → orchestrator-DnP17K36.js}
RENAMED
|
@@ -1,120 +1,8 @@
|
|
|
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 } from "./utils-
|
|
4
|
+
import { g as getBrowserState, a as getConfig, r as relative } from "./utils-Owv5OOOf.js";
|
|
5
5
|
import { client, channel, globalChannel } from "@vitest/browser/client";
|
|
6
|
-
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
7
|
-
function normalizeWindowsPath(input = "") {
|
|
8
|
-
if (!input) {
|
|
9
|
-
return input;
|
|
10
|
-
}
|
|
11
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
12
|
-
}
|
|
13
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
14
|
-
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
15
|
-
function cwd() {
|
|
16
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
17
|
-
return process.cwd().replace(/\\/g, "/");
|
|
18
|
-
}
|
|
19
|
-
return "/";
|
|
20
|
-
}
|
|
21
|
-
const resolve = function(...arguments_) {
|
|
22
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
23
|
-
let resolvedPath = "";
|
|
24
|
-
let resolvedAbsolute = false;
|
|
25
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
26
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
27
|
-
if (!path || path.length === 0) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
31
|
-
resolvedAbsolute = isAbsolute(path);
|
|
32
|
-
}
|
|
33
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
34
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
35
|
-
return `/${resolvedPath}`;
|
|
36
|
-
}
|
|
37
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
38
|
-
};
|
|
39
|
-
function normalizeString(path, allowAboveRoot) {
|
|
40
|
-
let res = "";
|
|
41
|
-
let lastSegmentLength = 0;
|
|
42
|
-
let lastSlash = -1;
|
|
43
|
-
let dots = 0;
|
|
44
|
-
let char = null;
|
|
45
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
46
|
-
if (index < path.length) {
|
|
47
|
-
char = path[index];
|
|
48
|
-
} else if (char === "/") {
|
|
49
|
-
break;
|
|
50
|
-
} else {
|
|
51
|
-
char = "/";
|
|
52
|
-
}
|
|
53
|
-
if (char === "/") {
|
|
54
|
-
if (lastSlash === index - 1 || dots === 1) ;
|
|
55
|
-
else if (dots === 2) {
|
|
56
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
57
|
-
if (res.length > 2) {
|
|
58
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
59
|
-
if (lastSlashIndex === -1) {
|
|
60
|
-
res = "";
|
|
61
|
-
lastSegmentLength = 0;
|
|
62
|
-
} else {
|
|
63
|
-
res = res.slice(0, lastSlashIndex);
|
|
64
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
65
|
-
}
|
|
66
|
-
lastSlash = index;
|
|
67
|
-
dots = 0;
|
|
68
|
-
continue;
|
|
69
|
-
} else if (res.length > 0) {
|
|
70
|
-
res = "";
|
|
71
|
-
lastSegmentLength = 0;
|
|
72
|
-
lastSlash = index;
|
|
73
|
-
dots = 0;
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (allowAboveRoot) {
|
|
78
|
-
res += res.length > 0 ? "/.." : "..";
|
|
79
|
-
lastSegmentLength = 2;
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
if (res.length > 0) {
|
|
83
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
84
|
-
} else {
|
|
85
|
-
res = path.slice(lastSlash + 1, index);
|
|
86
|
-
}
|
|
87
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
88
|
-
}
|
|
89
|
-
lastSlash = index;
|
|
90
|
-
dots = 0;
|
|
91
|
-
} else if (char === "." && dots !== -1) {
|
|
92
|
-
++dots;
|
|
93
|
-
} else {
|
|
94
|
-
dots = -1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return res;
|
|
98
|
-
}
|
|
99
|
-
const isAbsolute = function(p) {
|
|
100
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
101
|
-
};
|
|
102
|
-
const relative = function(from, to) {
|
|
103
|
-
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
104
|
-
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
105
|
-
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
|
|
106
|
-
return _to.join("/");
|
|
107
|
-
}
|
|
108
|
-
const _fromCopy = [..._from];
|
|
109
|
-
for (const segment of _fromCopy) {
|
|
110
|
-
if (_to[0] !== segment) {
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
_from.shift();
|
|
114
|
-
_to.shift();
|
|
115
|
-
}
|
|
116
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
117
|
-
};
|
|
118
6
|
function generateHash(str) {
|
|
119
7
|
let hash = 0;
|
|
120
8
|
if (str.length === 0) {
|
|
@@ -178,13 +66,13 @@ class IframeOrchestrator {
|
|
|
178
66
|
}
|
|
179
67
|
const iframe = this.createIframe(container, file);
|
|
180
68
|
await setIframeViewport(iframe, width, height);
|
|
181
|
-
await new Promise((
|
|
69
|
+
await new Promise((resolve) => {
|
|
182
70
|
channel.addEventListener(
|
|
183
71
|
"message",
|
|
184
72
|
function handler(e) {
|
|
185
73
|
if (e.data.type === "done" || e.data.type === "error") {
|
|
186
74
|
channel.removeEventListener("message", handler);
|
|
187
|
-
|
|
75
|
+
resolve();
|
|
188
76
|
}
|
|
189
77
|
}
|
|
190
78
|
);
|
|
@@ -310,9 +198,9 @@ async function getContainer(config) {
|
|
|
310
198
|
if (config.browser.ui) {
|
|
311
199
|
const element = document.querySelector("#tester-ui");
|
|
312
200
|
if (!element) {
|
|
313
|
-
return new Promise((
|
|
201
|
+
return new Promise((resolve) => {
|
|
314
202
|
setTimeout(() => {
|
|
315
|
-
|
|
203
|
+
resolve(getContainer(config));
|
|
316
204
|
}, 30);
|
|
317
205
|
});
|
|
318
206
|
}
|