@vitest/browser 0.29.3 → 0.29.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.
@@ -242,6 +242,7 @@ class StateManager {
242
242
  this.idMap = /* @__PURE__ */ new Map();
243
243
  this.taskFileMap = /* @__PURE__ */ new WeakMap();
244
244
  this.errorsSet = /* @__PURE__ */ new Set();
245
+ this.processTimeoutCauses = /* @__PURE__ */ new Set();
245
246
  }
246
247
  catchError(err, type) {
247
248
  if (isAggregateError(err))
@@ -255,6 +256,12 @@ class StateManager {
255
256
  getUnhandledErrors() {
256
257
  return Array.from(this.errorsSet.values());
257
258
  }
259
+ addProcessTimeoutCause(cause) {
260
+ this.processTimeoutCauses.add(cause);
261
+ }
262
+ getProcessTimeoutCauses() {
263
+ return Array.from(this.processTimeoutCauses.values());
264
+ }
258
265
  getPaths() {
259
266
  return Array.from(this.pathsSet);
260
267
  }
@@ -313,7 +320,7 @@ class StateManager {
313
320
  }
314
321
  }
315
322
  }
316
- function createClient(url, options = {}) {
323
+ function createClient(url2, options = {}) {
317
324
  const {
318
325
  handlers = {},
319
326
  autoReconnect = true,
@@ -324,7 +331,7 @@ function createClient(url, options = {}) {
324
331
  } = options;
325
332
  let tries = reconnectTries;
326
333
  const ctx = reactive({
327
- ws: new WebSocketConstructor(url),
334
+ ws: new WebSocketConstructor(url2),
328
335
  state: new StateManager(),
329
336
  waitForConnection,
330
337
  reconnect
@@ -370,7 +377,7 @@ function createClient(url, options = {}) {
370
377
  function reconnect(reset = false) {
371
378
  if (reset)
372
379
  tries = reconnectTries;
373
- ctx.ws = new WebSocketConstructor(url);
380
+ ctx.ws = new WebSocketConstructor(url2);
374
381
  registerWS();
375
382
  }
376
383
  function registerWS() {
@@ -400,12 +407,19 @@ function createBrowserRunner(original) {
400
407
  constructor(options) {
401
408
  super(options.config);
402
409
  __publicField(this, "config");
403
- __publicField(this, "hasMap", /* @__PURE__ */ new Map());
410
+ __publicField(this, "hashMap", /* @__PURE__ */ new Map());
404
411
  __publicField(this, "client");
405
412
  this.config = options.config;
406
- this.hasMap = options.browserHashMap;
413
+ this.hashMap = options.browserHashMap;
407
414
  this.client = options.client;
408
415
  }
416
+ async onAfterRunTest(task) {
417
+ var _a, _b, _c;
418
+ await ((_a = super.onAfterRunTest) == null ? void 0 : _a.call(this));
419
+ (_c = (_b = task.result) == null ? void 0 : _b.errors) == null ? void 0 : _c.forEach((error) => {
420
+ console.error(error.message);
421
+ });
422
+ }
409
423
  onCollected(files) {
410
424
  return this.client.rpc.onCollected(files);
411
425
  }
@@ -414,7 +428,11 @@ function createBrowserRunner(original) {
414
428
  }
415
429
  async importFile(filepath) {
416
430
  const match = filepath.match(/^(\w:\/)/);
417
- const hash = this.hasMap.get(filepath);
431
+ let hash = this.hashMap.get(filepath);
432
+ if (!hash) {
433
+ hash = Date.now().toString();
434
+ this.hashMap.set(filepath, hash);
435
+ }
418
436
  const importpath = match ? `/@fs/${filepath.slice(match[1].length)}?v=${hash}` : `${filepath}?v=${hash}`;
419
437
  await __vitePreload(() => import(importpath), true ? [] : void 0);
420
438
  }
@@ -440,8 +458,8 @@ class BrowserSnapshotEnvironment {
440
458
  await this.client.rpc.createDirectory(filepath);
441
459
  }
442
460
  }
443
- globalThis.process = { env: {}, argv: [], stdout: { write: () => {
444
- } } };
461
+ globalThis.process = { env: {}, argv: [], cwd: () => "/", stdout: { write: () => {
462
+ } }, nextTick: (cb) => cb() };
445
463
  globalThis.global = globalThis;
446
464
  const PORT = location.port;
447
465
  const HOST = [location.hostname, PORT].filter(Boolean).join(":");
@@ -449,19 +467,12 @@ const ENTRY_URL = `${location.protocol === "https:" ? "wss:" : "ws:"}//${HOST}/_
449
467
  let config;
450
468
  let runner;
451
469
  const browserHashMap = /* @__PURE__ */ new Map();
452
- const client = createClient(ENTRY_URL, {
453
- handlers: {
454
- async onPathsCollected(paths) {
455
- if (!paths)
456
- return;
457
- const now = `${new Date().getTime()}`;
458
- paths.forEach((i) => {
459
- browserHashMap.set(i, now);
460
- });
461
- await runTests(paths, config, client);
462
- }
463
- }
464
- });
470
+ const url = new URL(location.href);
471
+ const testId = url.searchParams.get("id") || "unknown";
472
+ const getQueryPaths = () => {
473
+ return url.searchParams.getAll("path");
474
+ };
475
+ const client = createClient(ENTRY_URL);
465
476
  const ws = client.ws;
466
477
  async function loadConfig() {
467
478
  let retries = 5;
@@ -480,12 +491,11 @@ ws.addEventListener("open", async () => {
480
491
  globalThis.__vitest_worker__ = {
481
492
  config,
482
493
  browserHashMap,
494
+ moduleCache: /* @__PURE__ */ new Map(),
483
495
  rpc: client.rpc
484
496
  };
485
497
  globalThis.__vitest_mocker__ = {};
486
- const paths = await client.rpc.getPaths();
487
- const now = `${new Date().getTime()}`;
488
- paths.forEach((i) => browserHashMap.set(i, now));
498
+ const paths = getQueryPaths();
489
499
  const iFrame = document.getElementById("vitest-ui");
490
500
  iFrame.setAttribute("src", "/__vitest__/");
491
501
  await runTests(paths, config, client);
@@ -504,8 +514,15 @@ async function runTests(paths, config2, client2) {
504
514
  setupSnapshotEnvironment(new BrowserSnapshotEnvironment(client2));
505
515
  hasSnapshot = true;
506
516
  }
507
- await setupCommonEnv(config2);
508
- await startTests(paths, runner);
509
- await client2.rpc.onFinished();
510
- await client2.rpc.onWatcherStart();
517
+ try {
518
+ await setupCommonEnv(config2);
519
+ const files = paths.map((path2) => {
520
+ return `${config2.root}/${path2}`.replace(/\/+/g, "/");
521
+ });
522
+ const now = `${new Date().getTime()}`;
523
+ files.forEach((i) => browserHashMap.set(i, now));
524
+ await startTests(files, runner);
525
+ } finally {
526
+ await client2.rpc.onDone(testId);
527
+ }
511
528
  }
@@ -21,7 +21,7 @@
21
21
  border: none;
22
22
  }
23
23
  </style>
24
- <script type="module" crossorigin src="/assets/index-79af63dc.js"></script>
24
+ <script type="module" crossorigin src="/assets/index-25415511.js"></script>
25
25
  </head>
26
26
  <body>
27
27
  <iframe id="vitest-ui" src=""></iframe>
package/dist/index.js CHANGED
@@ -14,13 +14,13 @@ var index = (base = "/") => {
14
14
  {
15
15
  enforce: "pre",
16
16
  name: "vitest:browser",
17
- async resolveId(id, _, ctx) {
18
- if (ctx.ssr)
19
- return;
17
+ async resolveId(id) {
20
18
  if (id === "/__vitest_index__")
21
19
  return this.resolve("vitest/browser");
22
20
  if (id === "/__vitest_runners__")
23
21
  return this.resolve("vitest/runners");
22
+ if (id.startsWith("node:"))
23
+ id = id.slice(5);
24
24
  if (polyfills.includes(id))
25
25
  return polyfillPath(normalizeId(id));
26
26
  return null;
@@ -37,8 +37,8 @@ var index = (base = "/") => {
37
37
  },
38
38
  {
39
39
  name: "modern-node-polyfills",
40
- async resolveId(id, _, ctx) {
41
- if (ctx.ssr || !builtinModules.includes(id))
40
+ async resolveId(id) {
41
+ if (!builtinModules.includes(id))
42
42
  return;
43
43
  id = normalizeId(id);
44
44
  return { id: await polyfillPath(id), moduleSideEffects: false };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/browser",
3
3
  "type": "module",
4
- "version": "0.29.3",
4
+ "version": "0.29.5",
5
5
  "description": "Browser running for Vitest",
6
6
  "repository": {
7
7
  "type": "git",
@@ -23,22 +23,25 @@
23
23
  "dist",
24
24
  "stubs"
25
25
  ],
26
+ "peerDependencies": {
27
+ "vitest": ">=0.29.4"
28
+ },
26
29
  "dependencies": {
27
30
  "local-pkg": "^0.4.2",
28
31
  "mlly": "^1.1.0",
29
- "modern-node-polyfills": "0.0.9",
32
+ "modern-node-polyfills": "0.1.0",
30
33
  "rollup-plugin-node-polyfills": "^0.2.1",
31
34
  "sirv": "^2.0.2",
32
- "@vitest/runner": "0.29.3"
35
+ "@vitest/runner": "0.29.5"
33
36
  },
34
37
  "devDependencies": {
35
38
  "@types/ws": "^8.5.4",
36
39
  "rollup": "^2.79.1",
37
- "@vitest/ws-client": "0.29.3",
38
- "vitest": "0.29.3"
40
+ "@vitest/ws-client": "0.29.5",
41
+ "vitest": "0.29.5"
39
42
  },
40
43
  "scripts": {
41
- "build": "rimraf dist && pnpm build:node && pnpm build:client && pnpm copy",
44
+ "build": "rimraf dist && pnpm build:node && pnpm build:client",
42
45
  "build:client": "vite build src/client",
43
46
  "build:node": "rollup -c",
44
47
  "dev:client": "vite build src/client --watch",