@vitest/browser 2.0.0-beta.3 → 2.0.0-beta.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/context.d.ts +8 -0
- package/dist/client/.vite/manifest.json +24 -0
- package/dist/client/__vitest__/assets/index-B74JATHR.css +1 -0
- package/dist/client/__vitest__/assets/index-BoV0brgU.js +51 -0
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/orchestrator-CEB54dI4.js +192 -0
- package/dist/client/__vitest_browser__/{rpc-Hw6RY18C.js → rpc-DBukiZYG.js} +217 -416
- package/dist/client/__vitest_browser__/{tester-Ly7RLJnN.js → tester-C3Mchfpf.js} +246 -33
- package/dist/client/esm-client-injector.js +12 -28
- package/dist/client/{index.html → orchestrator.html} +8 -7
- package/dist/client/tester.html +4 -3
- package/dist/index.js +243 -258
- package/package.json +9 -7
- package/dist/client/__vitest__/assets/index-C576npev.css +0 -1
- package/dist/client/__vitest__/assets/index-DBVixaI-.js +0 -51
- package/dist/client/__vitest_browser__/main-uRgy0zc4.js +0 -102
|
@@ -4,12 +4,6 @@ function __vite__mapDeps(indexes) {
|
|
|
4
4
|
}
|
|
5
5
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
6
6
|
}
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __publicField = (obj, key, value) => {
|
|
10
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
-
return value;
|
|
12
|
-
};
|
|
13
7
|
(function polyfill() {
|
|
14
8
|
const relList = document.createElement("link").relList;
|
|
15
9
|
if (relList && relList.supports && relList.supports("modulepreload")) {
|
|
@@ -51,6 +45,124 @@ var __publicField = (obj, key, value) => {
|
|
|
51
45
|
fetch(link.href, fetchOpts);
|
|
52
46
|
}
|
|
53
47
|
})();
|
|
48
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
49
|
+
function normalizeWindowsPath(input = "") {
|
|
50
|
+
if (!input) {
|
|
51
|
+
return input;
|
|
52
|
+
}
|
|
53
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
54
|
+
}
|
|
55
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
56
|
+
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
57
|
+
function cwd() {
|
|
58
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
59
|
+
return process.cwd().replace(/\\/g, "/");
|
|
60
|
+
}
|
|
61
|
+
return "/";
|
|
62
|
+
}
|
|
63
|
+
const resolve = function(...arguments_) {
|
|
64
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
65
|
+
let resolvedPath = "";
|
|
66
|
+
let resolvedAbsolute = false;
|
|
67
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
68
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
69
|
+
if (!path || path.length === 0) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
73
|
+
resolvedAbsolute = isAbsolute(path);
|
|
74
|
+
}
|
|
75
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
76
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
77
|
+
return `/${resolvedPath}`;
|
|
78
|
+
}
|
|
79
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
80
|
+
};
|
|
81
|
+
function normalizeString(path, allowAboveRoot) {
|
|
82
|
+
let res = "";
|
|
83
|
+
let lastSegmentLength = 0;
|
|
84
|
+
let lastSlash = -1;
|
|
85
|
+
let dots = 0;
|
|
86
|
+
let char = null;
|
|
87
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
88
|
+
if (index < path.length) {
|
|
89
|
+
char = path[index];
|
|
90
|
+
} else if (char === "/") {
|
|
91
|
+
break;
|
|
92
|
+
} else {
|
|
93
|
+
char = "/";
|
|
94
|
+
}
|
|
95
|
+
if (char === "/") {
|
|
96
|
+
if (lastSlash === index - 1 || dots === 1)
|
|
97
|
+
;
|
|
98
|
+
else if (dots === 2) {
|
|
99
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
100
|
+
if (res.length > 2) {
|
|
101
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
102
|
+
if (lastSlashIndex === -1) {
|
|
103
|
+
res = "";
|
|
104
|
+
lastSegmentLength = 0;
|
|
105
|
+
} else {
|
|
106
|
+
res = res.slice(0, lastSlashIndex);
|
|
107
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
108
|
+
}
|
|
109
|
+
lastSlash = index;
|
|
110
|
+
dots = 0;
|
|
111
|
+
continue;
|
|
112
|
+
} else if (res.length > 0) {
|
|
113
|
+
res = "";
|
|
114
|
+
lastSegmentLength = 0;
|
|
115
|
+
lastSlash = index;
|
|
116
|
+
dots = 0;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (allowAboveRoot) {
|
|
121
|
+
res += res.length > 0 ? "/.." : "..";
|
|
122
|
+
lastSegmentLength = 2;
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
if (res.length > 0) {
|
|
126
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
127
|
+
} else {
|
|
128
|
+
res = path.slice(lastSlash + 1, index);
|
|
129
|
+
}
|
|
130
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
131
|
+
}
|
|
132
|
+
lastSlash = index;
|
|
133
|
+
dots = 0;
|
|
134
|
+
} else if (char === "." && dots !== -1) {
|
|
135
|
+
++dots;
|
|
136
|
+
} else {
|
|
137
|
+
dots = -1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return res;
|
|
141
|
+
}
|
|
142
|
+
const isAbsolute = function(p) {
|
|
143
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
144
|
+
};
|
|
145
|
+
const _EXTNAME_RE = /.(\.[^./]+)$/;
|
|
146
|
+
const extname = function(p) {
|
|
147
|
+
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
148
|
+
return match && match[1] || "";
|
|
149
|
+
};
|
|
150
|
+
const relative = function(from, to) {
|
|
151
|
+
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
152
|
+
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
153
|
+
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
|
|
154
|
+
return _to.join("/");
|
|
155
|
+
}
|
|
156
|
+
const _fromCopy = [..._from];
|
|
157
|
+
for (const segment of _fromCopy) {
|
|
158
|
+
if (_to[0] !== segment) {
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
_from.shift();
|
|
162
|
+
_to.shift();
|
|
163
|
+
}
|
|
164
|
+
return [..._from.map(() => ".."), ..._to].join("/");
|
|
165
|
+
};
|
|
54
166
|
const DEFAULT_TIMEOUT = 6e4;
|
|
55
167
|
function defaultSerialize(i) {
|
|
56
168
|
return i;
|
|
@@ -225,410 +337,6 @@ const stringify = (value, replacer, space) => {
|
|
|
225
337
|
return after;
|
|
226
338
|
}
|
|
227
339
|
};
|
|
228
|
-
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
229
|
-
function normalizeWindowsPath(input = "") {
|
|
230
|
-
if (!input) {
|
|
231
|
-
return input;
|
|
232
|
-
}
|
|
233
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
234
|
-
}
|
|
235
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
236
|
-
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
237
|
-
function cwd() {
|
|
238
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
239
|
-
return process.cwd().replace(/\\/g, "/");
|
|
240
|
-
}
|
|
241
|
-
return "/";
|
|
242
|
-
}
|
|
243
|
-
const resolve = function(...arguments_) {
|
|
244
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
245
|
-
let resolvedPath = "";
|
|
246
|
-
let resolvedAbsolute = false;
|
|
247
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
248
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
249
|
-
if (!path || path.length === 0) {
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
253
|
-
resolvedAbsolute = isAbsolute(path);
|
|
254
|
-
}
|
|
255
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
256
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
257
|
-
return `/${resolvedPath}`;
|
|
258
|
-
}
|
|
259
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
260
|
-
};
|
|
261
|
-
function normalizeString(path, allowAboveRoot) {
|
|
262
|
-
let res = "";
|
|
263
|
-
let lastSegmentLength = 0;
|
|
264
|
-
let lastSlash = -1;
|
|
265
|
-
let dots = 0;
|
|
266
|
-
let char = null;
|
|
267
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
268
|
-
if (index < path.length) {
|
|
269
|
-
char = path[index];
|
|
270
|
-
} else if (char === "/") {
|
|
271
|
-
break;
|
|
272
|
-
} else {
|
|
273
|
-
char = "/";
|
|
274
|
-
}
|
|
275
|
-
if (char === "/") {
|
|
276
|
-
if (lastSlash === index - 1 || dots === 1)
|
|
277
|
-
;
|
|
278
|
-
else if (dots === 2) {
|
|
279
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
280
|
-
if (res.length > 2) {
|
|
281
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
282
|
-
if (lastSlashIndex === -1) {
|
|
283
|
-
res = "";
|
|
284
|
-
lastSegmentLength = 0;
|
|
285
|
-
} else {
|
|
286
|
-
res = res.slice(0, lastSlashIndex);
|
|
287
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
288
|
-
}
|
|
289
|
-
lastSlash = index;
|
|
290
|
-
dots = 0;
|
|
291
|
-
continue;
|
|
292
|
-
} else if (res.length > 0) {
|
|
293
|
-
res = "";
|
|
294
|
-
lastSegmentLength = 0;
|
|
295
|
-
lastSlash = index;
|
|
296
|
-
dots = 0;
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (allowAboveRoot) {
|
|
301
|
-
res += res.length > 0 ? "/.." : "..";
|
|
302
|
-
lastSegmentLength = 2;
|
|
303
|
-
}
|
|
304
|
-
} else {
|
|
305
|
-
if (res.length > 0) {
|
|
306
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
307
|
-
} else {
|
|
308
|
-
res = path.slice(lastSlash + 1, index);
|
|
309
|
-
}
|
|
310
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
311
|
-
}
|
|
312
|
-
lastSlash = index;
|
|
313
|
-
dots = 0;
|
|
314
|
-
} else if (char === "." && dots !== -1) {
|
|
315
|
-
++dots;
|
|
316
|
-
} else {
|
|
317
|
-
dots = -1;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return res;
|
|
321
|
-
}
|
|
322
|
-
const isAbsolute = function(p) {
|
|
323
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
324
|
-
};
|
|
325
|
-
const relative = function(from, to) {
|
|
326
|
-
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
327
|
-
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
328
|
-
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
|
|
329
|
-
return _to.join("/");
|
|
330
|
-
}
|
|
331
|
-
const _fromCopy = [..._from];
|
|
332
|
-
for (const segment of _fromCopy) {
|
|
333
|
-
if (_to[0] !== segment) {
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
_from.shift();
|
|
337
|
-
_to.shift();
|
|
338
|
-
}
|
|
339
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
340
|
-
};
|
|
341
|
-
function generateHash(str) {
|
|
342
|
-
let hash = 0;
|
|
343
|
-
if (str.length === 0)
|
|
344
|
-
return `${hash}`;
|
|
345
|
-
for (let i = 0; i < str.length; i++) {
|
|
346
|
-
const char = str.charCodeAt(i);
|
|
347
|
-
hash = (hash << 5) - hash + char;
|
|
348
|
-
hash = hash & hash;
|
|
349
|
-
}
|
|
350
|
-
return `${hash}`;
|
|
351
|
-
}
|
|
352
|
-
function createFileTask(filepath, root, projectName) {
|
|
353
|
-
const path = relative(root, filepath);
|
|
354
|
-
const file = {
|
|
355
|
-
id: generateHash(`${path}${projectName || ""}`),
|
|
356
|
-
name: path,
|
|
357
|
-
type: "suite",
|
|
358
|
-
mode: "run",
|
|
359
|
-
filepath,
|
|
360
|
-
tasks: [],
|
|
361
|
-
meta: /* @__PURE__ */ Object.create(null),
|
|
362
|
-
projectName,
|
|
363
|
-
file: void 0
|
|
364
|
-
};
|
|
365
|
-
file.file = file;
|
|
366
|
-
return file;
|
|
367
|
-
}
|
|
368
|
-
function isAggregateError(err) {
|
|
369
|
-
if (typeof AggregateError !== "undefined" && err instanceof AggregateError)
|
|
370
|
-
return true;
|
|
371
|
-
return err instanceof Error && "errors" in err;
|
|
372
|
-
}
|
|
373
|
-
class StateManager {
|
|
374
|
-
constructor() {
|
|
375
|
-
__publicField(this, "filesMap", /* @__PURE__ */ new Map());
|
|
376
|
-
__publicField(this, "pathsSet", /* @__PURE__ */ new Set());
|
|
377
|
-
__publicField(this, "idMap", /* @__PURE__ */ new Map());
|
|
378
|
-
__publicField(this, "taskFileMap", /* @__PURE__ */ new WeakMap());
|
|
379
|
-
__publicField(this, "errorsSet", /* @__PURE__ */ new Set());
|
|
380
|
-
__publicField(this, "processTimeoutCauses", /* @__PURE__ */ new Set());
|
|
381
|
-
}
|
|
382
|
-
catchError(err, type) {
|
|
383
|
-
if (isAggregateError(err))
|
|
384
|
-
return err.errors.forEach((error) => this.catchError(error, type));
|
|
385
|
-
if (err === Object(err))
|
|
386
|
-
err.type = type;
|
|
387
|
-
else
|
|
388
|
-
err = { type, message: err };
|
|
389
|
-
const _err = err;
|
|
390
|
-
if (_err && typeof _err === "object" && _err.code === "VITEST_PENDING") {
|
|
391
|
-
const task = this.idMap.get(_err.taskId);
|
|
392
|
-
if (task) {
|
|
393
|
-
task.mode = "skip";
|
|
394
|
-
task.result ?? (task.result = { state: "skip" });
|
|
395
|
-
task.result.state = "skip";
|
|
396
|
-
}
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
this.errorsSet.add(err);
|
|
400
|
-
}
|
|
401
|
-
clearErrors() {
|
|
402
|
-
this.errorsSet.clear();
|
|
403
|
-
}
|
|
404
|
-
getUnhandledErrors() {
|
|
405
|
-
return Array.from(this.errorsSet.values());
|
|
406
|
-
}
|
|
407
|
-
addProcessTimeoutCause(cause) {
|
|
408
|
-
this.processTimeoutCauses.add(cause);
|
|
409
|
-
}
|
|
410
|
-
getProcessTimeoutCauses() {
|
|
411
|
-
return Array.from(this.processTimeoutCauses.values());
|
|
412
|
-
}
|
|
413
|
-
getPaths() {
|
|
414
|
-
return Array.from(this.pathsSet);
|
|
415
|
-
}
|
|
416
|
-
getFiles(keys2) {
|
|
417
|
-
if (keys2)
|
|
418
|
-
return keys2.map((key) => this.filesMap.get(key)).filter(Boolean).flat();
|
|
419
|
-
return Array.from(this.filesMap.values()).flat();
|
|
420
|
-
}
|
|
421
|
-
getFilepaths() {
|
|
422
|
-
return Array.from(this.filesMap.keys());
|
|
423
|
-
}
|
|
424
|
-
getFailedFilepaths() {
|
|
425
|
-
return this.getFiles().filter((i) => {
|
|
426
|
-
var _a;
|
|
427
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
428
|
-
}).map((i) => i.filepath);
|
|
429
|
-
}
|
|
430
|
-
collectPaths(paths = []) {
|
|
431
|
-
paths.forEach((path) => {
|
|
432
|
-
this.pathsSet.add(path);
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
collectFiles(files = []) {
|
|
436
|
-
files.forEach((file) => {
|
|
437
|
-
const existing = this.filesMap.get(file.filepath) || [];
|
|
438
|
-
const otherProject = existing.filter((i) => i.projectName !== file.projectName);
|
|
439
|
-
const currentFile = existing.find((i) => i.projectName === file.projectName);
|
|
440
|
-
if (currentFile)
|
|
441
|
-
file.logs = currentFile.logs;
|
|
442
|
-
otherProject.push(file);
|
|
443
|
-
this.filesMap.set(file.filepath, otherProject);
|
|
444
|
-
this.updateId(file);
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
// this file is reused by ws-client, and shoult not rely on heavy dependencies like workspace
|
|
448
|
-
clearFiles(_project, paths = []) {
|
|
449
|
-
const project = _project;
|
|
450
|
-
paths.forEach((path) => {
|
|
451
|
-
const files = this.filesMap.get(path);
|
|
452
|
-
const fileTask = createFileTask(path, project.config.root, project.config.name);
|
|
453
|
-
this.idMap.set(fileTask.id, fileTask);
|
|
454
|
-
if (!files) {
|
|
455
|
-
this.filesMap.set(path, [fileTask]);
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
const filtered = files.filter((file) => file.projectName !== project.config.name);
|
|
459
|
-
if (!filtered.length) {
|
|
460
|
-
this.filesMap.set(path, [fileTask]);
|
|
461
|
-
} else {
|
|
462
|
-
this.filesMap.set(path, [
|
|
463
|
-
...filtered,
|
|
464
|
-
fileTask
|
|
465
|
-
]);
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
updateId(task) {
|
|
470
|
-
if (this.idMap.get(task.id) === task)
|
|
471
|
-
return;
|
|
472
|
-
this.idMap.set(task.id, task);
|
|
473
|
-
if (task.type === "suite") {
|
|
474
|
-
task.tasks.forEach((task2) => {
|
|
475
|
-
this.updateId(task2);
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
updateTasks(packs) {
|
|
480
|
-
for (const [id, result, meta] of packs) {
|
|
481
|
-
const task = this.idMap.get(id);
|
|
482
|
-
if (task) {
|
|
483
|
-
task.result = result;
|
|
484
|
-
task.meta = meta;
|
|
485
|
-
if ((result == null ? void 0 : result.state) === "skip")
|
|
486
|
-
task.mode = "skip";
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
updateUserLog(log) {
|
|
491
|
-
const task = log.taskId && this.idMap.get(log.taskId);
|
|
492
|
-
if (task) {
|
|
493
|
-
if (!task.logs)
|
|
494
|
-
task.logs = [];
|
|
495
|
-
task.logs.push(log);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
getCountOfFailedTests() {
|
|
499
|
-
return Array.from(this.idMap.values()).filter((t) => {
|
|
500
|
-
var _a;
|
|
501
|
-
return ((_a = t.result) == null ? void 0 : _a.state) === "fail";
|
|
502
|
-
}).length;
|
|
503
|
-
}
|
|
504
|
-
cancelFiles(files, root, projectName) {
|
|
505
|
-
this.collectFiles(files.map((filepath) => createFileTask(filepath, root, projectName)));
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
function createClient(url, options = {}) {
|
|
509
|
-
const {
|
|
510
|
-
handlers = {},
|
|
511
|
-
autoReconnect = true,
|
|
512
|
-
reconnectInterval = 2e3,
|
|
513
|
-
reconnectTries = 10,
|
|
514
|
-
connectTimeout = 6e4,
|
|
515
|
-
reactive = (v) => v,
|
|
516
|
-
WebSocketConstructor = globalThis.WebSocket
|
|
517
|
-
} = options;
|
|
518
|
-
let tries = reconnectTries;
|
|
519
|
-
const ctx = reactive({
|
|
520
|
-
ws: new WebSocketConstructor(url),
|
|
521
|
-
state: new StateManager(),
|
|
522
|
-
waitForConnection,
|
|
523
|
-
reconnect
|
|
524
|
-
});
|
|
525
|
-
ctx.state.filesMap = reactive(ctx.state.filesMap);
|
|
526
|
-
ctx.state.idMap = reactive(ctx.state.idMap);
|
|
527
|
-
let onMessage;
|
|
528
|
-
const functions = {
|
|
529
|
-
onSpecsCollected(specs) {
|
|
530
|
-
var _a;
|
|
531
|
-
specs == null ? void 0 : specs.forEach(([config, file]) => {
|
|
532
|
-
ctx.state.clearFiles({ config }, [file]);
|
|
533
|
-
});
|
|
534
|
-
(_a = handlers.onSpecsCollected) == null ? void 0 : _a.call(handlers, specs);
|
|
535
|
-
},
|
|
536
|
-
onPathsCollected(paths) {
|
|
537
|
-
var _a;
|
|
538
|
-
ctx.state.collectPaths(paths);
|
|
539
|
-
(_a = handlers.onPathsCollected) == null ? void 0 : _a.call(handlers, paths);
|
|
540
|
-
},
|
|
541
|
-
onCollected(files) {
|
|
542
|
-
var _a;
|
|
543
|
-
ctx.state.collectFiles(files);
|
|
544
|
-
(_a = handlers.onCollected) == null ? void 0 : _a.call(handlers, files);
|
|
545
|
-
},
|
|
546
|
-
onTaskUpdate(packs) {
|
|
547
|
-
var _a;
|
|
548
|
-
ctx.state.updateTasks(packs);
|
|
549
|
-
(_a = handlers.onTaskUpdate) == null ? void 0 : _a.call(handlers, packs);
|
|
550
|
-
},
|
|
551
|
-
onUserConsoleLog(log) {
|
|
552
|
-
var _a;
|
|
553
|
-
ctx.state.updateUserLog(log);
|
|
554
|
-
(_a = handlers.onUserConsoleLog) == null ? void 0 : _a.call(handlers, log);
|
|
555
|
-
},
|
|
556
|
-
onFinished(files, errors) {
|
|
557
|
-
var _a;
|
|
558
|
-
(_a = handlers.onFinished) == null ? void 0 : _a.call(handlers, files, errors);
|
|
559
|
-
},
|
|
560
|
-
onFinishedReportCoverage() {
|
|
561
|
-
var _a;
|
|
562
|
-
(_a = handlers.onFinishedReportCoverage) == null ? void 0 : _a.call(handlers);
|
|
563
|
-
},
|
|
564
|
-
onCancel(reason) {
|
|
565
|
-
var _a;
|
|
566
|
-
(_a = handlers.onCancel) == null ? void 0 : _a.call(handlers, reason);
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
const birpcHandlers = {
|
|
570
|
-
post: (msg) => ctx.ws.send(msg),
|
|
571
|
-
on: (fn) => onMessage = fn,
|
|
572
|
-
serialize: stringify,
|
|
573
|
-
deserialize: parse,
|
|
574
|
-
onTimeoutError(functionName) {
|
|
575
|
-
throw new Error(`[vitest-ws-client]: Timeout calling "${functionName}"`);
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
ctx.rpc = createBirpc(
|
|
579
|
-
functions,
|
|
580
|
-
birpcHandlers
|
|
581
|
-
);
|
|
582
|
-
let openPromise;
|
|
583
|
-
function reconnect(reset = false) {
|
|
584
|
-
if (reset)
|
|
585
|
-
tries = reconnectTries;
|
|
586
|
-
ctx.ws = new WebSocketConstructor(url);
|
|
587
|
-
registerWS();
|
|
588
|
-
}
|
|
589
|
-
function registerWS() {
|
|
590
|
-
openPromise = new Promise((resolve2, reject) => {
|
|
591
|
-
var _a, _b;
|
|
592
|
-
const timeout = (_b = (_a = setTimeout(() => {
|
|
593
|
-
reject(new Error(`Cannot connect to the server in ${connectTimeout / 1e3} seconds`));
|
|
594
|
-
}, connectTimeout)) == null ? void 0 : _a.unref) == null ? void 0 : _b.call(_a);
|
|
595
|
-
if (ctx.ws.OPEN === ctx.ws.readyState)
|
|
596
|
-
resolve2();
|
|
597
|
-
ctx.ws.addEventListener("open", () => {
|
|
598
|
-
tries = reconnectTries;
|
|
599
|
-
resolve2();
|
|
600
|
-
clearTimeout(timeout);
|
|
601
|
-
});
|
|
602
|
-
});
|
|
603
|
-
ctx.ws.addEventListener("message", (v) => {
|
|
604
|
-
onMessage(v.data);
|
|
605
|
-
});
|
|
606
|
-
ctx.ws.addEventListener("close", () => {
|
|
607
|
-
tries -= 1;
|
|
608
|
-
if (autoReconnect && tries > 0)
|
|
609
|
-
setTimeout(reconnect, reconnectInterval);
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
registerWS();
|
|
613
|
-
function waitForConnection() {
|
|
614
|
-
return openPromise;
|
|
615
|
-
}
|
|
616
|
-
return ctx;
|
|
617
|
-
}
|
|
618
|
-
const PORT = location.port;
|
|
619
|
-
const HOST = [location.hostname, PORT].filter(Boolean).join(":");
|
|
620
|
-
const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_api__`;
|
|
621
|
-
let setCancel = (_) => {
|
|
622
|
-
};
|
|
623
|
-
const onCancel = new Promise((resolve2) => {
|
|
624
|
-
setCancel = resolve2;
|
|
625
|
-
});
|
|
626
|
-
const client = createClient(ENTRY_URL, {
|
|
627
|
-
handlers: {
|
|
628
|
-
onCancel: setCancel
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
const channel = new BroadcastChannel("vitest");
|
|
632
340
|
const scriptRel = "modulepreload";
|
|
633
341
|
const assetsURL = function(dep) {
|
|
634
342
|
return "/" + dep;
|
|
@@ -680,7 +388,7 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
|
|
|
680
388
|
};
|
|
681
389
|
async function importId(id) {
|
|
682
390
|
const name = `${getConfig().base || "/"}@id/${id}`;
|
|
683
|
-
return getBrowserState().wrapModule(__vitePreload(() => import(name), true ? __vite__mapDeps([]) : void 0));
|
|
391
|
+
return getBrowserState().wrapModule(() => __vitePreload(() => import(name), true ? __vite__mapDeps([]) : void 0));
|
|
684
392
|
}
|
|
685
393
|
function getConfig() {
|
|
686
394
|
return getBrowserState().config;
|
|
@@ -688,6 +396,97 @@ function getConfig() {
|
|
|
688
396
|
function getBrowserState() {
|
|
689
397
|
return window.__vitest_browser_runner__;
|
|
690
398
|
}
|
|
399
|
+
const PAGE_TYPE = getBrowserState().type;
|
|
400
|
+
const PORT = location.port;
|
|
401
|
+
const HOST = [location.hostname, PORT].filter(Boolean).join(":");
|
|
402
|
+
const SESSION_ID = crypto.randomUUID();
|
|
403
|
+
const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&sessionId=${SESSION_ID}`;
|
|
404
|
+
let setCancel = (_) => {
|
|
405
|
+
};
|
|
406
|
+
const onCancel = new Promise((resolve2) => {
|
|
407
|
+
setCancel = resolve2;
|
|
408
|
+
});
|
|
409
|
+
function createClient() {
|
|
410
|
+
const reconnectInterval = 2e3;
|
|
411
|
+
const reconnectTries = 10;
|
|
412
|
+
const connectTimeout = 6e4;
|
|
413
|
+
let tries = reconnectTries;
|
|
414
|
+
const ctx = {
|
|
415
|
+
ws: new WebSocket(ENTRY_URL),
|
|
416
|
+
waitForConnection
|
|
417
|
+
};
|
|
418
|
+
let onMessage;
|
|
419
|
+
ctx.rpc = createBirpc({
|
|
420
|
+
onCancel: setCancel,
|
|
421
|
+
async startMocking(id) {
|
|
422
|
+
if (typeof __vitest_mocker__ === "undefined")
|
|
423
|
+
throw new Error(`Cannot mock modules in the orchestrator process`);
|
|
424
|
+
const mocker = __vitest_mocker__;
|
|
425
|
+
const exports = await mocker.resolve(id);
|
|
426
|
+
return Object.keys(exports);
|
|
427
|
+
},
|
|
428
|
+
async createTesters(files) {
|
|
429
|
+
var _a, _b;
|
|
430
|
+
if (PAGE_TYPE !== "orchestrator")
|
|
431
|
+
return;
|
|
432
|
+
(_b = (_a = getBrowserState()).createTesters) == null ? void 0 : _b.call(_a, files);
|
|
433
|
+
}
|
|
434
|
+
}, {
|
|
435
|
+
post: (msg) => ctx.ws.send(msg),
|
|
436
|
+
on: (fn) => onMessage = fn,
|
|
437
|
+
serialize: (e) => stringify(e, (_, v) => {
|
|
438
|
+
if (v instanceof Error) {
|
|
439
|
+
return {
|
|
440
|
+
name: v.name,
|
|
441
|
+
message: v.message,
|
|
442
|
+
stack: v.stack
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
return v;
|
|
446
|
+
}),
|
|
447
|
+
deserialize: parse,
|
|
448
|
+
onTimeoutError(functionName) {
|
|
449
|
+
throw new Error(`[vitest-browser]: Timeout calling "${functionName}"`);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
let openPromise;
|
|
453
|
+
function reconnect(reset = false) {
|
|
454
|
+
if (reset)
|
|
455
|
+
tries = reconnectTries;
|
|
456
|
+
ctx.ws = new WebSocket(ENTRY_URL);
|
|
457
|
+
registerWS();
|
|
458
|
+
}
|
|
459
|
+
function registerWS() {
|
|
460
|
+
openPromise = new Promise((resolve2, reject) => {
|
|
461
|
+
var _a, _b;
|
|
462
|
+
const timeout = (_b = (_a = setTimeout(() => {
|
|
463
|
+
reject(new Error(`Cannot connect to the server in ${connectTimeout / 1e3} seconds`));
|
|
464
|
+
}, connectTimeout)) == null ? void 0 : _a.unref) == null ? void 0 : _b.call(_a);
|
|
465
|
+
if (ctx.ws.OPEN === ctx.ws.readyState)
|
|
466
|
+
resolve2();
|
|
467
|
+
ctx.ws.addEventListener("open", () => {
|
|
468
|
+
tries = reconnectTries;
|
|
469
|
+
resolve2();
|
|
470
|
+
clearTimeout(timeout);
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
ctx.ws.addEventListener("message", (v) => {
|
|
474
|
+
onMessage(v.data);
|
|
475
|
+
});
|
|
476
|
+
ctx.ws.addEventListener("close", () => {
|
|
477
|
+
tries -= 1;
|
|
478
|
+
if (tries > 0)
|
|
479
|
+
setTimeout(reconnect, reconnectInterval);
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
registerWS();
|
|
483
|
+
function waitForConnection() {
|
|
484
|
+
return openPromise;
|
|
485
|
+
}
|
|
486
|
+
return ctx;
|
|
487
|
+
}
|
|
488
|
+
const client = createClient();
|
|
489
|
+
const channel = new BroadcastChannel("vitest");
|
|
691
490
|
const { get } = Reflect;
|
|
692
491
|
function withSafeTimers(getTimers, fn) {
|
|
693
492
|
const { setTimeout: setTimeout2, clearTimeout: clearTimeout2, setImmediate, clearImmediate } = getTimers();
|
|
@@ -745,13 +544,15 @@ function rpc() {
|
|
|
745
544
|
}
|
|
746
545
|
export {
|
|
747
546
|
__vitePreload as _,
|
|
748
|
-
|
|
749
|
-
|
|
547
|
+
channel as a,
|
|
548
|
+
getConfig as b,
|
|
750
549
|
client as c,
|
|
751
|
-
|
|
752
|
-
|
|
550
|
+
rpcDone as d,
|
|
551
|
+
rpc as e,
|
|
552
|
+
extname as f,
|
|
553
|
+
getBrowserState as g,
|
|
753
554
|
importId as i,
|
|
754
555
|
loadSafeRpc as l,
|
|
755
556
|
onCancel as o,
|
|
756
|
-
|
|
557
|
+
relative as r
|
|
757
558
|
};
|