vitest 0.0.124 → 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/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
@@ -8,7 +8,7 @@ import { m as mergeStream, g as getStream, c as crossSpawn } from './index-6e709
8
8
  import require$$0, { constants } from 'os';
9
9
  import { s as signalExit } from './index-648e7ab2.js';
10
10
  import { e as ensurePackageInstalled } from './index-9fdde2e8.js';
11
- import { c as createVitest } from './index-0963bf06.js';
11
+ import { c as createVitest } from './index-37193236.js';
12
12
  import './_commonjsHelpers-c9e3b764.js';
13
13
  import 'fs';
14
14
  import 'stream';
@@ -21,7 +21,7 @@ import 'vite';
21
21
  import './constants-8b3a9b31.js';
22
22
  import './magic-string.es-94000aea.js';
23
23
  import 'perf_hooks';
24
- import './diff-aeba6bd6.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.124";
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;
@@ -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
@@ -7,7 +7,7 @@ import chai$1, { expect, util } from 'chai';
7
7
  import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
8
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-aeba6bd6.js';
10
+ import { l as getOriginalPos, m as posToNumber, n as parseStacktrace, u as unifiedDiff } from './diff-3adb959a.js';
11
11
  import { performance as performance$1 } from 'perf_hooks';
12
12
  import { createHash } from 'crypto';
13
13
  import { format } from 'util';
@@ -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;
@@ -1320,9 +1318,6 @@ function processError(err) {
1320
1318
  function hash(str, length = 10) {
1321
1319
  return createHash("md5").update(str).digest("hex").slice(0, length);
1322
1320
  }
1323
- function inModuleGraph(files) {
1324
- return files.some((file) => process.__vitest_worker__.moduleCache.has(file));
1325
- }
1326
1321
  async function collectTests(paths, config) {
1327
1322
  const files = [];
1328
1323
  for (const filepath of paths) {
@@ -1339,8 +1334,6 @@ async function collectTests(paths, config) {
1339
1334
  try {
1340
1335
  await runSetupFiles(config);
1341
1336
  await import(filepath);
1342
- if (config.findRelatedTests && !inModuleGraph(config.findRelatedTests))
1343
- continue;
1344
1337
  const defaultTasks = await defaultSuite.collect(file);
1345
1338
  setHooks(file, getHooks(defaultTasks));
1346
1339
  for (const c of [...defaultTasks.tasks, ...context.tasks]) {
@@ -1,8 +1,8 @@
1
+ import fs$8, { promises, existsSync } from 'fs';
1
2
  import { c, s as slash$1, a as isAbsolute, r as relative, d as dirname, b as basename, g as getFullName, h as hasFailed, f as getSuites, j as getTests, t as toArray, k as resolve, l as deepMerge, m as toFilePath, n as noop$1, e as ensurePackageInstalled } from './index-9fdde2e8.js';
2
3
  import { createServer, mergeConfig } from 'vite';
3
4
  import path$a from 'path';
4
5
  import process$1 from 'process';
5
- import fs$8, { promises, existsSync } from 'fs';
6
6
  import require$$0 from 'os';
7
7
  import require$$0$1 from 'util';
8
8
  import require$$0$2 from 'stream';
@@ -10,7 +10,7 @@ import require$$2 from 'events';
10
10
  import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-8b3a9b31.js';
11
11
  import MagicString from './magic-string.es-94000aea.js';
12
12
  import { performance } from 'perf_hooks';
13
- import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-aeba6bd6.js';
13
+ import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-3adb959a.js';
14
14
  import { o as onetime, s as signalExit } from './index-648e7ab2.js';
15
15
  import { createRequire } from 'module';
16
16
  import { pathToFileURL } from 'url';
@@ -7980,8 +7980,8 @@ function resolveConfig(options, viteConfig) {
7980
7980
  resolved.setupFiles = Array.from(resolved.setupFiles || []).map((i) => resolve(resolved.root, i));
7981
7981
  if (resolved.api === true)
7982
7982
  resolved.api = defaultPort;
7983
- if (options.findRelatedTests)
7984
- resolved.findRelatedTests = toArray(options.findRelatedTests).map((file) => resolve(resolved.root, file));
7983
+ if (options.related)
7984
+ resolved.related = toArray(options.related).map((file) => resolve(resolved.root, file));
7985
7985
  return resolved;
7986
7986
  }
7987
7987
 
@@ -8188,7 +8188,7 @@ class Vitest {
8188
8188
  }
8189
8189
  async start(filters) {
8190
8190
  this.report("onInit", this);
8191
- const files = await this.globTestFiles(filters);
8191
+ const files = await this.filterTestsBySource(await this.globTestFiles(filters));
8192
8192
  if (!files.length) {
8193
8193
  if (this.config.passWithNoTests)
8194
8194
  this.log("No test files found\n");
@@ -8202,6 +8202,42 @@ class Vitest {
8202
8202
  if (this.config.coverage.enabled)
8203
8203
  await reportCoverage(this);
8204
8204
  }
8205
+ async getTestDependencies(filepath) {
8206
+ const deps = new Set();
8207
+ const addImports = async (filepath2) => {
8208
+ const transformed = await this.server.transformRequest(filepath2, { ssr: true });
8209
+ if (!transformed)
8210
+ return;
8211
+ const dependencies = [...transformed.deps || [], ...transformed.dynamicDeps || []];
8212
+ for (const dep of dependencies) {
8213
+ const path = await this.server.pluginContainer.resolveId(dep, filepath2, { ssr: true });
8214
+ const fsPath = path && !path.external && path.id.split("?")[0];
8215
+ if (fsPath && !fsPath.includes("node_modules") && !deps.has(fsPath) && existsSync(fsPath)) {
8216
+ deps.add(fsPath);
8217
+ await addImports(fsPath);
8218
+ }
8219
+ }
8220
+ };
8221
+ await addImports(filepath);
8222
+ return deps;
8223
+ }
8224
+ async filterTestsBySource(tests) {
8225
+ const related = this.config.related;
8226
+ if (!related)
8227
+ return tests;
8228
+ if (!related.length)
8229
+ return [];
8230
+ const testDeps = await Promise.all(tests.map(async (filepath) => {
8231
+ const deps = await this.getTestDependencies(filepath);
8232
+ return [filepath, deps];
8233
+ }));
8234
+ const runningTests = [];
8235
+ for (const [filepath, deps] of testDeps) {
8236
+ if (deps.size && related.some((path) => deps.has(path)))
8237
+ runningTests.push(filepath);
8238
+ }
8239
+ return runningTests;
8240
+ }
8205
8241
  async runFiles(files) {
8206
8242
  await this.runningPromise;
8207
8243
  this.runningPromise = (async () => {
@@ -8365,7 +8401,7 @@ async function createVitest(options, viteOverrides = {}) {
8365
8401
  await ctx.setServer(options, server2);
8366
8402
  haveStarted = true;
8367
8403
  if (options.api)
8368
- (await import('./setup-e485f26d.js')).setup(ctx);
8404
+ (await import('./setup-b0d2ca33.js')).setup(ctx);
8369
8405
  }
8370
8406
  },
8371
8407
  MocksPlugin(),
package/dist/index.d.ts CHANGED
@@ -212,6 +212,8 @@ declare class Vitest {
212
212
  constructor();
213
213
  setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
214
214
  start(filters?: string[]): Promise<void>;
215
+ private getTestDependencies;
216
+ filterTestsBySource(tests: string[]): Promise<string[]>;
215
217
  runFiles(files: string[]): Promise<void>;
216
218
  log(...args: any[]): void;
217
219
  error(...args: any[]): void;
@@ -369,6 +371,18 @@ interface ParsedStack {
369
371
  file: string;
370
372
  line: number;
371
373
  column: number;
374
+ sourcePos?: Position;
375
+ }
376
+ interface ErrorWithDiff extends Error {
377
+ name: string;
378
+ nameStr?: string;
379
+ stack?: string;
380
+ stackStr?: string;
381
+ stacks?: ParsedStack[];
382
+ showDiff?: boolean;
383
+ actual?: any;
384
+ expected?: any;
385
+ operator?: string;
372
386
  }
373
387
 
374
388
  declare type ChainableFunction<T extends string, Args extends any[], R = any> = {
@@ -391,7 +405,7 @@ interface TaskBase {
391
405
  interface TaskResult {
392
406
  state: TaskState;
393
407
  duration?: number;
394
- error?: unknown;
408
+ error?: ErrorWithDiff;
395
409
  }
396
410
  declare type TaskResultPack = [id: string, result: TaskResult | undefined];
397
411
  interface Suite extends TaskBase {
@@ -693,13 +707,13 @@ interface UserConfig extends InlineConfig {
693
707
  /**
694
708
  * Run tests that cover a list of source files
695
709
  */
696
- findRelatedTests?: string[] | string;
710
+ related?: string[] | string;
697
711
  }
698
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'findRelatedTests'> {
712
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related'> {
699
713
  config?: string;
700
714
  filters?: string[];
701
715
  testNamePattern?: RegExp;
702
- findRelatedTests?: string[];
716
+ related?: string[];
703
717
  depsInline: (string | RegExp)[];
704
718
  depsExternal: (string | RegExp)[];
705
719
  fallbackCJS: boolean;
@@ -896,7 +910,8 @@ declare const vi: VitestUtils;
896
910
  interface WebSocketHandlers {
897
911
  getFiles(): File[];
898
912
  getConfig(): ResolvedConfig;
899
- getSourceCode(id: string): Promise<string>;
913
+ readFile(id: string): Promise<string>;
914
+ writeFile(id: string, content: string): Promise<void>;
900
915
  getModuleGraph(id: string): Promise<{
901
916
  graph: Record<string, string[]>;
902
917
  externalized: string[];
@@ -996,4 +1011,4 @@ declare global {
996
1011
  }
997
1012
  }
998
1013
 
999
- export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ConstructorArgumentsOf, DoneCallback, EnhancedSpy, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable, ParsedStack, Position, PropertyKeysOf, Reporter, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
1014
+ export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ConstructorArgumentsOf, DoneCallback, EnhancedSpy, Environment, EnvironmentReturn, ErrorWithDiff, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable, ParsedStack, Position, PropertyKeysOf, Reporter, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
package/dist/node.d.ts CHANGED
@@ -122,6 +122,28 @@ interface UserConsoleLog {
122
122
  type: 'stdout' | 'stderr';
123
123
  taskId?: string;
124
124
  }
125
+ interface Position {
126
+ line: number;
127
+ column: number;
128
+ }
129
+ interface ParsedStack {
130
+ method: string;
131
+ file: string;
132
+ line: number;
133
+ column: number;
134
+ sourcePos?: Position;
135
+ }
136
+ interface ErrorWithDiff extends Error {
137
+ name: string;
138
+ nameStr?: string;
139
+ stack?: string;
140
+ stackStr?: string;
141
+ stacks?: ParsedStack[];
142
+ showDiff?: boolean;
143
+ actual?: any;
144
+ expected?: any;
145
+ operator?: string;
146
+ }
125
147
 
126
148
  declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
127
149
  declare type TaskState = RunMode | 'pass' | 'fail';
@@ -137,7 +159,7 @@ interface TaskBase {
137
159
  interface TaskResult {
138
160
  state: TaskState;
139
161
  duration?: number;
140
- error?: unknown;
162
+ error?: ErrorWithDiff;
141
163
  }
142
164
  declare type TaskResultPack = [id: string, result: TaskResult | undefined];
143
165
  interface Suite extends TaskBase {
@@ -401,13 +423,13 @@ interface UserConfig extends InlineConfig {
401
423
  /**
402
424
  * Run tests that cover a list of source files
403
425
  */
404
- findRelatedTests?: string[] | string;
426
+ related?: string[] | string;
405
427
  }
406
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'findRelatedTests'> {
428
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related'> {
407
429
  config?: string;
408
430
  filters?: string[];
409
431
  testNamePattern?: RegExp;
410
- findRelatedTests?: string[];
432
+ related?: string[];
411
433
  depsInline: (string | RegExp)[];
412
434
  depsExternal: (string | RegExp)[];
413
435
  fallbackCJS: boolean;
@@ -466,6 +488,8 @@ declare class Vitest {
466
488
  constructor();
467
489
  setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
468
490
  start(filters?: string[]): Promise<void>;
491
+ private getTestDependencies;
492
+ filterTestsBySource(tests: string[]): Promise<string[]>;
469
493
  runFiles(files: string[]): Promise<void>;
470
494
  log(...args: any[]): void;
471
495
  error(...args: any[]): void;
package/dist/node.js CHANGED
@@ -1,4 +1,5 @@
1
- export { c as createVitest } from './index-0963bf06.js';
1
+ export { c as createVitest } from './index-37193236.js';
2
+ import 'fs';
2
3
  import './index-9fdde2e8.js';
3
4
  import 'url';
4
5
  import 'tty';
@@ -6,7 +7,6 @@ import 'local-pkg';
6
7
  import 'path';
7
8
  import 'vite';
8
9
  import 'process';
9
- import 'fs';
10
10
  import 'os';
11
11
  import 'util';
12
12
  import 'stream';
@@ -14,7 +14,7 @@ import 'events';
14
14
  import './constants-8b3a9b31.js';
15
15
  import './magic-string.es-94000aea.js';
16
16
  import 'perf_hooks';
17
- import './diff-aeba6bd6.js';
17
+ import './diff-3adb959a.js';
18
18
  import './index-648e7ab2.js';
19
19
  import './_commonjsHelpers-c9e3b764.js';
20
20
  import 'assert';
@@ -11,6 +11,7 @@ import require$$2$1 from 'http';
11
11
  import require$$7 from 'url';
12
12
  import { A as API_PATH } from './constants-8b3a9b31.js';
13
13
  import { s as shouldExternalize } from './externalize-2f63779d.js';
14
+ import { o as interpretSourcePos, n as parseStacktrace } from './diff-3adb959a.js';
14
15
  import './index-9fdde2e8.js';
15
16
  import 'tty';
16
17
  import 'local-pkg';
@@ -4270,9 +4271,12 @@ function setup(ctx) {
4270
4271
  getFiles() {
4271
4272
  return ctx.state.getFiles();
4272
4273
  },
4273
- getSourceCode(id) {
4274
+ readFile(id) {
4274
4275
  return promises.readFile(id, "utf-8");
4275
4276
  },
4277
+ writeFile(id, content) {
4278
+ return promises.writeFile(id, content, "utf-8");
4279
+ },
4276
4280
  async rerun(files) {
4277
4281
  await ctx.report("onWatcherRerun", files);
4278
4282
  await ctx.runFiles(files);
@@ -4335,12 +4339,21 @@ class WebSocketReporter {
4335
4339
  this.clients = clients;
4336
4340
  }
4337
4341
  onCollected(files) {
4342
+ if (this.clients.size === 0)
4343
+ return;
4338
4344
  this.clients.forEach((client) => {
4339
4345
  var _a;
4340
4346
  (_a = client.onCollected) == null ? void 0 : _a.call(client, files);
4341
4347
  });
4342
4348
  }
4343
- onTaskUpdate(packs) {
4349
+ async onTaskUpdate(packs) {
4350
+ if (this.clients.size === 0)
4351
+ return;
4352
+ await Promise.all(packs.map(async (i) => {
4353
+ var _a;
4354
+ if ((_a = i[1]) == null ? void 0 : _a.error)
4355
+ await interpretSourcePos(parseStacktrace(i[1].error), this.ctx);
4356
+ }));
4344
4357
  this.clients.forEach((client) => {
4345
4358
  var _a;
4346
4359
  (_a = client.onTaskUpdate) == null ? void 0 : _a.call(client, packs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.124",
3
+ "version": "0.0.125",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -8,13 +8,13 @@
8
8
  "test",
9
9
  "jest"
10
10
  ],
11
- "homepage": "https://github.com/antfu/vitest#readme",
11
+ "homepage": "https://github.com/vitest-dev/vitest#readme",
12
12
  "bugs": {
13
- "url": "https://github.com/antfu/vitest/issues"
13
+ "url": "https://github.com/vitest-dev/vitest/issues"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/antfu/vitest.git"
17
+ "url": "git+https://github.com/vitest-dev/vitest.git"
18
18
  },
19
19
  "funding": "https://github.com/sponsors/antfu",
20
20
  "license": "MIT",
@@ -91,7 +91,7 @@
91
91
  "strip-ansi": "^7.0.1",
92
92
  "typescript": "^4.5.4",
93
93
  "ws": "^8.4.0",
94
- "@vitest/ui": "0.0.124"
94
+ "@vitest/ui": "0.0.125"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "c8": "*",
@@ -120,5 +120,5 @@
120
120
  "build": "rimraf dist && rollup -c",
121
121
  "dev": "rollup -c --watch src"
122
122
  },
123
- "readme": "# vitest\n\n[![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)\n\nA blazing fast unit test framework powered by Vite.\n\n> **This project is currently in closed beta exclusively for Sponsors.**<br>\n> 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.\n> Learn more at [vitest.dev](https://vitest.dev)\n"
123
+ "readme": "# vitest\n\n[![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)\n\nA blazing fast unit test framework powered by Vite.\n\n[GitHub](https://github.com/vitest-dev/vitest) | [Documentation](https://vitest.dev/)\n"
124
124
  }