vitest 0.0.121 → 0.0.125

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/LICENSE.md CHANGED
@@ -166,7 +166,7 @@ Repository: chalk/ansi-regex
166
166
 
167
167
  > MIT License
168
168
  >
169
- > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
169
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
170
170
  >
171
171
  > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
172
172
  >
@@ -183,7 +183,7 @@ Repository: chalk/ansi-styles
183
183
 
184
184
  > MIT License
185
185
  >
186
- > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
186
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
187
187
  >
188
188
  > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
189
189
  >
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-37193236.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.121";
1703
+ var version = "0.0.125";
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 };