vitest 0.0.114 → 0.0.118

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.
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { j as resolve } from './index-ea5153a0.js';
2
+ import { k as resolve } from './index-80671389.js';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
5
  const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
@@ -1,5 +1,5 @@
1
1
  import { existsSync, promises } from 'fs';
2
- import { m as notNullish, c, r as relative } from './index-ea5153a0.js';
2
+ import { o as notNullish, c, r as relative } from './index-80671389.js';
3
3
 
4
4
  function Diff() {}
5
5
  Diff.prototype = {
package/dist/entry.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import fs, { promises } from 'fs';
2
- import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, n as nanoid, l as clearContext, m as defaultSuite, o as setHooks, p as getHooks, q as context, s as setState, r as getFn, b as getState, e as vi } from './vi-67e478ef.js';
2
+ import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, b as getState, e as vi } from './vi-85b65e90.js';
3
3
  import { Console } from 'console';
4
4
  import { Writable } from 'stream';
5
5
  import { importModule } from 'local-pkg';
6
6
  import chai$1, { expect, util } from 'chai';
7
7
  import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
8
- import { p as index, s as slash, q as getNames, c as c$1, k as toArray, r as relative, u as interpretOnlyMode, v as partitionSuiteChildren, w as hasTests, h as hasFailed } from './index-ea5153a0.js';
9
- import { r as rpc, s as send } from './rpc-85fe6402.js';
10
- import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-3cfdad26.js';
8
+ import { q as index, s as slash, u as getNames, c as c$1, t as toArray, r as relative, v as partitionSuiteChildren, w as hasTests, h as hasFailed } from './index-80671389.js';
9
+ import { r as rpc } from './rpc-8c7cc374.js';
10
+ import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-d87307c6.js';
11
11
  import { performance } from 'perf_hooks';
12
+ import { createHash } from 'crypto';
12
13
  import { format as format$1 } from 'util';
13
14
  import './jest-mock-4a754991.js';
14
15
  import 'tinyspy';
@@ -387,7 +388,7 @@ async function saveInlineSnapshots(snapshots) {
387
388
  const MagicString = (await import('./magic-string.es-94000aea.js')).default;
388
389
  const files = new Set(snapshots.map((i) => i.file));
389
390
  await Promise.all(Array.from(files).map(async (file) => {
390
- const map = await rpc("getSourceMap", file);
391
+ const map = await rpc().getSourceMap(file);
391
392
  const snaps = snapshots.filter((i) => i.file === file);
392
393
  const code = await promises.readFile(file, "utf8");
393
394
  const s = new MagicString(code);
@@ -402,12 +403,13 @@ async function saveInlineSnapshots(snapshots) {
402
403
  }));
403
404
  }
404
405
  const startRegex = /toMatchInlineSnapshot\s*\(\s*(['"`\)])/m;
405
- function replaceInlineSnap(code, s, index, newSnap) {
406
+ function replaceInlineSnap(code, s, index, newSnap, indent = "") {
406
407
  const startMatch = startRegex.exec(code.slice(index));
407
408
  if (!startMatch)
408
409
  return false;
409
- newSnap = newSnap.replace(/\\/g, "\\\\");
410
- const snapString = newSnap.includes("\n") ? `\`${newSnap.replace(/`/g, "\\`").trimEnd()}\`` : `'${newSnap.replace(/'/g, "\\'")}'`;
410
+ newSnap = newSnap.replace(/\\/g, "\\\\").split("\n").map((i) => (indent + i).trimEnd()).join("\n");
411
+ const isOneline = !newSnap.includes("\n");
412
+ const snapString = isOneline ? `'${newSnap.replace(/'/g, "\\'").trim()}'` : `\`${newSnap.replace(/`/g, "\\`").trimEnd()}\``;
411
413
  const quote = startMatch[1];
412
414
  const startIndex = index + startMatch.index + startMatch[0].length;
413
415
  if (quote === ")") {
@@ -3103,7 +3105,7 @@ class SnapshotClient {
3103
3105
  if (!this.testFile || !this.snapshotState)
3104
3106
  return;
3105
3107
  const result = await packSnapshotState(this.testFile, this.snapshotState);
3106
- await rpc("snapshotSaved", result);
3108
+ await rpc().snapshotSaved(result);
3107
3109
  this.testFile = "";
3108
3110
  this.snapshotState = void 0;
3109
3111
  }
@@ -3530,13 +3532,13 @@ async function setupGlobalEnv(config) {
3530
3532
  setupConsoleLogSpy();
3531
3533
  await setupChai();
3532
3534
  if (config.global)
3533
- (await import('./global-12653c72.js')).registerApiGlobally();
3535
+ (await import('./global-fc93e939.js')).registerApiGlobally();
3534
3536
  }
3535
3537
  function setupConsoleLogSpy() {
3536
3538
  const stdout = new Writable({
3537
3539
  write(data, encoding, callback) {
3538
3540
  var _a;
3539
- send("log", {
3541
+ rpc().onUserLog({
3540
3542
  type: "stdout",
3541
3543
  content: String(data),
3542
3544
  taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
@@ -3547,7 +3549,7 @@ function setupConsoleLogSpy() {
3547
3549
  const stderr = new Writable({
3548
3550
  write(data, encoding, callback) {
3549
3551
  var _a;
3550
- send("log", {
3552
+ rpc().onUserLog({
3551
3553
  type: "stderr",
3552
3554
  content: String(data),
3553
3555
  taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
@@ -3578,7 +3580,7 @@ async function runSetupFiles(config) {
3578
3580
  }));
3579
3581
  }
3580
3582
 
3581
- function serializeError(val) {
3583
+ function serializeError(val, seen = /* @__PURE__ */ new WeakSet()) {
3582
3584
  if (!val || typeof val === "string")
3583
3585
  return val;
3584
3586
  if (typeof val === "function")
@@ -3591,9 +3593,18 @@ function serializeError(val) {
3591
3593
  return val.tagName;
3592
3594
  if (typeof val.asymmetricMatch === "function")
3593
3595
  return `${val.toString()} ${format$1(val.sample)}`;
3594
- Object.keys(val).forEach((key) => {
3595
- val[key] = serializeError(val[key]);
3596
- });
3596
+ if (seen.has(val))
3597
+ return val;
3598
+ seen.add(val);
3599
+ if (Array.isArray(val)) {
3600
+ val = val.map((e) => {
3601
+ return serializeError(e, seen);
3602
+ });
3603
+ } else {
3604
+ Object.keys(val).forEach((key) => {
3605
+ val[key] = serializeError(val[key], seen);
3606
+ });
3607
+ }
3597
3608
  return val;
3598
3609
  }
3599
3610
  function processError(err) {
@@ -3610,12 +3621,16 @@ function processError(err) {
3610
3621
  return serializeError(err);
3611
3622
  }
3612
3623
 
3624
+ function hash(str, length = 10) {
3625
+ return createHash("md5").update(str).digest("hex").slice(0, length);
3626
+ }
3613
3627
  async function collectTests(paths, config) {
3614
3628
  const files = [];
3615
3629
  for (const filepath of paths) {
3630
+ const path = relative(config.root, filepath);
3616
3631
  const file = {
3617
- id: nanoid(),
3618
- name: relative(config.root, filepath),
3632
+ id: hash(path),
3633
+ name: path,
3619
3634
  type: "suite",
3620
3635
  mode: "run",
3621
3636
  computeMode: "serial",
@@ -3647,12 +3662,43 @@ async function collectTests(paths, config) {
3647
3662
  };
3648
3663
  process.stdout.write("\0");
3649
3664
  }
3665
+ calculateHash(file);
3650
3666
  files.push(file);
3651
3667
  }
3652
- const tasks = files.reduce((tasks2, file) => tasks2.concat(file.tasks), []);
3653
- interpretOnlyMode(tasks);
3668
+ interpretTaskModes(files, config.testNamePattern);
3654
3669
  return files;
3655
3670
  }
3671
+ function interpretTaskModes(tasks, namePattern) {
3672
+ if (tasks.some((t) => t.mode === "only")) {
3673
+ tasks.forEach((t) => {
3674
+ if (t.mode === "run")
3675
+ t.mode = "skip";
3676
+ else if (t.mode === "only")
3677
+ t.mode = "run";
3678
+ });
3679
+ }
3680
+ tasks.forEach((t) => {
3681
+ if (t.type === "test") {
3682
+ if (namePattern && !t.name.match(namePattern))
3683
+ t.mode = "skip";
3684
+ } else if (t.type === "suite") {
3685
+ if (t.mode === "skip")
3686
+ t.tasks.forEach((c) => c.mode === "run" && (c.mode = "skip"));
3687
+ interpretTaskModes(t.tasks, namePattern);
3688
+ if (t.mode === "run") {
3689
+ if (t.tasks.every((i) => i.mode !== "run"))
3690
+ t.mode = "skip";
3691
+ }
3692
+ }
3693
+ });
3694
+ }
3695
+ function calculateHash(parent) {
3696
+ parent.tasks.forEach((t, idx) => {
3697
+ t.id = `${parent.id}_${idx}`;
3698
+ if (t.type === "suite")
3699
+ calculateHash(t);
3700
+ });
3701
+ }
3656
3702
 
3657
3703
  async function callSuiteHook(suite, name, args) {
3658
3704
  if (name === "beforeEach" && suite.suite)
@@ -3661,8 +3707,24 @@ async function callSuiteHook(suite, name, args) {
3661
3707
  if (name === "afterEach" && suite.suite)
3662
3708
  await callSuiteHook(suite.suite, name, args);
3663
3709
  }
3710
+ const packs = [];
3711
+ let updateTimer;
3712
+ let previousUpdate;
3664
3713
  function updateTask(task) {
3665
- return rpc("onTaskUpdate", [task.id, task.result]);
3714
+ packs.push([task.id, task.result]);
3715
+ clearTimeout(updateTimer);
3716
+ updateTimer = setTimeout(() => {
3717
+ previousUpdate = sendTasksUpdate();
3718
+ }, 10);
3719
+ }
3720
+ async function sendTasksUpdate() {
3721
+ clearTimeout(updateTimer);
3722
+ await previousUpdate;
3723
+ if (packs.length) {
3724
+ const p = rpc().onTaskUpdate(packs);
3725
+ packs.length = 0;
3726
+ return p;
3727
+ }
3666
3728
  }
3667
3729
  async function runTest(test) {
3668
3730
  if (test.mode !== "run")
@@ -3761,9 +3823,10 @@ async function runSuites(suites) {
3761
3823
  }
3762
3824
  async function startTests(paths, config) {
3763
3825
  const files = await collectTests(paths, config);
3764
- send("onCollected", files);
3826
+ rpc().onCollected(files);
3765
3827
  await runSuites(files);
3766
3828
  await getSnapshotClient().saveSnap();
3829
+ await sendTasksUpdate();
3767
3830
  }
3768
3831
  function clearModuleMocks() {
3769
3832
  const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config;
@@ -1,11 +1,11 @@
1
- import { g as globalApis } from './constants-9c7f06df.js';
2
- import { i as index } from './index-ebf35a56.js';
1
+ import { g as globalApis } from './constants-56bfb5ab.js';
2
+ import { i as index } from './index-be3cc31e.js';
3
3
  import 'url';
4
- import './index-ea5153a0.js';
4
+ import './index-80671389.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
- import './vi-67e478ef.js';
8
+ import './vi-85b65e90.js';
9
9
  import './_commonjsHelpers-c9e3b764.js';
10
10
  import './jest-mock-4a754991.js';
11
11
  import 'chai';