vitest 0.0.122 → 0.0.126

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/README.md CHANGED
@@ -4,6 +4,4 @@
4
4
 
5
5
  A blazing fast unit test framework powered by Vite.
6
6
 
7
- > **This project is currently in closed beta exclusively for Sponsors.**<br>
8
- > Become a Sponsor of [@patak-dev](https://github.com/sponsors/patak-dev) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
9
- > Learn more at [vitest.dev](https://vitest.dev)
7
+ [GitHub](https://github.com/vitest-dev/vitest) | [Documentation](https://vitest.dev/)
package/dist/cli.js CHANGED
@@ -7,8 +7,8 @@ import process$1 from 'process';
7
7
  import { m as mergeStream, g as getStream, c as crossSpawn } from './index-6e709f57.js';
8
8
  import require$$0, { constants } from 'os';
9
9
  import { s as signalExit } from './index-648e7ab2.js';
10
- import { e as ensurePackageInstalled } from './index-090545ef.js';
11
- import { c as createVitest } from './index-123a18df.js';
10
+ import { e as ensurePackageInstalled } from './index-9fdde2e8.js';
11
+ import { c as createVitest } from './index-e04b9e4c.js';
12
12
  import './_commonjsHelpers-c9e3b764.js';
13
13
  import 'fs';
14
14
  import 'stream';
@@ -18,10 +18,10 @@ import 'url';
18
18
  import 'tty';
19
19
  import 'local-pkg';
20
20
  import 'vite';
21
- import './constants-22bbd600.js';
21
+ import './constants-8b3a9b31.js';
22
22
  import './magic-string.es-94000aea.js';
23
23
  import 'perf_hooks';
24
- import './diff-a295cb37.js';
24
+ import './diff-3adb959a.js';
25
25
  import 'module';
26
26
  import 'worker_threads';
27
27
  import 'tinypool';
@@ -1700,16 +1700,22 @@ function execa(file, args, options) {
1700
1700
  return mergePromise(spawned, handlePromiseOnce);
1701
1701
  }
1702
1702
 
1703
- var version = "0.0.122";
1703
+ var version = "0.0.126";
1704
1704
 
1705
1705
  const CLOSE_TIMEOUT = 1e3;
1706
1706
  const cli = cac("vitest");
1707
- cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open UI", { default: false }).option("-t, --testNamePattern <pattern>", "run test names with the specified pattern").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--findRelatedTests <filepath>", "run only tests that import specified file").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
1707
+ cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open UI", { default: false }).option("-t, --testNamePattern <pattern>", "run test names with the specified pattern").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console output from tests").option("--isolate", "isolate environment for each test file", { default: true }).option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
1708
1708
  cli.command("run [...filters]").action(run);
1709
+ cli.command("related [...filters]").action(runRelated);
1709
1710
  cli.command("watch [...filters]").action(dev);
1710
1711
  cli.command("dev [...filters]").action(dev);
1711
1712
  cli.command("[...filters]").action(dev);
1712
1713
  cli.parse();
1714
+ async function runRelated(relatedFiles, argv) {
1715
+ argv.related = relatedFiles;
1716
+ argv.passWithNoTests ?? (argv.passWithNoTests = true);
1717
+ await dev([], argv);
1718
+ }
1713
1719
  async function dev(cliFilters, argv) {
1714
1720
  if (argv.watch == null)
1715
1721
  argv.watch = !process.env.CI && !argv.run;
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { k as resolve } from './index-090545ef.js';
2
+ import { k as resolve } from './index-9fdde2e8.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 { o as notNullish, c, r as relative } from './index-090545ef.js';
2
+ import { o as notNullish, c, r as relative } from './index-9fdde2e8.js';
3
3
 
4
4
  function Diff() {}
5
5
  Diff.prototype = {
@@ -4506,9 +4506,28 @@ function getOriginalPos(map, { line, column }) {
4506
4506
  }
4507
4507
  const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
4508
4508
  const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/;
4509
- function parseStack(stack) {
4510
- const lines = stack.split("\n");
4511
- const stackFrames = lines.map((raw) => {
4509
+ async function interpretSourcePos(stackFrames, ctx) {
4510
+ var _a;
4511
+ for (const frame of stackFrames) {
4512
+ const transformResult = (_a = ctx.server.moduleGraph.getModuleById(frame.file)) == null ? void 0 : _a.ssrTransformResult;
4513
+ if (!transformResult)
4514
+ continue;
4515
+ const sourcePos = await getOriginalPos(transformResult.map, frame);
4516
+ if (sourcePos)
4517
+ frame.sourcePos = sourcePos;
4518
+ }
4519
+ return stackFrames;
4520
+ }
4521
+ const stackIgnorePatterns = [
4522
+ "/vitest/dist/",
4523
+ "/node_modules/tinypool/",
4524
+ "/node_modules/tinyspy/"
4525
+ ];
4526
+ function parseStacktrace(e) {
4527
+ if (e.stacks)
4528
+ return e.stacks;
4529
+ const stackStr = e.stack || e.stackStr || "";
4530
+ const stackFrames = stackStr.split("\n").map((raw) => {
4512
4531
  const line = raw.trim();
4513
4532
  const match = line.match(stackFnCallRE) || line.match(stackBarePathRE);
4514
4533
  if (!match)
@@ -4516,14 +4535,17 @@ function parseStack(stack) {
4516
4535
  let file = match[2];
4517
4536
  if (file.startsWith("file://"))
4518
4537
  file = file.slice(7);
4538
+ if (stackIgnorePatterns.some((p) => file.includes(p)))
4539
+ return null;
4519
4540
  return {
4520
4541
  method: match[1],
4521
4542
  file: match[2],
4522
4543
  line: parseInt(match[3]),
4523
4544
  column: parseInt(match[4])
4524
4545
  };
4525
- });
4526
- return stackFrames.filter(notNullish);
4546
+ }).filter(notNullish);
4547
+ e.stacks = stackFrames;
4548
+ return stackFrames;
4527
4549
  }
4528
4550
  function posToNumber(source, pos) {
4529
4551
  if (typeof pos === "number")
@@ -4555,14 +4577,12 @@ async function printError(error, ctx) {
4555
4577
  stack: error
4556
4578
  };
4557
4579
  }
4558
- const stackStr = e.stack || e.stackStr || "";
4559
- const stacks = parseStack(stackStr);
4580
+ const stacks = parseStacktrace(e);
4560
4581
  if (!stacks.length) {
4561
4582
  ctx.console.error(e);
4562
4583
  } else {
4563
- const nearest = stacks.find((stack) => {
4564
- return !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file);
4565
- });
4584
+ await interpretSourcePos(stacks, ctx);
4585
+ const nearest = stacks.find((stack) => ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file));
4566
4586
  printErrorMessage(e);
4567
4587
  await printStack(ctx, stacks, nearest, async (s, pos) => {
4568
4588
  if (s === nearest && nearest) {
@@ -4571,7 +4591,7 @@ async function printError(error, ctx) {
4571
4591
  }
4572
4592
  });
4573
4593
  }
4574
- handleImportOutsideModuleError(stackStr, ctx);
4594
+ handleImportOutsideModuleError(e.stack || e.stackStr || "", ctx);
4575
4595
  if (e.showDiff)
4576
4596
  displayDiff(e.actual, e.expected);
4577
4597
  }
@@ -4603,12 +4623,6 @@ As a temporary workaround you can try to inline the package by updating your con
4603
4623
  }
4604
4624
  `)));
4605
4625
  }
4606
- async function getSourcePos(ctx, nearest) {
4607
- const mod = ctx.server.moduleGraph.getModuleById(nearest.file);
4608
- const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
4609
- const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
4610
- return pos;
4611
- }
4612
4626
  function displayDiff(actual, expected) {
4613
4627
  console.error(c.gray(unifiedDiff(actual, expected)) + "\n");
4614
4628
  }
@@ -4620,7 +4634,7 @@ async function printStack(ctx, stack, highlight, onStack) {
4620
4634
  if (!stack.length)
4621
4635
  return;
4622
4636
  for (const frame of stack) {
4623
- const pos = await getSourcePos(ctx, frame) || frame;
4637
+ const pos = frame.sourcePos || frame;
4624
4638
  const color = frame === highlight ? c.yellow : c.gray;
4625
4639
  const path = relative(ctx.config.root, frame.file);
4626
4640
  ctx.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
@@ -4734,4 +4748,4 @@ function formatLine(line) {
4734
4748
  return cliTruncate(line, (process.stdout.columns || 80) - 4);
4735
4749
  }
4736
4750
 
4737
- export { F_POINTER as F, F_DOWN as a, F_LONG_DASH as b, F_DOWN_RIGHT as c, F_DOT as d, F_CHECK as e, F_CROSS as f, F_RIGHT as g, stringWidth as h, ansiStyles as i, sliceAnsi as j, cliTruncate as k, getOriginalPos as l, posToNumber as m, parseStack as n, printError as p, stripAnsi as s, unifiedDiff as u };
4751
+ export { F_POINTER as F, F_DOWN as a, F_LONG_DASH as b, F_DOWN_RIGHT as c, F_DOT as d, F_CHECK as e, F_CROSS as f, F_RIGHT as g, stringWidth as h, ansiStyles as i, sliceAnsi as j, cliTruncate as k, getOriginalPos as l, posToNumber as m, parseStacktrace as n, interpretSourcePos as o, printError as p, stripAnsi as s, unifiedDiff as u };
package/dist/entry.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import fs, { promises } from 'fs';
2
- import { f as format_1, h as getSerializers, p as plugins_1, b as getState, j as equals, k as iterableEquality, l as subsetEquality, m as isA, J as JestChaiExpect, n as clearContext, o as defaultSuite, q as setHooks, r as getHooks, u as context, s as setState, x as getFn, e as vi } from './vi-c99184a5.js';
2
+ import { f as format_1, h as getSerializers, p as plugins_1, j as equals, b as getState, k as iterableEquality, l as subsetEquality, m as isA, J as JestChaiExpect, n as clearContext, o as defaultSuite, q as setHooks, r as getHooks, u as context, s as setState, x as getFn, e as vi } from './vi-5ff3926d.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 { u as index, s as slash, v as getNames, c, t as toArray, r as relative, w as partitionSuiteChildren, x as hasTests, h as hasFailed } from './index-090545ef.js';
8
+ import { u as index, s as slash, v as getNames, c, t as toArray, r as relative, w as partitionSuiteChildren, x as hasTests, h as hasFailed } from './index-9fdde2e8.js';
9
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-a295cb37.js';
11
- import { performance } from 'perf_hooks';
10
+ import { l as getOriginalPos, m as posToNumber, n as parseStacktrace, u as unifiedDiff } from './diff-3adb959a.js';
11
+ import { performance as performance$1 } from 'perf_hooks';
12
12
  import { createHash } from 'crypto';
13
13
  import { format } from 'util';
14
- import './jest-mock-038a01b3.js';
14
+ import './jest-mock-30625866.js';
15
15
  import 'tinyspy';
16
16
  import 'url';
17
17
  import 'tty';
@@ -589,7 +589,6 @@ class SnapshotState {
589
589
  this._inlineSnapshots = [];
590
590
  this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
591
591
  this._counters = new Map();
592
- this._index = 0;
593
592
  this.expand = options.expand || false;
594
593
  this.added = 0;
595
594
  this.matched = 0;
@@ -610,7 +609,7 @@ class SnapshotState {
610
609
  this._dirty = true;
611
610
  if (options.isInline) {
612
611
  const error = options.error || new Error("Unknown error");
613
- const stacks = parseStack(error.stack || "");
612
+ const stacks = parseStacktrace(error);
614
613
  stacks.forEach((i) => i.file = slash(i.file));
615
614
  const stack = stacks.find((i) => process.__vitest_worker__.ctx.files.includes(i.file));
616
615
  if (!stack) {
@@ -626,7 +625,6 @@ class SnapshotState {
626
625
  clear() {
627
626
  this._snapshotData = this._initialData;
628
627
  this._counters = new Map();
629
- this._index = 0;
630
628
  this.added = 0;
631
629
  this.matched = 0;
632
630
  this.unmatched = 0;
@@ -987,12 +985,11 @@ const getMatcherState = (assertion) => {
987
985
  iterableEquality,
988
986
  subsetEquality
989
987
  });
990
- const matcherState = __spreadProps(__spreadValues({
988
+ const matcherState = __spreadProps(__spreadValues({}, getState()), {
991
989
  isNot,
992
990
  utils: jestUtils,
993
991
  promise,
994
- equals
995
- }, getState()), {
992
+ equals,
996
993
  suppressedErrors: []
997
994
  });
998
995
  return {
@@ -1228,7 +1225,7 @@ async function setupGlobalEnv(config) {
1228
1225
  setupConsoleLogSpy();
1229
1226
  await setupChai();
1230
1227
  if (config.global)
1231
- (await import('./global-71c4f178.js')).registerApiGlobally();
1228
+ (await import('./global-eb23b22e.js')).registerApiGlobally();
1232
1229
  }
1233
1230
  function setupConsoleLogSpy() {
1234
1231
  const stdout = new Writable({
@@ -1320,9 +1317,6 @@ function processError(err) {
1320
1317
  function hash(str, length = 10) {
1321
1318
  return createHash("md5").update(str).digest("hex").slice(0, length);
1322
1319
  }
1323
- function inModuleGraph(files) {
1324
- return files.some((file) => process.__vitest_worker__.moduleCache.has(file));
1325
- }
1326
1320
  async function collectTests(paths, config) {
1327
1321
  const files = [];
1328
1322
  for (const filepath of paths) {
@@ -1332,7 +1326,6 @@ async function collectTests(paths, config) {
1332
1326
  name: path,
1333
1327
  type: "suite",
1334
1328
  mode: "run",
1335
- computeMode: "serial",
1336
1329
  filepath,
1337
1330
  tasks: []
1338
1331
  };
@@ -1340,8 +1333,6 @@ async function collectTests(paths, config) {
1340
1333
  try {
1341
1334
  await runSetupFiles(config);
1342
1335
  await import(filepath);
1343
- if (config.findRelatedTests && !inModuleGraph(config.findRelatedTests))
1344
- continue;
1345
1336
  const defaultTasks = await defaultSuite.collect(file);
1346
1337
  setHooks(file, getHooks(defaultTasks));
1347
1338
  for (const c of [...defaultTasks.tasks, ...context.tasks]) {
@@ -1350,14 +1341,15 @@ async function collectTests(paths, config) {
1350
1341
  } else if (c.type === "suite") {
1351
1342
  file.tasks.push(c);
1352
1343
  } else {
1344
+ const start = performance.now();
1353
1345
  const suite = await c.collect(file);
1346
+ file.collectDuration = performance.now() - start;
1354
1347
  if (suite.name || suite.tasks.length)
1355
1348
  file.tasks.push(suite);
1356
1349
  }
1357
1350
  }
1358
1351
  } catch (e) {
1359
1352
  file.result = {
1360
- start: performance.now(),
1361
1353
  state: "fail",
1362
1354
  error: processError(e)
1363
1355
  };
@@ -1446,8 +1438,8 @@ async function sendTasksUpdate() {
1446
1438
  async function runTest(test) {
1447
1439
  if (test.mode !== "run")
1448
1440
  return;
1441
+ const start = performance$1.now();
1449
1442
  test.result = {
1450
- start: performance.now(),
1451
1443
  state: "run"
1452
1444
  };
1453
1445
  updateTask(test);
@@ -1490,7 +1482,7 @@ async function runTest(test) {
1490
1482
  }
1491
1483
  }
1492
1484
  getSnapshotClient().clearTest();
1493
- test.result.end = performance.now();
1485
+ test.result.duration = performance$1.now() - start;
1494
1486
  process.__vitest_worker__.current = void 0;
1495
1487
  updateTask(test);
1496
1488
  }
@@ -1498,8 +1490,8 @@ async function runSuite(suite) {
1498
1490
  var _a;
1499
1491
  if (((_a = suite.result) == null ? void 0 : _a.state) === "fail")
1500
1492
  return;
1493
+ const start = performance$1.now();
1501
1494
  suite.result = {
1502
- start: performance.now(),
1503
1495
  state: "run"
1504
1496
  };
1505
1497
  updateTask(suite);
@@ -1511,12 +1503,11 @@ async function runSuite(suite) {
1511
1503
  try {
1512
1504
  await callSuiteHook(suite, "beforeAll", [suite]);
1513
1505
  for (const tasksGroup of partitionSuiteChildren(suite)) {
1514
- const computeMode = tasksGroup[0].computeMode;
1515
- if (computeMode === "serial") {
1506
+ if (tasksGroup[0].concurrent === true) {
1507
+ await Promise.all(tasksGroup.map((c) => runSuiteChild(c)));
1508
+ } else {
1516
1509
  for (const c of tasksGroup)
1517
1510
  await runSuiteChild(c);
1518
- } else if (computeMode === "concurrent") {
1519
- await Promise.all(tasksGroup.map((c) => runSuiteChild(c)));
1520
1511
  }
1521
1512
  }
1522
1513
  await callSuiteHook(suite, "afterAll", [suite]);
@@ -1525,7 +1516,7 @@ async function runSuite(suite) {
1525
1516
  suite.result.error = processError(e);
1526
1517
  }
1527
1518
  }
1528
- suite.result.end = performance.now();
1519
+ suite.result.duration = performance$1.now() - start;
1529
1520
  if (suite.mode === "run") {
1530
1521
  if (!hasTests(suite)) {
1531
1522
  suite.result.state = "fail";