@vitest/browser 1.5.2 → 1.6.0
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/dist/client/__vitest__/assets/{index-TejngHZE.js → index-TpLatVz2.js} +20 -20
- package/dist/client/__vitest__/index.html +1 -1
- package/dist/client/__vitest_browser__/{tester-h3GciVI8.js → tester-RmfypyZ0.js} +19 -12
- package/dist/client/index.html +1 -0
- package/dist/client/tester.html +2 -1
- package/dist/index.js +75 -3
- package/package.json +7 -7
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
})()
|
|
18
18
|
</script>
|
|
19
19
|
<!-- !LOAD_METADATA! -->
|
|
20
|
-
<script type="module" crossorigin src="./assets/index-
|
|
20
|
+
<script type="module" crossorigin src="./assets/index-TpLatVz2.js"></script>
|
|
21
21
|
<link rel="stylesheet" crossorigin href="./assets/index-fUmMsp0O.css">
|
|
22
22
|
</head>
|
|
23
23
|
<body>
|
|
@@ -10,7 +10,7 @@ var __publicField = (obj, key, value) => {
|
|
|
10
10
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
11
|
return value;
|
|
12
12
|
};
|
|
13
|
-
import { i as importId, d as rpc, g as getConfig, _ as __vitePreload, b as channel, a as getBrowserState, c as client, l as loadSafeRpc, o as onCancel } from "./rpc-slP7oy1q.js";
|
|
13
|
+
import { i as importId, d as rpc$1, g as getConfig, _ as __vitePreload, b as channel, a as getBrowserState, c as client, l as loadSafeRpc, o as onCancel } from "./rpc-slP7oy1q.js";
|
|
14
14
|
function showPopupWarning(name, value, defaultValue) {
|
|
15
15
|
return (...params) => {
|
|
16
16
|
const formatedParams = params.map((p) => JSON.stringify(p)).join(", ");
|
|
@@ -48,7 +48,7 @@ async function setupConsoleLogSpy() {
|
|
|
48
48
|
return;
|
|
49
49
|
const unknownTestId = "__vitest__unknown_test__";
|
|
50
50
|
const taskId = ((_b = (_a = globalThis.__vitest_worker__) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
51
|
-
rpc().sendLog({
|
|
51
|
+
rpc$1().sendLog({
|
|
52
52
|
content,
|
|
53
53
|
time: Date$1.now(),
|
|
54
54
|
taskId,
|
|
@@ -121,7 +121,7 @@ ${stack}`);
|
|
|
121
121
|
return countReset(label);
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
-
class
|
|
124
|
+
class VitestBrowserSnapshotEnvironment {
|
|
125
125
|
getVersion() {
|
|
126
126
|
return "1";
|
|
127
127
|
}
|
|
@@ -144,6 +144,9 @@ class BrowserSnapshotEnvironment {
|
|
|
144
144
|
return rpc().removeSnapshotFile(filepath);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
+
function rpc() {
|
|
148
|
+
return globalThis.__vitest_worker__.rpc;
|
|
149
|
+
}
|
|
147
150
|
const browserHashMap = /* @__PURE__ */ new Map();
|
|
148
151
|
function createBrowserRunner(runnerClass, coverageModule) {
|
|
149
152
|
return class BrowserTestRunner extends runnerClass {
|
|
@@ -155,10 +158,10 @@ function createBrowserRunner(runnerClass, coverageModule) {
|
|
|
155
158
|
var _a, _b, _c;
|
|
156
159
|
await ((_a = super.onAfterRunTask) == null ? void 0 : _a.call(this, task));
|
|
157
160
|
if (this.config.bail && ((_b = task.result) == null ? void 0 : _b.state) === "fail") {
|
|
158
|
-
const previousFailures = await rpc().getCountOfFailedTests();
|
|
161
|
+
const previousFailures = await rpc$1().getCountOfFailedTests();
|
|
159
162
|
const currentFailures = 1 + previousFailures;
|
|
160
163
|
if (currentFailures >= this.config.bail) {
|
|
161
|
-
rpc().onCancel("test-failure");
|
|
164
|
+
rpc$1().onCancel("test-failure");
|
|
162
165
|
(_c = this.onCancel) == null ? void 0 : _c.call(this, "test-failure");
|
|
163
166
|
}
|
|
164
167
|
}
|
|
@@ -168,7 +171,7 @@ function createBrowserRunner(runnerClass, coverageModule) {
|
|
|
168
171
|
await ((_a = super.onAfterRunFiles) == null ? void 0 : _a.call(this, files));
|
|
169
172
|
const coverage = await ((_b = coverageModule == null ? void 0 : coverageModule.takeCoverage) == null ? void 0 : _b.call(coverageModule));
|
|
170
173
|
if (coverage) {
|
|
171
|
-
await rpc().onAfterSuiteRun({
|
|
174
|
+
await rpc$1().onAfterSuiteRun({
|
|
172
175
|
coverage,
|
|
173
176
|
transformMode: "web",
|
|
174
177
|
projectName: this.config.name
|
|
@@ -182,10 +185,10 @@ function createBrowserRunner(runnerClass, coverageModule) {
|
|
|
182
185
|
} catch (_) {
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
|
-
return rpc().onCollected(files);
|
|
188
|
+
return rpc$1().onCollected(files);
|
|
186
189
|
});
|
|
187
190
|
__publicField(this, "onTaskUpdate", (task) => {
|
|
188
|
-
return rpc().onTaskUpdate(task);
|
|
191
|
+
return rpc$1().onTaskUpdate(task);
|
|
189
192
|
});
|
|
190
193
|
__publicField(this, "importFile", async (filepath) => {
|
|
191
194
|
let [test, hash] = this.hashMap.get(filepath) ?? [false, ""];
|
|
@@ -208,15 +211,19 @@ async function initiateRunner() {
|
|
|
208
211
|
if (cachedRunner)
|
|
209
212
|
return cachedRunner;
|
|
210
213
|
const config = getConfig();
|
|
211
|
-
const [
|
|
214
|
+
const [
|
|
215
|
+
{ VitestTestRunner, NodeBenchmarkRunner },
|
|
216
|
+
{ takeCoverageInsideWorker, loadDiffConfig, loadSnapshotSerializers }
|
|
217
|
+
] = await Promise.all([
|
|
212
218
|
importId("vitest/runners"),
|
|
213
219
|
importId("vitest/browser")
|
|
214
220
|
]);
|
|
215
|
-
const
|
|
221
|
+
const runnerClass = config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
222
|
+
const BrowserRunner = createBrowserRunner(runnerClass, {
|
|
216
223
|
takeCoverage: () => takeCoverageInsideWorker(config.coverage, { executeId: importId })
|
|
217
224
|
});
|
|
218
225
|
if (!config.snapshotOptions.snapshotEnvironment)
|
|
219
|
-
config.snapshotOptions.snapshotEnvironment = new
|
|
226
|
+
config.snapshotOptions.snapshotEnvironment = new VitestBrowserSnapshotEnvironment();
|
|
220
227
|
const runner = new BrowserRunner({
|
|
221
228
|
config
|
|
222
229
|
});
|
|
@@ -233,7 +240,7 @@ async function updateFilesLocations(files) {
|
|
|
233
240
|
const { loadSourceMapUtils } = await importId("vitest/utils");
|
|
234
241
|
const { TraceMap, originalPositionFor } = await loadSourceMapUtils();
|
|
235
242
|
const promises = files.map(async (file) => {
|
|
236
|
-
const result = await rpc().getBrowserFileSourceMap(file.filepath);
|
|
243
|
+
const result = await rpc$1().getBrowserFileSourceMap(file.filepath);
|
|
237
244
|
if (!result)
|
|
238
245
|
return null;
|
|
239
246
|
const traceMap = new TraceMap(result);
|
package/dist/client/index.html
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
</style>
|
|
24
24
|
<script>{__VITEST_INJECTOR__}</script>
|
|
25
|
+
{__VITEST_SCRIPTS__}
|
|
25
26
|
<script type="module" crossorigin src="/__vitest_browser__/main-v2hiOVax.js"></script>
|
|
26
27
|
<link rel="modulepreload" crossorigin href="/__vitest_browser__/rpc-slP7oy1q.js">
|
|
27
28
|
</head>
|
package/dist/client/tester.html
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
}
|
|
17
17
|
</style>
|
|
18
18
|
<script>{__VITEST_INJECTOR__}</script>
|
|
19
|
-
|
|
19
|
+
{__VITEST_SCRIPTS__}
|
|
20
|
+
<script type="module" crossorigin src="/__vitest_browser__/tester-RmfypyZ0.js"></script>
|
|
20
21
|
<link rel="modulepreload" crossorigin href="/__vitest_browser__/rpc-slP7oy1q.js">
|
|
21
22
|
</head>
|
|
22
23
|
<body>
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import sirv from 'sirv';
|
|
4
4
|
import { coverageConfigDefaults } from 'vitest/config';
|
|
5
|
+
import { slash } from '@vitest/utils';
|
|
5
6
|
import MagicString from 'magic-string';
|
|
6
7
|
import { esmWalker } from '@vitest/utils/ast';
|
|
7
8
|
|
|
@@ -11,7 +12,58 @@ function normalizeWindowsPath(input = "") {
|
|
|
11
12
|
}
|
|
12
13
|
return input.replace(/\\/g, "/");
|
|
13
14
|
}
|
|
15
|
+
|
|
16
|
+
const _UNC_REGEX = /^[/\\]{2}/;
|
|
14
17
|
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
18
|
+
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
19
|
+
const normalize = function(path) {
|
|
20
|
+
if (path.length === 0) {
|
|
21
|
+
return ".";
|
|
22
|
+
}
|
|
23
|
+
path = normalizeWindowsPath(path);
|
|
24
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
25
|
+
const isPathAbsolute = isAbsolute(path);
|
|
26
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
27
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
28
|
+
if (path.length === 0) {
|
|
29
|
+
if (isPathAbsolute) {
|
|
30
|
+
return "/";
|
|
31
|
+
}
|
|
32
|
+
return trailingSeparator ? "./" : ".";
|
|
33
|
+
}
|
|
34
|
+
if (trailingSeparator) {
|
|
35
|
+
path += "/";
|
|
36
|
+
}
|
|
37
|
+
if (_DRIVE_LETTER_RE.test(path)) {
|
|
38
|
+
path += "/";
|
|
39
|
+
}
|
|
40
|
+
if (isUNCPath) {
|
|
41
|
+
if (!isPathAbsolute) {
|
|
42
|
+
return `//./${path}`;
|
|
43
|
+
}
|
|
44
|
+
return `//${path}`;
|
|
45
|
+
}
|
|
46
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
47
|
+
};
|
|
48
|
+
const join = function(...arguments_) {
|
|
49
|
+
if (arguments_.length === 0) {
|
|
50
|
+
return ".";
|
|
51
|
+
}
|
|
52
|
+
let joined;
|
|
53
|
+
for (const argument of arguments_) {
|
|
54
|
+
if (argument && argument.length > 0) {
|
|
55
|
+
if (joined === void 0) {
|
|
56
|
+
joined = argument;
|
|
57
|
+
} else {
|
|
58
|
+
joined += `/${argument}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (joined === void 0) {
|
|
63
|
+
return ".";
|
|
64
|
+
}
|
|
65
|
+
return normalize(joined.replace(/\/\/+/g, "/"));
|
|
66
|
+
};
|
|
15
67
|
function cwd() {
|
|
16
68
|
if (typeof process !== "undefined") {
|
|
17
69
|
return process.cwd().replace(/\\/g, "/");
|
|
@@ -345,9 +397,6 @@ export { ${viInjectedKey} }`);
|
|
|
345
397
|
};
|
|
346
398
|
}
|
|
347
399
|
|
|
348
|
-
function replacer(code, values) {
|
|
349
|
-
return code.replace(/{\s*(\w+)\s*}/g, (_, key) => values[key] ?? "");
|
|
350
|
-
}
|
|
351
400
|
var index = (project, base = "/") => {
|
|
352
401
|
const pkgRoot = resolve(fileURLToPath(import.meta.url), "../..");
|
|
353
402
|
const distRoot = resolve(pkgRoot, "dist");
|
|
@@ -376,6 +425,8 @@ var index = (project, base = "/") => {
|
|
|
376
425
|
}
|
|
377
426
|
next();
|
|
378
427
|
});
|
|
428
|
+
let indexScripts;
|
|
429
|
+
let testerScripts;
|
|
379
430
|
server.middlewares.use(async (req, res, next) => {
|
|
380
431
|
if (!req.url)
|
|
381
432
|
return next();
|
|
@@ -393,9 +444,12 @@ var index = (project, base = "/") => {
|
|
|
393
444
|
__VITEST_FILES__: JSON.stringify(files)
|
|
394
445
|
});
|
|
395
446
|
if (url.pathname === base) {
|
|
447
|
+
if (!indexScripts)
|
|
448
|
+
indexScripts = await formatScripts(project.config.browser.indexScripts, server);
|
|
396
449
|
const html2 = replacer(await runnerHtml, {
|
|
397
450
|
__VITEST_FAVICON__: favicon,
|
|
398
451
|
__VITEST_TITLE__: "Vitest Browser Runner",
|
|
452
|
+
__VITEST_SCRIPTS__: indexScripts,
|
|
399
453
|
__VITEST_INJECTOR__: injector
|
|
400
454
|
});
|
|
401
455
|
res.write(html2, "utf-8");
|
|
@@ -404,9 +458,12 @@ var index = (project, base = "/") => {
|
|
|
404
458
|
}
|
|
405
459
|
const decodedTestFile = decodeURIComponent(url.pathname.slice(testerPrefix.length));
|
|
406
460
|
const tests = decodedTestFile === "__vitest_all__" || !files.includes(decodedTestFile) ? "__vitest_browser_runner__.files" : JSON.stringify([decodedTestFile]);
|
|
461
|
+
if (!testerScripts)
|
|
462
|
+
testerScripts = await formatScripts(project.config.browser.testerScripts, server);
|
|
407
463
|
const html = replacer(await testerHtml, {
|
|
408
464
|
__VITEST_FAVICON__: favicon,
|
|
409
465
|
__VITEST_TITLE__: "Vitest Browser Tester",
|
|
466
|
+
__VITEST_SCRIPTS__: testerScripts,
|
|
410
467
|
__VITEST_INJECTOR__: injector,
|
|
411
468
|
__VITEST_APPEND__: (
|
|
412
469
|
// TODO: have only a single global variable to not pollute the global scope
|
|
@@ -541,5 +598,20 @@ function wrapConfig(config) {
|
|
|
541
598
|
testNamePattern: config.testNamePattern ? config.testNamePattern.toString() : void 0
|
|
542
599
|
};
|
|
543
600
|
}
|
|
601
|
+
function replacer(code, values) {
|
|
602
|
+
return code.replace(/{\s*(\w+)\s*}/g, (_, key) => values[key] ?? "");
|
|
603
|
+
}
|
|
604
|
+
async function formatScripts(scripts, server) {
|
|
605
|
+
if (!scripts?.length)
|
|
606
|
+
return "";
|
|
607
|
+
const promises = scripts.map(async ({ content, src, async, id, type = "module" }, index) => {
|
|
608
|
+
const srcLink = (src ? (await server.pluginContainer.resolveId(src))?.id : void 0) || src;
|
|
609
|
+
const transformId = srcLink || join(server.config.root, `virtual__${id || `injected-${index}.js`}`);
|
|
610
|
+
await server.moduleGraph.ensureEntryFromUrl(transformId);
|
|
611
|
+
const contentProcessed = content && type === "module" ? (await server.pluginContainer.transform(content, transformId)).code : content;
|
|
612
|
+
return `<script type="${type}"${async ? " async" : ""}${srcLink ? ` src="${slash(`/@fs/${srcLink}`)}"` : ""}>${contentProcessed || ""}<\/script>`;
|
|
613
|
+
});
|
|
614
|
+
return (await Promise.all(promises)).join("\n");
|
|
615
|
+
}
|
|
544
616
|
|
|
545
617
|
export { index as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.0",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"playwright": "*",
|
|
45
45
|
"webdriverio": "*",
|
|
46
|
-
"vitest": "1.
|
|
46
|
+
"vitest": "1.6.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"playwright": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"magic-string": "^0.30.5",
|
|
61
61
|
"sirv": "^2.0.4",
|
|
62
|
-
"@vitest/utils": "1.
|
|
62
|
+
"@vitest/utils": "1.6.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/ws": "^8.5.9",
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
"playwright-core": "^1.41.0",
|
|
70
70
|
"safaridriver": "^0.1.2",
|
|
71
71
|
"webdriverio": "^8.32.2",
|
|
72
|
-
"@vitest/runner": "1.
|
|
73
|
-
"@vitest/
|
|
74
|
-
"@vitest/
|
|
75
|
-
"vitest": "1.
|
|
72
|
+
"@vitest/runner": "1.6.0",
|
|
73
|
+
"@vitest/ui": "1.6.0",
|
|
74
|
+
"@vitest/ws-client": "1.6.0",
|
|
75
|
+
"vitest": "1.6.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "rimraf dist && pnpm build:node && pnpm build:client",
|