@vitest/browser 1.6.0 → 2.0.0-beta.10

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.
@@ -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,174 @@ 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 _UNC_REGEX = /^[/\\]{2}/;
56
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
57
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
58
+ const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
59
+ const normalize = function(path) {
60
+ if (path.length === 0) {
61
+ return ".";
62
+ }
63
+ path = normalizeWindowsPath(path);
64
+ const isUNCPath = path.match(_UNC_REGEX);
65
+ const isPathAbsolute = isAbsolute(path);
66
+ const trailingSeparator = path[path.length - 1] === "/";
67
+ path = normalizeString(path, !isPathAbsolute);
68
+ if (path.length === 0) {
69
+ if (isPathAbsolute) {
70
+ return "/";
71
+ }
72
+ return trailingSeparator ? "./" : ".";
73
+ }
74
+ if (trailingSeparator) {
75
+ path += "/";
76
+ }
77
+ if (_DRIVE_LETTER_RE.test(path)) {
78
+ path += "/";
79
+ }
80
+ if (isUNCPath) {
81
+ if (!isPathAbsolute) {
82
+ return `//./${path}`;
83
+ }
84
+ return `//${path}`;
85
+ }
86
+ return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
87
+ };
88
+ const join = function(...arguments_) {
89
+ if (arguments_.length === 0) {
90
+ return ".";
91
+ }
92
+ let joined;
93
+ for (const argument of arguments_) {
94
+ if (argument && argument.length > 0) {
95
+ if (joined === void 0) {
96
+ joined = argument;
97
+ } else {
98
+ joined += `/${argument}`;
99
+ }
100
+ }
101
+ }
102
+ if (joined === void 0) {
103
+ return ".";
104
+ }
105
+ return normalize(joined.replace(/\/\/+/g, "/"));
106
+ };
107
+ function cwd() {
108
+ if (typeof process !== "undefined" && typeof process.cwd === "function") {
109
+ return process.cwd().replace(/\\/g, "/");
110
+ }
111
+ return "/";
112
+ }
113
+ const resolve = function(...arguments_) {
114
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
115
+ let resolvedPath = "";
116
+ let resolvedAbsolute = false;
117
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
118
+ const path = index >= 0 ? arguments_[index] : cwd();
119
+ if (!path || path.length === 0) {
120
+ continue;
121
+ }
122
+ resolvedPath = `${path}/${resolvedPath}`;
123
+ resolvedAbsolute = isAbsolute(path);
124
+ }
125
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
126
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
127
+ return `/${resolvedPath}`;
128
+ }
129
+ return resolvedPath.length > 0 ? resolvedPath : ".";
130
+ };
131
+ function normalizeString(path, allowAboveRoot) {
132
+ let res = "";
133
+ let lastSegmentLength = 0;
134
+ let lastSlash = -1;
135
+ let dots = 0;
136
+ let char = null;
137
+ for (let index = 0; index <= path.length; ++index) {
138
+ if (index < path.length) {
139
+ char = path[index];
140
+ } else if (char === "/") {
141
+ break;
142
+ } else {
143
+ char = "/";
144
+ }
145
+ if (char === "/") {
146
+ if (lastSlash === index - 1 || dots === 1)
147
+ ;
148
+ else if (dots === 2) {
149
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
150
+ if (res.length > 2) {
151
+ const lastSlashIndex = res.lastIndexOf("/");
152
+ if (lastSlashIndex === -1) {
153
+ res = "";
154
+ lastSegmentLength = 0;
155
+ } else {
156
+ res = res.slice(0, lastSlashIndex);
157
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
158
+ }
159
+ lastSlash = index;
160
+ dots = 0;
161
+ continue;
162
+ } else if (res.length > 0) {
163
+ res = "";
164
+ lastSegmentLength = 0;
165
+ lastSlash = index;
166
+ dots = 0;
167
+ continue;
168
+ }
169
+ }
170
+ if (allowAboveRoot) {
171
+ res += res.length > 0 ? "/.." : "..";
172
+ lastSegmentLength = 2;
173
+ }
174
+ } else {
175
+ if (res.length > 0) {
176
+ res += `/${path.slice(lastSlash + 1, index)}`;
177
+ } else {
178
+ res = path.slice(lastSlash + 1, index);
179
+ }
180
+ lastSegmentLength = index - lastSlash - 1;
181
+ }
182
+ lastSlash = index;
183
+ dots = 0;
184
+ } else if (char === "." && dots !== -1) {
185
+ ++dots;
186
+ } else {
187
+ dots = -1;
188
+ }
189
+ }
190
+ return res;
191
+ }
192
+ const isAbsolute = function(p) {
193
+ return _IS_ABSOLUTE_RE.test(p);
194
+ };
195
+ const _EXTNAME_RE = /.(\.[^./]+)$/;
196
+ const extname = function(p) {
197
+ const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
198
+ return match && match[1] || "";
199
+ };
200
+ const relative = function(from, to) {
201
+ const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
202
+ const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
203
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
204
+ return _to.join("/");
205
+ }
206
+ const _fromCopy = [..._from];
207
+ for (const segment of _fromCopy) {
208
+ if (_to[0] !== segment) {
209
+ break;
210
+ }
211
+ _from.shift();
212
+ _to.shift();
213
+ }
214
+ return [..._from.map(() => ".."), ..._to].join("/");
215
+ };
54
216
  const DEFAULT_TIMEOUT = 6e4;
55
217
  function defaultSerialize(i) {
56
218
  return i;
@@ -74,6 +236,8 @@ function createBirpc(functions, options) {
74
236
  get(_, method) {
75
237
  if (method === "$functions")
76
238
  return functions;
239
+ if (method === "then" && !eventNames.includes("then") && !("then" in functions))
240
+ return void 0;
77
241
  const sendEvent = (...args) => {
78
242
  post(serialize({ m: method, a: args, t: "q" }));
79
243
  };
@@ -84,11 +248,11 @@ function createBirpc(functions, options) {
84
248
  const sendCall = async (...args) => {
85
249
  await _promise;
86
250
  return new Promise((resolve2, reject) => {
87
- var _a, _b;
251
+ var _a;
88
252
  const id = nanoid();
89
253
  let timeoutId;
90
254
  if (timeout >= 0) {
91
- timeoutId = (_b = (_a = setTimeout$1(() => {
255
+ timeoutId = setTimeout$1(() => {
92
256
  var _a2;
93
257
  try {
94
258
  (_a2 = options.onTimeoutError) == null ? void 0 : _a2.call(options, method, args);
@@ -97,7 +261,9 @@ function createBirpc(functions, options) {
97
261
  reject(e);
98
262
  }
99
263
  rpcPromiseMap.delete(id);
100
- }, timeout)).unref) == null ? void 0 : _b.call(_a);
264
+ }, timeout);
265
+ if (typeof timeoutId === "object")
266
+ timeoutId = (_a = timeoutId.unref) == null ? void 0 : _a.call(timeoutId);
101
267
  }
102
268
  rpcPromiseMap.set(id, { resolve: resolve2, reject, timeoutId });
103
269
  post(serialize({ m: method, a: args, i: id, t: "q" }));
@@ -150,7 +316,6 @@ function nanoid(size = 21) {
150
316
  id += urlAlphabet[random() * 64 | 0];
151
317
  return id;
152
318
  }
153
- /*! (c) 2020 Andrea Giammarchi */
154
319
  const { parse: $parse, stringify: $stringify } = JSON;
155
320
  const { keys } = Object;
156
321
  const Primitive = String;
@@ -222,371 +387,6 @@ const stringify = (value, replacer, space) => {
222
387
  return after;
223
388
  }
224
389
  };
225
- function normalizeWindowsPath(input = "") {
226
- if (!input || !input.includes("\\")) {
227
- return input;
228
- }
229
- return input.replace(/\\/g, "/");
230
- }
231
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
232
- function cwd() {
233
- if (typeof process !== "undefined") {
234
- return process.cwd().replace(/\\/g, "/");
235
- }
236
- return "/";
237
- }
238
- const resolve = function(...arguments_) {
239
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
240
- let resolvedPath = "";
241
- let resolvedAbsolute = false;
242
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
243
- const path = index >= 0 ? arguments_[index] : cwd();
244
- if (!path || path.length === 0) {
245
- continue;
246
- }
247
- resolvedPath = `${path}/${resolvedPath}`;
248
- resolvedAbsolute = isAbsolute(path);
249
- }
250
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
251
- if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
252
- return `/${resolvedPath}`;
253
- }
254
- return resolvedPath.length > 0 ? resolvedPath : ".";
255
- };
256
- function normalizeString(path, allowAboveRoot) {
257
- let res = "";
258
- let lastSegmentLength = 0;
259
- let lastSlash = -1;
260
- let dots = 0;
261
- let char = null;
262
- for (let index = 0; index <= path.length; ++index) {
263
- if (index < path.length) {
264
- char = path[index];
265
- } else if (char === "/") {
266
- break;
267
- } else {
268
- char = "/";
269
- }
270
- if (char === "/") {
271
- if (lastSlash === index - 1 || dots === 1)
272
- ;
273
- else if (dots === 2) {
274
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
275
- if (res.length > 2) {
276
- const lastSlashIndex = res.lastIndexOf("/");
277
- if (lastSlashIndex === -1) {
278
- res = "";
279
- lastSegmentLength = 0;
280
- } else {
281
- res = res.slice(0, lastSlashIndex);
282
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
283
- }
284
- lastSlash = index;
285
- dots = 0;
286
- continue;
287
- } else if (res.length > 0) {
288
- res = "";
289
- lastSegmentLength = 0;
290
- lastSlash = index;
291
- dots = 0;
292
- continue;
293
- }
294
- }
295
- if (allowAboveRoot) {
296
- res += res.length > 0 ? "/.." : "..";
297
- lastSegmentLength = 2;
298
- }
299
- } else {
300
- if (res.length > 0) {
301
- res += `/${path.slice(lastSlash + 1, index)}`;
302
- } else {
303
- res = path.slice(lastSlash + 1, index);
304
- }
305
- lastSegmentLength = index - lastSlash - 1;
306
- }
307
- lastSlash = index;
308
- dots = 0;
309
- } else if (char === "." && dots !== -1) {
310
- ++dots;
311
- } else {
312
- dots = -1;
313
- }
314
- }
315
- return res;
316
- }
317
- const isAbsolute = function(p) {
318
- return _IS_ABSOLUTE_RE.test(p);
319
- };
320
- const relative = function(from, to) {
321
- const _from = resolve(from).split("/");
322
- const _to = resolve(to).split("/");
323
- const _fromCopy = [..._from];
324
- for (const segment of _fromCopy) {
325
- if (_to[0] !== segment) {
326
- break;
327
- }
328
- _from.shift();
329
- _to.shift();
330
- }
331
- return [..._from.map(() => ".."), ..._to].join("/");
332
- };
333
- function isAggregateError(err) {
334
- if (typeof AggregateError !== "undefined" && err instanceof AggregateError)
335
- return true;
336
- return err instanceof Error && "errors" in err;
337
- }
338
- class StateManager {
339
- constructor() {
340
- __publicField(this, "filesMap", /* @__PURE__ */ new Map());
341
- __publicField(this, "pathsSet", /* @__PURE__ */ new Set());
342
- __publicField(this, "idMap", /* @__PURE__ */ new Map());
343
- __publicField(this, "taskFileMap", /* @__PURE__ */ new WeakMap());
344
- __publicField(this, "errorsSet", /* @__PURE__ */ new Set());
345
- __publicField(this, "processTimeoutCauses", /* @__PURE__ */ new Set());
346
- }
347
- catchError(err, type) {
348
- if (isAggregateError(err))
349
- return err.errors.forEach((error) => this.catchError(error, type));
350
- if (err === Object(err))
351
- err.type = type;
352
- else
353
- err = { type, message: err };
354
- const _err = err;
355
- if (_err && typeof _err === "object" && _err.code === "VITEST_PENDING") {
356
- const task = this.idMap.get(_err.taskId);
357
- if (task) {
358
- task.mode = "skip";
359
- task.result ?? (task.result = { state: "skip" });
360
- task.result.state = "skip";
361
- }
362
- return;
363
- }
364
- this.errorsSet.add(err);
365
- }
366
- clearErrors() {
367
- this.errorsSet.clear();
368
- }
369
- getUnhandledErrors() {
370
- return Array.from(this.errorsSet.values());
371
- }
372
- addProcessTimeoutCause(cause) {
373
- this.processTimeoutCauses.add(cause);
374
- }
375
- getProcessTimeoutCauses() {
376
- return Array.from(this.processTimeoutCauses.values());
377
- }
378
- getPaths() {
379
- return Array.from(this.pathsSet);
380
- }
381
- getFiles(keys2) {
382
- if (keys2)
383
- return keys2.map((key) => this.filesMap.get(key)).filter(Boolean).flat();
384
- return Array.from(this.filesMap.values()).flat();
385
- }
386
- getFilepaths() {
387
- return Array.from(this.filesMap.keys());
388
- }
389
- getFailedFilepaths() {
390
- return this.getFiles().filter((i) => {
391
- var _a;
392
- return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
393
- }).map((i) => i.filepath);
394
- }
395
- collectPaths(paths = []) {
396
- paths.forEach((path) => {
397
- this.pathsSet.add(path);
398
- });
399
- }
400
- collectFiles(files = []) {
401
- files.forEach((file) => {
402
- const existing = this.filesMap.get(file.filepath) || [];
403
- const otherProject = existing.filter((i) => i.projectName !== file.projectName);
404
- otherProject.push(file);
405
- this.filesMap.set(file.filepath, otherProject);
406
- this.updateId(file);
407
- });
408
- }
409
- // this file is reused by ws-client, and shoult not rely on heavy dependencies like workspace
410
- clearFiles(_project, paths = []) {
411
- const project = _project;
412
- paths.forEach((path) => {
413
- const files = this.filesMap.get(path);
414
- if (!files)
415
- return;
416
- const filtered = files.filter((file) => file.projectName !== project.config.name);
417
- if (!filtered.length)
418
- this.filesMap.delete(path);
419
- else
420
- this.filesMap.set(path, filtered);
421
- });
422
- }
423
- updateId(task) {
424
- if (this.idMap.get(task.id) === task)
425
- return;
426
- this.idMap.set(task.id, task);
427
- if (task.type === "suite") {
428
- task.tasks.forEach((task2) => {
429
- this.updateId(task2);
430
- });
431
- }
432
- }
433
- updateTasks(packs) {
434
- for (const [id, result, meta] of packs) {
435
- const task = this.idMap.get(id);
436
- if (task) {
437
- task.result = result;
438
- task.meta = meta;
439
- if ((result == null ? void 0 : result.state) === "skip")
440
- task.mode = "skip";
441
- }
442
- }
443
- }
444
- updateUserLog(log) {
445
- const task = log.taskId && this.idMap.get(log.taskId);
446
- if (task) {
447
- if (!task.logs)
448
- task.logs = [];
449
- task.logs.push(log);
450
- }
451
- }
452
- getCountOfFailedTests() {
453
- return Array.from(this.idMap.values()).filter((t) => {
454
- var _a;
455
- return ((_a = t.result) == null ? void 0 : _a.state) === "fail";
456
- }).length;
457
- }
458
- cancelFiles(files, root, projectName) {
459
- this.collectFiles(files.map((filepath) => ({
460
- filepath,
461
- name: relative(root, filepath),
462
- id: filepath,
463
- mode: "skip",
464
- type: "suite",
465
- result: {
466
- state: "skip"
467
- },
468
- meta: {},
469
- // Cancelled files have not yet collected tests
470
- tasks: [],
471
- projectName
472
- })));
473
- }
474
- }
475
- function createClient(url, options = {}) {
476
- const {
477
- handlers = {},
478
- autoReconnect = true,
479
- reconnectInterval = 2e3,
480
- reconnectTries = 10,
481
- connectTimeout = 6e4,
482
- reactive = (v) => v,
483
- WebSocketConstructor = globalThis.WebSocket
484
- } = options;
485
- let tries = reconnectTries;
486
- const ctx = reactive({
487
- ws: new WebSocketConstructor(url),
488
- state: new StateManager(),
489
- waitForConnection,
490
- reconnect
491
- });
492
- ctx.state.filesMap = reactive(ctx.state.filesMap);
493
- ctx.state.idMap = reactive(ctx.state.idMap);
494
- let onMessage;
495
- const functions = {
496
- onPathsCollected(paths) {
497
- var _a;
498
- ctx.state.collectPaths(paths);
499
- (_a = handlers.onPathsCollected) == null ? void 0 : _a.call(handlers, paths);
500
- },
501
- onCollected(files) {
502
- var _a;
503
- ctx.state.collectFiles(files);
504
- (_a = handlers.onCollected) == null ? void 0 : _a.call(handlers, files);
505
- },
506
- onTaskUpdate(packs) {
507
- var _a;
508
- ctx.state.updateTasks(packs);
509
- (_a = handlers.onTaskUpdate) == null ? void 0 : _a.call(handlers, packs);
510
- },
511
- onUserConsoleLog(log) {
512
- ctx.state.updateUserLog(log);
513
- },
514
- onFinished(files, errors) {
515
- var _a;
516
- (_a = handlers.onFinished) == null ? void 0 : _a.call(handlers, files, errors);
517
- },
518
- onFinishedReportCoverage() {
519
- var _a;
520
- (_a = handlers.onFinishedReportCoverage) == null ? void 0 : _a.call(handlers);
521
- },
522
- onCancel(reason) {
523
- var _a;
524
- (_a = handlers.onCancel) == null ? void 0 : _a.call(handlers, reason);
525
- }
526
- };
527
- const birpcHandlers = {
528
- post: (msg) => ctx.ws.send(msg),
529
- on: (fn) => onMessage = fn,
530
- serialize: stringify,
531
- deserialize: parse,
532
- onTimeoutError(functionName) {
533
- throw new Error(`[vitest-ws-client]: Timeout calling "${functionName}"`);
534
- }
535
- };
536
- ctx.rpc = createBirpc(
537
- functions,
538
- birpcHandlers
539
- );
540
- let openPromise;
541
- function reconnect(reset = false) {
542
- if (reset)
543
- tries = reconnectTries;
544
- ctx.ws = new WebSocketConstructor(url);
545
- registerWS();
546
- }
547
- function registerWS() {
548
- openPromise = new Promise((resolve2, reject) => {
549
- var _a, _b;
550
- const timeout = (_b = (_a = setTimeout(() => {
551
- reject(new Error(`Cannot connect to the server in ${connectTimeout / 1e3} seconds`));
552
- }, connectTimeout)) == null ? void 0 : _a.unref) == null ? void 0 : _b.call(_a);
553
- if (ctx.ws.OPEN === ctx.ws.readyState)
554
- resolve2();
555
- ctx.ws.addEventListener("open", () => {
556
- tries = reconnectTries;
557
- resolve2();
558
- clearTimeout(timeout);
559
- });
560
- });
561
- ctx.ws.addEventListener("message", (v) => {
562
- onMessage(v.data);
563
- });
564
- ctx.ws.addEventListener("close", () => {
565
- tries -= 1;
566
- if (autoReconnect && tries > 0)
567
- setTimeout(reconnect, reconnectInterval);
568
- });
569
- }
570
- registerWS();
571
- function waitForConnection() {
572
- return openPromise;
573
- }
574
- return ctx;
575
- }
576
- const PORT = location.port;
577
- const HOST = [location.hostname, PORT].filter(Boolean).join(":");
578
- const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_api__`;
579
- let setCancel = (_) => {
580
- };
581
- const onCancel = new Promise((resolve2) => {
582
- setCancel = resolve2;
583
- });
584
- const client = createClient(ENTRY_URL, {
585
- handlers: {
586
- onCancel: setCancel
587
- }
588
- });
589
- const channel = new BroadcastChannel("vitest");
590
390
  const scriptRel = "modulepreload";
591
391
  const assetsURL = function(dep) {
592
392
  return "/" + dep;
@@ -595,7 +395,7 @@ const seen = {};
595
395
  const __vitePreload = function preload(baseModule, deps, importerUrl) {
596
396
  let promise = Promise.resolve();
597
397
  if (deps && deps.length > 0) {
598
- const links = document.getElementsByTagName("link");
398
+ document.getElementsByTagName("link");
599
399
  const cspNonceMeta = document.querySelector("meta[property=csp-nonce]");
600
400
  const cspNonce = (cspNonceMeta == null ? void 0 : cspNonceMeta.nonce) || (cspNonceMeta == null ? void 0 : cspNonceMeta.getAttribute("nonce"));
601
401
  promise = Promise.all(deps.map((dep) => {
@@ -605,15 +405,7 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
605
405
  seen[dep] = true;
606
406
  const isCss = dep.endsWith(".css");
607
407
  const cssSelector = isCss ? '[rel="stylesheet"]' : "";
608
- const isBaseRelative = !!importerUrl;
609
- if (isBaseRelative) {
610
- for (let i = links.length - 1; i >= 0; i--) {
611
- const link2 = links[i];
612
- if (link2.href === dep && (!isCss || link2.rel === "stylesheet")) {
613
- return;
614
- }
615
- }
616
- } else if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
408
+ if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
617
409
  return;
618
410
  }
619
411
  const link = document.createElement("link");
@@ -645,8 +437,8 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
645
437
  });
646
438
  };
647
439
  async function importId(id) {
648
- const name = `${getConfig().base || "/"}@id/${id}`;
649
- return getBrowserState().wrapModule(__vitePreload(() => import(name), true ? __vite__mapDeps([]) : void 0));
440
+ const name = `/@id/${id}`;
441
+ return getBrowserState().wrapModule(() => __vitePreload(() => import(name), true ? __vite__mapDeps([]) : void 0));
650
442
  }
651
443
  function getConfig() {
652
444
  return getBrowserState().config;
@@ -654,6 +446,106 @@ function getConfig() {
654
446
  function getBrowserState() {
655
447
  return window.__vitest_browser_runner__;
656
448
  }
449
+ const channel = new BroadcastChannel(`vitest:${getBrowserState().contextId}`);
450
+ function waitForChannel(event) {
451
+ return new Promise((resolve2) => {
452
+ channel.addEventListener("message", (e) => {
453
+ var _a;
454
+ if (((_a = e.data) == null ? void 0 : _a.type) === event)
455
+ resolve2();
456
+ }, { once: true });
457
+ });
458
+ }
459
+ const PAGE_TYPE = getBrowserState().type;
460
+ const PORT = location.port;
461
+ const HOST = [location.hostname, PORT].filter(Boolean).join(":");
462
+ const SESSION_ID = PAGE_TYPE === "orchestrator" ? getBrowserState().contextId : crypto.randomUUID();
463
+ const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/__vitest_browser_api__?type=${PAGE_TYPE}&sessionId=${SESSION_ID}`;
464
+ let setCancel = (_) => {
465
+ };
466
+ const onCancel = new Promise((resolve2) => {
467
+ setCancel = resolve2;
468
+ });
469
+ function createClient() {
470
+ const reconnectInterval = 2e3;
471
+ const reconnectTries = 10;
472
+ const connectTimeout = 6e4;
473
+ let tries = reconnectTries;
474
+ const ctx = {
475
+ ws: new WebSocket(ENTRY_URL),
476
+ waitForConnection
477
+ };
478
+ let onMessage;
479
+ ctx.rpc = createBirpc({
480
+ onCancel: setCancel,
481
+ async startMocking(id) {
482
+ if (typeof __vitest_mocker__ === "undefined")
483
+ throw new Error(`Cannot mock modules in the orchestrator process`);
484
+ const mocker = __vitest_mocker__;
485
+ const exports = await mocker.resolve(id);
486
+ return Object.keys(exports);
487
+ },
488
+ async createTesters(files) {
489
+ var _a, _b;
490
+ if (PAGE_TYPE !== "orchestrator")
491
+ return;
492
+ (_b = (_a = getBrowserState()).createTesters) == null ? void 0 : _b.call(_a, files);
493
+ }
494
+ }, {
495
+ post: (msg) => ctx.ws.send(msg),
496
+ on: (fn) => onMessage = fn,
497
+ serialize: (e) => stringify(e, (_, v) => {
498
+ if (v instanceof Error) {
499
+ return {
500
+ name: v.name,
501
+ message: v.message,
502
+ stack: v.stack
503
+ };
504
+ }
505
+ return v;
506
+ }),
507
+ deserialize: parse,
508
+ onTimeoutError(functionName) {
509
+ throw new Error(`[vitest-browser]: Timeout calling "${functionName}"`);
510
+ }
511
+ });
512
+ let openPromise;
513
+ function reconnect(reset = false) {
514
+ if (reset)
515
+ tries = reconnectTries;
516
+ ctx.ws = new WebSocket(ENTRY_URL);
517
+ registerWS();
518
+ }
519
+ function registerWS() {
520
+ openPromise = new Promise((resolve2, reject) => {
521
+ var _a, _b;
522
+ const timeout = (_b = (_a = setTimeout(() => {
523
+ reject(new Error(`Cannot connect to the server in ${connectTimeout / 1e3} seconds`));
524
+ }, connectTimeout)) == null ? void 0 : _a.unref) == null ? void 0 : _b.call(_a);
525
+ if (ctx.ws.OPEN === ctx.ws.readyState)
526
+ resolve2();
527
+ ctx.ws.addEventListener("open", () => {
528
+ tries = reconnectTries;
529
+ resolve2();
530
+ clearTimeout(timeout);
531
+ });
532
+ });
533
+ ctx.ws.addEventListener("message", (v) => {
534
+ onMessage(v.data);
535
+ });
536
+ ctx.ws.addEventListener("close", () => {
537
+ tries -= 1;
538
+ if (tries > 0)
539
+ setTimeout(reconnect, reconnectInterval);
540
+ });
541
+ }
542
+ registerWS();
543
+ function waitForConnection() {
544
+ return openPromise;
545
+ }
546
+ return ctx;
547
+ }
548
+ const client = createClient();
657
549
  const { get } = Reflect;
658
550
  function withSafeTimers(getTimers, fn) {
659
551
  const { setTimeout: setTimeout2, clearTimeout: clearTimeout2, setImmediate, clearImmediate } = getTimers();
@@ -711,13 +603,17 @@ function rpc() {
711
603
  }
712
604
  export {
713
605
  __vitePreload as _,
714
- getBrowserState as a,
715
- channel as b,
606
+ channel as a,
607
+ getConfig as b,
716
608
  client as c,
717
- rpc as d,
718
- getConfig as g,
609
+ rpcDone as d,
610
+ rpc as e,
611
+ extname as f,
612
+ getBrowserState as g,
719
613
  importId as i,
614
+ join as j,
720
615
  loadSafeRpc as l,
721
616
  onCancel as o,
722
- rpcDone as r
617
+ relative as r,
618
+ waitForChannel as w
723
619
  };