vitest 0.26.3 → 0.27.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.
Files changed (39) hide show
  1. package/LICENSE.md +2 -54
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +15 -15
  4. package/dist/{chunk-api-setup.47a09f0f.js → chunk-api-setup.16ac28c0.js} +9 -4
  5. package/dist/{chunk-integrations-coverage.befed097.js → chunk-integrations-coverage.44413252.js} +19 -1
  6. package/dist/chunk-integrations-globals.3dfaeb99.js +27 -0
  7. package/dist/{chunk-typecheck-constants.06e1fe5b.js → chunk-mock-date.a1c85759.js} +9 -27
  8. package/dist/{chunk-node-git.a90c0582.js → chunk-node-git.543e964a.js} +1 -2
  9. package/dist/{chunk-runtime-chain.f51aa930.js → chunk-runtime-chain.6df5a66b.js} +1191 -1027
  10. package/dist/{chunk-runtime-error.f5c8aaf2.js → chunk-runtime-error.fad2c32b.js} +2 -2
  11. package/dist/{chunk-runtime-mocker.887bf8c8.js → chunk-runtime-mocker.a677dd28.js} +8 -6
  12. package/dist/{chunk-runtime-rpc.54d72169.js → chunk-runtime-rpc.7f83c8a9.js} +2 -2
  13. package/dist/{chunk-runtime-setup.a06d5c72.js → chunk-runtime-setup.731b2b04.js} +51 -52
  14. package/dist/{chunk-snapshot-manager.70695b70.js → chunk-snapshot-manager.700322bf.js} +408 -272
  15. package/dist/{chunk-utils-env.3fdc1793.js → chunk-utils-env.b861e3a0.js} +1 -63
  16. package/dist/{chunk-utils-import.e7f64637.js → chunk-utils-import.2baa69a9.js} +22 -8
  17. package/dist/chunk-utils-source-map.60562959.js +408 -0
  18. package/dist/{chunk-utils-timers.715da787.js → chunk-utils-timers.52534f96.js} +2977 -3458
  19. package/dist/cli-wrapper.js +11 -11
  20. package/dist/cli.js +12 -624
  21. package/dist/config.cjs +2 -1
  22. package/dist/config.d.ts +1 -1
  23. package/dist/config.js +2 -1
  24. package/dist/entry.js +14 -14
  25. package/dist/environments.d.ts +1 -1
  26. package/dist/{index-761e769b.d.ts → index-2d10c3fd.d.ts} +1 -1
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.js +12 -12
  29. package/dist/loader.js +3 -3
  30. package/dist/node.d.ts +2 -2
  31. package/dist/node.js +8 -8
  32. package/dist/spy.js +2 -102
  33. package/dist/suite.js +10 -10
  34. package/dist/{types-bae746aa.d.ts → types-e1e1d1e5.d.ts} +88 -76
  35. package/dist/vendor-index.723a074f.js +102 -0
  36. package/dist/worker.js +7 -7
  37. package/package.json +9 -5
  38. package/dist/chunk-integrations-globals.ee28730b.js +0 -27
  39. package/dist/chunk-utils-source-map.5278ee22.js +0 -86
@@ -1,7 +1,7 @@
1
1
  import util$1 from 'util';
2
2
  import { util } from 'chai';
3
- import { a as stringify } from './chunk-utils-timers.715da787.js';
4
- import { x as deepClone, g as getWorkerState, y as getType } from './chunk-typecheck-constants.06e1fe5b.js';
3
+ import { a as stringify } from './chunk-utils-timers.52534f96.js';
4
+ import { w as deepClone, g as getWorkerState, x as getType } from './chunk-mock-date.a1c85759.js';
5
5
 
6
6
  const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
7
7
  const IS_COLLECTION_SYMBOL = "@@__IMMUTABLE_ITERABLE__@@";
@@ -2,9 +2,10 @@ import { ViteNodeRunner } from 'vite-node/client';
2
2
  import { isInternalRequest } from 'vite-node/utils';
3
3
  import { normalizePath } from 'vite';
4
4
  import { i as isNodeBuiltin } from './vendor-index.2e96c50b.js';
5
- import { g as getWorkerState, y as getType, K as getAllMockableProperties, e as getCurrentEnvironment } from './chunk-typecheck-constants.06e1fe5b.js';
5
+ import { g as getWorkerState, x as getType, H as getAllMockableProperties, d as getCurrentEnvironment } from './chunk-mock-date.a1c85759.js';
6
6
  import { existsSync, readdirSync } from 'node:fs';
7
- import { b as resolve, e as distDir, g as isAbsolute, p as picocolors, d as dirname, j as join, c as basename, l as extname } from './chunk-utils-env.3fdc1793.js';
7
+ import { b as resolve, f as distDir, h as isAbsolute, d as dirname, j as join, c as basename, e as extname } from './chunk-utils-env.b861e3a0.js';
8
+ import c from 'picocolors';
8
9
 
9
10
  class RefTracker {
10
11
  constructor() {
@@ -105,7 +106,7 @@ const _VitestMocker = class {
105
106
  `[vitest] No "${String(prop)}" export is defined on the "${mockpath}" mock. Did you forget to return it from "vi.mock"?
106
107
  If you need to partially mock a module, you can use "vi.importActual" inside:
107
108
 
108
- ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
109
+ ${c.green(`vi.mock("${mockpath}", async () => {
109
110
  const actual = await vi.importActual("${mockpath}")
110
111
  return {
111
112
  ...actual,
@@ -281,8 +282,7 @@ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
281
282
  return result;
282
283
  }
283
284
  if (typeof mock === "string" && !callstack.includes(mock))
284
- url = mock;
285
- return url;
285
+ return mock;
286
286
  }
287
287
  queueMock(id, importer, factory) {
288
288
  _VitestMocker.pendingIds.push({ type: "mock", id, importer, factory });
@@ -339,7 +339,9 @@ class VitestRunner extends ViteNodeRunner {
339
339
  });
340
340
  }
341
341
  shouldInterop(path, mod) {
342
- return this.options.interopDefault ?? (getCurrentEnvironment() !== "node" && super.shouldInterop(path, mod));
342
+ if (this.options.interopDefault === false)
343
+ return false;
344
+ return (this.options.interopDefault || getCurrentEnvironment() !== "node") && super.shouldInterop(path, mod);
343
345
  }
344
346
  }
345
347
 
@@ -1,5 +1,5 @@
1
- import { g as getWorkerState } from './chunk-typecheck-constants.06e1fe5b.js';
2
- import { s as safeSetTimeout } from './chunk-utils-timers.715da787.js';
1
+ import { g as getWorkerState } from './chunk-mock-date.a1c85759.js';
2
+ import { s as safeSetTimeout } from './chunk-utils-timers.52534f96.js';
3
3
 
4
4
  const safeRandom = Math.random;
5
5
  function withSafeTimers(fn) {
@@ -1,14 +1,14 @@
1
1
  import { performance } from 'perf_hooks';
2
- import { s as someTasksAreOnly, i as interpretTaskModes, t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.befed097.js';
3
- import { r as resetRunOnceCounter, i as index, v as vi, s as setCurrentTest } from './chunk-utils-import.e7f64637.js';
4
- import { g as getWorkerState, R as RealDate, t as toArray, l as relativePath, j as isRunningInBenchmark, p as partitionSuiteChildren, q as shuffle, u as hasTests, v as hasFailed, w as createDefer, f as getFullName } from './chunk-typecheck-constants.06e1fe5b.js';
5
- import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getBenchOptions, n as getFn, o as setState, G as GLOBAL_EXPECT, p as getState } from './chunk-runtime-chain.f51aa930.js';
6
- import { r as rpc } from './chunk-runtime-rpc.54d72169.js';
7
- import { p as processError } from './chunk-runtime-error.f5c8aaf2.js';
2
+ import { g as generateHash, c as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.44413252.js';
3
+ import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getBenchOptions, n as getFn, o as setState, p as getSnapshotClient, G as GLOBAL_EXPECT, q as getState } from './chunk-runtime-chain.6df5a66b.js';
4
+ import { r as resetRunOnceCounter, i as index, v as vi, s as setCurrentTest } from './chunk-utils-import.2baa69a9.js';
5
+ import { g as getWorkerState, R as RealDate, t as toArray, k as relativePath, h as isRunningInBenchmark, p as partitionSuiteChildren, l as shuffle, q as hasTests, u as hasFailed, v as createDefer, e as getFullName } from './chunk-mock-date.a1c85759.js';
6
+ import { r as rpc } from './chunk-runtime-rpc.7f83c8a9.js';
7
+ import { p as processError } from './chunk-runtime-error.fad2c32b.js';
8
8
  import { installSourcemapsSupport } from 'vite-node/source-map';
9
9
  import { e as environments } from './chunk-env-node.b3664da2.js';
10
- import { i as isNode, a as isBrowser } from './chunk-utils-env.3fdc1793.js';
11
- import { b as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.715da787.js';
10
+ import { i as isNode, a as isBrowser } from './chunk-utils-env.b861e3a0.js';
11
+ import { b as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.52534f96.js';
12
12
 
13
13
  let globalSetup = false;
14
14
  async function setupGlobalEnv(config) {
@@ -29,7 +29,7 @@ async function setupGlobalEnv(config) {
29
29
  await setupConsoleLogSpy();
30
30
  }
31
31
  if (config.globals)
32
- (await import('./chunk-integrations-globals.ee28730b.js')).registerApiGlobally();
32
+ (await import('./chunk-integrations-globals.3dfaeb99.js')).registerApiGlobally();
33
33
  }
34
34
  function setupDefines(defines) {
35
35
  for (const key in defines)
@@ -170,32 +170,21 @@ async function runSetupFiles(config) {
170
170
  }
171
171
 
172
172
  const now$1 = Date.now;
173
- function hash(str) {
174
- let hash2 = 0;
175
- if (str.length === 0)
176
- return `${hash2}`;
177
- for (let i = 0; i < str.length; i++) {
178
- const char = str.charCodeAt(i);
179
- hash2 = (hash2 << 5) - hash2 + char;
180
- hash2 = hash2 & hash2;
181
- }
182
- return `${hash2}`;
183
- }
184
173
  async function collectTests(paths, config) {
185
174
  const files = [];
186
175
  const browserHashMap = getWorkerState().browserHashMap;
187
176
  async function importFromBrowser(filepath) {
188
177
  const match = filepath.match(/^(\w:\/)/);
189
- const hash2 = browserHashMap.get(filepath);
178
+ const hash = browserHashMap.get(filepath);
190
179
  if (match)
191
- return await import(`/@fs/${filepath.slice(match[1].length)}?v=${hash2}`);
180
+ return await import(`/@fs/${filepath.slice(match[1].length)}?v=${hash}`);
192
181
  else
193
- return await import(`${filepath}?v=${hash2}`);
182
+ return await import(`${filepath}?v=${hash}`);
194
183
  }
195
184
  for (const filepath of paths) {
196
185
  const path = relativePath(config.root, filepath);
197
186
  const file = {
198
- id: hash(path),
187
+ id: generateHash(path),
199
188
  name: path,
200
189
  type: "suite",
201
190
  mode: "run",
@@ -230,27 +219,22 @@ async function collectTests(paths, config) {
230
219
  }
231
220
  file.collectDuration = now$1() - collectStart;
232
221
  } catch (e) {
222
+ const error = processError(e);
233
223
  file.result = {
234
224
  state: "fail",
235
- error: processError(e)
225
+ error,
226
+ errors: [error]
236
227
  };
237
228
  if (config.browser)
238
229
  console.error(e);
239
230
  }
240
- calculateHash(file);
231
+ calculateSuiteHash(file);
241
232
  const hasOnlyTasks = someTasksAreOnly(file);
242
233
  interpretTaskModes(file, config.testNamePattern, hasOnlyTasks, false, config.allowOnly);
243
234
  files.push(file);
244
235
  }
245
236
  return files;
246
237
  }
247
- function calculateHash(parent) {
248
- parent.tasks.forEach((t, idx) => {
249
- t.id = `${parent.id}_${idx}`;
250
- if (t.type === "suite")
251
- calculateHash(t);
252
- });
253
- }
254
238
 
255
239
  async function importTinybench() {
256
240
  if (!globalThis.EventTarget)
@@ -330,8 +314,8 @@ const callCleanupHooks = async (cleanups) => {
330
314
  async function runTest(test) {
331
315
  var _a, _b, _c;
332
316
  if (test.mode !== "run") {
333
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f51aa930.js').then(function (n) { return n.r; });
334
- getSnapshotClient().skipTestSnapshots(test);
317
+ const { getSnapshotClient: getSnapshotClient2 } = await import('./chunk-runtime-chain.6df5a66b.js').then(function (n) { return n.u; });
318
+ getSnapshotClient2().skipTestSnapshots(test);
335
319
  return;
336
320
  }
337
321
  if (((_a = test.result) == null ? void 0 : _a.state) === "fail") {
@@ -347,8 +331,8 @@ async function runTest(test) {
347
331
  clearModuleMocks();
348
332
  setCurrentTest(test);
349
333
  if (isNode) {
350
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f51aa930.js').then(function (n) { return n.r; });
351
- await getSnapshotClient().setTest(test);
334
+ const { getSnapshotClient: getSnapshotClient2 } = await import('./chunk-runtime-chain.6df5a66b.js').then(function (n) { return n.u; });
335
+ await getSnapshotClient2().setTest(test);
352
336
  }
353
337
  const workerState = getWorkerState();
354
338
  workerState.current = test;
@@ -363,7 +347,8 @@ async function runTest(test) {
363
347
  expectedAssertionsNumber: null,
364
348
  expectedAssertionsNumberErrorGen: null,
365
349
  testPath: (_b = test.suite.file) == null ? void 0 : _b.filepath,
366
- currentTestName: getFullName(test)
350
+ currentTestName: getFullName(test),
351
+ snapshotState: getSnapshotClient().snapshotState
367
352
  }, globalThis[GLOBAL_EXPECT]);
368
353
  beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", [test.context, test.suite]);
369
354
  test.result.retryCount = retryCount;
@@ -381,15 +366,19 @@ async function runTest(test) {
381
366
  throw isExpectingAssertionsError;
382
367
  test.result.state = "pass";
383
368
  } catch (e) {
369
+ const error = processError(e);
384
370
  test.result.state = "fail";
385
- test.result.error = processError(e);
371
+ test.result.error = error;
372
+ test.result.errors = [error];
386
373
  }
387
374
  try {
388
375
  await callSuiteHook(test.suite, test, "afterEach", [test.context, test.suite]);
389
376
  await callCleanupHooks(beforeEachCleanups);
390
377
  } catch (e) {
378
+ const error = processError(e);
391
379
  test.result.state = "fail";
392
- test.result.error = processError(e);
380
+ test.result.error = error;
381
+ test.result.errors = [error];
393
382
  }
394
383
  if (test.result.state === "pass")
395
384
  break;
@@ -399,19 +388,22 @@ async function runTest(test) {
399
388
  await Promise.all(((_c = test.onFailed) == null ? void 0 : _c.map((fn) => fn(test.result))) || []);
400
389
  if (test.fails) {
401
390
  if (test.result.state === "pass") {
391
+ const error = processError(new Error("Expect test to fail"));
402
392
  test.result.state = "fail";
403
- test.result.error = processError(new Error("Expect test to fail"));
393
+ test.result.error = error;
394
+ test.result.errors = [error];
404
395
  } else {
405
396
  test.result.state = "pass";
406
397
  test.result.error = void 0;
398
+ test.result.errors = void 0;
407
399
  }
408
400
  }
409
401
  if (isBrowser && test.result.error)
410
402
  console.error(test.result.error.message, test.result.error.stackStr);
411
403
  setCurrentTest(void 0);
412
404
  if (isNode) {
413
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f51aa930.js').then(function (n) { return n.r; });
414
- getSnapshotClient().clearTest();
405
+ const { getSnapshotClient: getSnapshotClient2 } = await import('./chunk-runtime-chain.6df5a66b.js').then(function (n) { return n.u; });
406
+ getSnapshotClient2().clearTest();
415
407
  }
416
408
  test.result.duration = now() - start;
417
409
  if (workerState.config.logHeapUsage && isNode)
@@ -472,8 +464,10 @@ async function runSuite(suite) {
472
464
  await callSuiteHook(suite, suite, "afterAll", [suite]);
473
465
  await callCleanupHooks(beforeAllCleanups);
474
466
  } catch (e) {
467
+ const error = processError(e);
475
468
  suite.result.state = "fail";
476
- suite.result.error = processError(e);
469
+ suite.result.error = error;
470
+ suite.result.errors = [error];
477
471
  }
478
472
  }
479
473
  suite.result.duration = now() - start;
@@ -482,8 +476,11 @@ async function runSuite(suite) {
482
476
  if (suite.mode === "run") {
483
477
  if (!hasTests(suite)) {
484
478
  suite.result.state = "fail";
485
- if (!suite.result.error)
486
- suite.result.error = new Error(`No test found in suite ${suite.name}`);
479
+ if (!suite.result.error) {
480
+ const error = processError(new Error(`No test found in suite ${suite.name}`));
481
+ suite.result.error = error;
482
+ suite.result.errors = [error];
483
+ }
487
484
  } else if (hasFailed(suite)) {
488
485
  suite.result.state = "fail";
489
486
  } else {
@@ -590,13 +587,15 @@ async function runSuites(suites) {
590
587
  await runSuite(suite);
591
588
  }
592
589
  async function runFiles(files, config) {
593
- var _a;
590
+ var _a, _b;
594
591
  for (const file of files) {
595
592
  if (!file.tasks.length && !config.passWithNoTests) {
596
- if (!((_a = file.result) == null ? void 0 : _a.error)) {
593
+ if (!((_b = (_a = file.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.length)) {
594
+ const error = processError(new Error(`No test suite found in file ${file.filepath}`));
597
595
  file.result = {
598
596
  state: "fail",
599
- error: new Error(`No test suite found in file ${file.filepath}`)
597
+ error,
598
+ errors: [error]
600
599
  };
601
600
  }
602
601
  }
@@ -616,12 +615,12 @@ async function startTestsBrowser(paths, config) {
616
615
  async function startTestsNode(paths, config) {
617
616
  const files = await collectTests(paths, config);
618
617
  rpc().onCollected(files);
619
- const { getSnapshotClient } = await import('./chunk-runtime-chain.f51aa930.js').then(function (n) { return n.r; });
620
- getSnapshotClient().clear();
618
+ const { getSnapshotClient: getSnapshotClient2 } = await import('./chunk-runtime-chain.6df5a66b.js').then(function (n) { return n.u; });
619
+ getSnapshotClient2().clear();
621
620
  await runFiles(files, config);
622
621
  const coverage = await takeCoverageInsideWorker(config.coverage);
623
622
  rpc().onAfterSuiteRun({ coverage });
624
- await getSnapshotClient().saveCurrent();
623
+ await getSnapshotClient2().saveCurrent();
625
624
  await sendTasksUpdate();
626
625
  }
627
626
  async function startTests(paths, config) {