vitest 1.5.3 → 1.6.1

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 (48) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/environments-node.vcoXCoKs.js +19 -0
  4. package/dist/chunks/{integrations-globals.Hr6znn-f.js → integrations-globals.kw4co3rx.js} +3 -3
  5. package/dist/chunks/{runtime-runBaseTests.l6qXp5eU.js → runtime-runBaseTests.oAvMKtQC.js} +8 -9
  6. package/dist/cli.js +2 -2
  7. package/dist/config.cjs +1 -1
  8. package/dist/config.d.ts +1 -1
  9. package/dist/config.js +1 -1
  10. package/dist/coverage.d.ts +1 -1
  11. package/dist/environments.d.ts +1 -1
  12. package/dist/execute.d.ts +6 -4
  13. package/dist/execute.js +3 -3
  14. package/dist/index.d.ts +4 -3
  15. package/dist/index.js +4 -4
  16. package/dist/node.d.ts +2 -2
  17. package/dist/node.js +7 -7
  18. package/dist/{reporters-BXNXFKfg.d.ts → reporters-w_64AS5f.d.ts} +103 -25
  19. package/dist/reporters.d.ts +1 -1
  20. package/dist/reporters.js +5 -5
  21. package/dist/runners.d.ts +1 -1
  22. package/dist/runners.js +2 -2
  23. package/dist/snapshot.d.ts +9 -0
  24. package/dist/snapshot.js +8 -0
  25. package/dist/{suite-KPWE530F.d.ts → suite-dWqIFb_-.d.ts} +1 -1
  26. package/dist/suite.d.ts +2 -2
  27. package/dist/vendor/{base.Xt0Omgh7.js → base.5NT-gWu5.js} +9 -1
  28. package/dist/vendor/{base.oIzAvGLe.js → base.Ybri3C14.js} +2 -2
  29. package/dist/vendor/{cac.RDd_SGOd.js → cac.cdAtVkJZ.js} +38 -15
  30. package/dist/vendor/{cli-api.AmIc1Dmz.js → cli-api.OdDWuB7Y.js} +159 -42
  31. package/dist/vendor/{execute.2_yoIC01.js → execute.fL3szUAI.js} +8 -3
  32. package/dist/vendor/{index.X7lgIMc_.js → index.-xs08BYx.js} +177 -122
  33. package/dist/vendor/{index.Fm6OikHU.js → index.DpVgvm2P.js} +17 -18
  34. package/dist/vendor/{index.QVcwRDVW.js → index.dI9lHwVn.js} +1 -1
  35. package/dist/vendor/{setup-common.5nUd4r76.js → setup-common.8nJLd4ay.js} +1 -1
  36. package/dist/vendor/{utils.VYmeMh-u.js → utils.dEtNIEgr.js} +1 -1
  37. package/dist/vendor/{vi.Y_w82WR8.js → vi.YFlodzP_.js} +1 -1
  38. package/dist/vendor/{vm.i4FO5N37.js → vm.QEE48c0T.js} +131 -41
  39. package/dist/worker.js +8 -2
  40. package/dist/workers/forks.js +4 -4
  41. package/dist/workers/runVmTests.js +10 -8
  42. package/dist/workers/threads.js +4 -4
  43. package/dist/workers/vmForks.js +4 -4
  44. package/dist/workers/vmThreads.js +4 -4
  45. package/dist/workers.d.ts +1 -1
  46. package/dist/workers.js +5 -5
  47. package/package.json +13 -9
  48. package/snapshot.d.ts +1 -0
@@ -1,4 +1,4 @@
1
- import { dirname, resolve, relative, normalize, join, basename, toNamespacedPath, isAbsolute } from 'pathe';
1
+ import { dirname, join, resolve, relative, normalize, basename, toNamespacedPath, isAbsolute } from 'pathe';
2
2
  import { A as API_PATH, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.5J7I254_.js';
3
3
  import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.E7sG1b3r.js';
4
4
  import { g as getEnvPackageName } from './index.GVFv9dZ0.js';
@@ -6,7 +6,7 @@ import { isFileServingAllowed, searchForWorkspaceRoot, version as version$1, cre
6
6
  import path$8 from 'node:path';
7
7
  import url, { fileURLToPath } from 'node:url';
8
8
  import process$1 from 'node:process';
9
- import fs$8, { promises, existsSync, readFileSync } from 'node:fs';
9
+ import fs$8, { promises as promises$1, existsSync, readFileSync } from 'node:fs';
10
10
  import { MessageChannel, isMainThread } from 'node:worker_threads';
11
11
  import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.jjO7Zipk.js';
12
12
  import require$$0 from 'os';
@@ -19,8 +19,8 @@ import c from 'picocolors';
19
19
  import { ViteNodeRunner } from 'vite-node/client';
20
20
  import { SnapshotManager } from '@vitest/snapshot/manager';
21
21
  import { ViteNodeServer } from 'vite-node/server';
22
- import { hasFailed, getTests } from '@vitest/runner/utils';
23
- import { n as noop$2, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, w as wildcardPatternToRegExp, e as stdout } from './base.Xt0Omgh7.js';
22
+ import { hasFailed, getTasks, getTests } from '@vitest/runner/utils';
23
+ import { n as noop$2, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, e as nanoid, w as wildcardPatternToRegExp, f as stdout } from './base.5NT-gWu5.js';
24
24
  import { createDefer, toArray as toArray$1, notNullish } from '@vitest/utils';
25
25
  import { a as isWindows } from './env.AtSIuHFg.js';
26
26
  import { rootDir } from '../path.js';
@@ -34,22 +34,23 @@ import require$$3 from 'net';
34
34
  import require$$4 from 'tls';
35
35
  import require$$7 from 'url';
36
36
  import { parseErrorStacktrace } from '@vitest/utils/source-map';
37
+ import crypto, { createHash as createHash$2 } from 'node:crypto';
37
38
  import v8 from 'node:v8';
38
39
  import * as nodeos from 'node:os';
39
- import nodeos__default from 'node:os';
40
+ import nodeos__default, { tmpdir } from 'node:os';
40
41
  import EventEmitter$2 from 'node:events';
41
42
  import Tinypool$1, { Tinypool } from 'tinypool';
42
- import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as generateCodeFrame, i as highlightCode, L as Logger } from './index.X7lgIMc_.js';
43
+ import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as generateCodeFrame, i as highlightCode, L as Logger } from './index.-xs08BYx.js';
44
+ import { mkdir, writeFile, rm } from 'node:fs/promises';
43
45
  import { resolveModule, isPackageExists } from 'local-pkg';
44
46
  import { isCI, provider as provider$1 } from 'std-env';
45
- import crypto, { createHash as createHash$2 } from 'node:crypto';
46
- import { v as version } from './cac.RDd_SGOd.js';
47
+ import { v as version } from './cac.cdAtVkJZ.js';
47
48
  import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
48
49
  import MagicString from 'magic-string';
49
50
  import { findNodeAround } from 'acorn-walk';
50
51
  import { esmWalker } from '@vitest/utils/ast';
51
52
  import { stripLiteral } from 'strip-literal';
52
- import { d as divider, s as stripAnsi } from './utils.VYmeMh-u.js';
53
+ import { d as divider, s as stripAnsi } from './utils.dEtNIEgr.js';
53
54
  import { createRequire } from 'node:module';
54
55
  import { a as removeUndefinedValues } from './index.SMVOaj7F.js';
55
56
  import readline from 'node:readline';
@@ -329,7 +330,7 @@ async function locatePath(
329
330
  checkType(type);
330
331
  cwd = toPath$1(cwd);
331
332
 
332
- const statFunction = allowSymlinks ? promises.stat : promises.lstat;
333
+ const statFunction = allowSymlinks ? promises$1.stat : promises$1.lstat;
333
334
 
334
335
  return pLocate(paths, async path_ => {
335
336
  try {
@@ -7624,6 +7625,20 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
7624
7625
 
7625
7626
  var WebSocketServer$1 = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
7626
7627
 
7628
+ function isValidApiRequest(config, req) {
7629
+ const url = new URL(req.url ?? "", "http://localhost");
7630
+ try {
7631
+ const token = url.searchParams.get("token");
7632
+ if (token && crypto.timingSafeEqual(
7633
+ Buffer.from(token),
7634
+ Buffer.from(config.api.token)
7635
+ ))
7636
+ return true;
7637
+ } catch {
7638
+ }
7639
+ return false;
7640
+ }
7641
+
7627
7642
  function setup(vitestOrWorkspace, _server) {
7628
7643
  var _a;
7629
7644
  const ctx = "ctx" in vitestOrWorkspace ? vitestOrWorkspace.ctx : vitestOrWorkspace;
@@ -7636,6 +7651,10 @@ function setup(vitestOrWorkspace, _server) {
7636
7651
  const { pathname } = new URL(request.url, "http://localhost");
7637
7652
  if (pathname !== API_PATH)
7638
7653
  return;
7654
+ if (!isValidApiRequest(ctx.config, request)) {
7655
+ socket.destroy();
7656
+ return;
7657
+ }
7639
7658
  wss.handleUpgrade(request, socket, head, (ws) => {
7640
7659
  wss.emit("connection", ws, request);
7641
7660
  setupClient(ws);
@@ -7682,28 +7701,28 @@ function setup(vitestOrWorkspace, _server) {
7682
7701
  checkFileAccess(snapshotPath);
7683
7702
  if (!existsSync(snapshotPath))
7684
7703
  return null;
7685
- return promises.readFile(snapshotPath, "utf-8");
7704
+ return promises$1.readFile(snapshotPath, "utf-8");
7686
7705
  },
7687
7706
  async readTestFile(id) {
7688
7707
  if (!ctx.state.filesMap.has(id) || !existsSync(id))
7689
7708
  return null;
7690
- return promises.readFile(id, "utf-8");
7709
+ return promises$1.readFile(id, "utf-8");
7691
7710
  },
7692
7711
  async saveTestFile(id, content) {
7693
7712
  if (!ctx.state.filesMap.has(id) || !existsSync(id))
7694
7713
  throw new Error(`Test file "${id}" was not registered, so it cannot be updated using the API.`);
7695
- return promises.writeFile(id, content, "utf-8");
7714
+ return promises$1.writeFile(id, content, "utf-8");
7696
7715
  },
7697
7716
  async saveSnapshotFile(id, content) {
7698
7717
  checkFileAccess(id);
7699
- await promises.mkdir(dirname(id), { recursive: true });
7700
- return promises.writeFile(id, content, "utf-8");
7718
+ await promises$1.mkdir(dirname(id), { recursive: true });
7719
+ return promises$1.writeFile(id, content, "utf-8");
7701
7720
  },
7702
7721
  async removeSnapshotFile(id) {
7703
7722
  checkFileAccess(id);
7704
7723
  if (!existsSync(id))
7705
7724
  throw new Error(`Snapshot file "${id}" does not exist.`);
7706
- return promises.unlink(id);
7725
+ return promises$1.unlink(id);
7707
7726
  },
7708
7727
  snapshotSaved(snapshot) {
7709
7728
  ctx.snapshot.add(snapshot);
@@ -7725,7 +7744,7 @@ function setup(vitestOrWorkspace, _server) {
7725
7744
  const result = await ctx.vitenode.transformRequest(id);
7726
7745
  if (result) {
7727
7746
  try {
7728
- result.source = result.source || await promises.readFile(id, "utf-8");
7747
+ result.source = result.source || await promises$1.readFile(id, "utf-8");
7729
7748
  } catch {
7730
7749
  }
7731
7750
  return result;
@@ -7766,6 +7785,10 @@ function setup(vitestOrWorkspace, _server) {
7766
7785
  },
7767
7786
  getProvidedContext() {
7768
7787
  return "ctx" in vitestOrWorkspace ? vitestOrWorkspace.getProvidedContext() : {};
7788
+ },
7789
+ async getTestFiles() {
7790
+ const spec = await ctx.globTestFiles();
7791
+ return spec.map(([project, file]) => [project.getName(), file]);
7769
7792
  }
7770
7793
  },
7771
7794
  {
@@ -7862,7 +7885,7 @@ function getTransformMode(patterns, filename) {
7862
7885
  async function groupFilesByEnv(files) {
7863
7886
  const filesWithEnv = await Promise.all(files.map(async ([project, file]) => {
7864
7887
  var _a, _b;
7865
- const code = await promises.readFile(file, "utf-8");
7888
+ const code = await promises$1.readFile(file, "utf-8");
7866
7889
  let env = (_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1];
7867
7890
  if (!env) {
7868
7891
  for (const [glob, target] of project.config.environmentMatchGlobs || []) {
@@ -7890,6 +7913,8 @@ async function groupFilesByEnv(files) {
7890
7913
  return groupBy(filesWithEnv, ({ environment }) => environment.name);
7891
7914
  }
7892
7915
 
7916
+ const created = /* @__PURE__ */ new Set();
7917
+ const promises = /* @__PURE__ */ new Map();
7893
7918
  function createMethodsRPC(project) {
7894
7919
  const ctx = project.ctx;
7895
7920
  return {
@@ -7908,8 +7933,30 @@ function createMethodsRPC(project) {
7908
7933
  const r = await project.vitenode.transformRequest(id);
7909
7934
  return r == null ? void 0 : r.map;
7910
7935
  },
7911
- fetch(id, transformMode) {
7912
- return project.vitenode.fetchModule(id, transformMode);
7936
+ async fetch(id, transformMode) {
7937
+ const result = await project.vitenode.fetchResult(id, transformMode);
7938
+ const code = result.code;
7939
+ if (result.externalize)
7940
+ return result;
7941
+ if ("id" in result && typeof result.id === "string")
7942
+ return { id: result.id };
7943
+ if (code == null)
7944
+ throw new Error(`Failed to fetch module ${id}`);
7945
+ const dir = join(project.tmpDir, transformMode);
7946
+ const name = createHash$2("sha1").update(id).digest("hex");
7947
+ const tmp = join(dir, name);
7948
+ if (promises.has(tmp)) {
7949
+ await promises.get(tmp);
7950
+ return { id: tmp };
7951
+ }
7952
+ if (!created.has(dir)) {
7953
+ await mkdir(dir, { recursive: true });
7954
+ created.add(dir);
7955
+ }
7956
+ promises.set(tmp, writeFile(tmp, code, "utf-8").finally(() => promises.delete(tmp)));
7957
+ await promises.get(tmp);
7958
+ Object.assign(result, { id: tmp });
7959
+ return { id: tmp };
7913
7960
  },
7914
7961
  resolveId(id, importer, transformMode) {
7915
7962
  return project.vitenode.resolveId(id, importer, transformMode);
@@ -9068,7 +9115,7 @@ const defaultCoverageExcludes = [
9068
9115
  "cypress/**",
9069
9116
  "test?(s)/**",
9070
9117
  "test?(-*).?(c|m)[jt]s?(x)",
9071
- "**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)",
9118
+ "**/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)",
9072
9119
  "**/__tests__/**",
9073
9120
  "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
9074
9121
  "**/vitest.{workspace,projects}.[jt]s?(on)",
@@ -9342,6 +9389,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
9342
9389
  throw new Error("--shard <index> must be a positive number less then <count>");
9343
9390
  resolved.shard = { index, count };
9344
9391
  }
9392
+ if (resolved.standalone && !resolved.watch)
9393
+ throw new Error(`Vitest standalone mode requires --watch`);
9345
9394
  if (resolved.maxWorkers)
9346
9395
  resolved.maxWorkers = Number(resolved.maxWorkers);
9347
9396
  if (resolved.minWorkers)
@@ -9424,6 +9473,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
9424
9473
  resolved.server.deps.moduleDirectories.push(...resolved.deps.moduleDirectories);
9425
9474
  if (resolved.runner)
9426
9475
  resolved.runner = resolvePath(resolved.runner, resolved.root);
9476
+ if (resolved.snapshotEnvironment)
9477
+ resolved.snapshotEnvironment = resolvePath(resolved.snapshotEnvironment, resolved.root);
9427
9478
  resolved.testNamePattern = resolved.testNamePattern ? resolved.testNamePattern instanceof RegExp ? resolved.testNamePattern : new RegExp(resolved.testNamePattern) : void 0;
9428
9479
  if (resolved.snapshotFormat && "plugins" in resolved.snapshotFormat)
9429
9480
  resolved.snapshotFormat.plugins = [];
@@ -9526,6 +9577,10 @@ function resolveConfig(mode, options, viteConfig, logger) {
9526
9577
  resolved.benchmark.reporters = ["default"];
9527
9578
  if (options.outputFile)
9528
9579
  resolved.benchmark.outputFile = options.outputFile;
9580
+ if (options.compare)
9581
+ resolved.benchmark.compare = options.compare;
9582
+ if (options.outputJson)
9583
+ resolved.benchmark.outputJson = options.outputJson;
9529
9584
  }
9530
9585
  resolved.setupFiles = toArray(resolved.setupFiles || []).map(
9531
9586
  (file) => resolvePath(file, resolved.root)
@@ -9542,7 +9597,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
9542
9597
  resolved.diff = resolvePath(resolved.diff, resolved.root);
9543
9598
  resolved.forceRerunTriggers.push(resolved.diff);
9544
9599
  }
9545
- resolved.api = resolveApiServerConfig(options);
9600
+ const api = resolveApiServerConfig(options);
9601
+ resolved.api = { ...api, token: crypto.randomUUID() };
9546
9602
  if (options.related)
9547
9603
  resolved.related = toArray(options.related).map((file) => resolve(resolved.root, file));
9548
9604
  if (options.reporters) {
@@ -10419,6 +10475,8 @@ class WorkspaceProject {
10419
10475
  browserProvider;
10420
10476
  browserState;
10421
10477
  testFilesList = null;
10478
+ id = nanoid();
10479
+ tmpDir = join(tmpdir(), this.id);
10422
10480
  _globalSetups;
10423
10481
  _provided = {};
10424
10482
  getName() {
@@ -10523,7 +10581,7 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
10523
10581
  const files = await this.globFiles(includeSource, exclude, cwd);
10524
10582
  await Promise.all(files.map(async (file) => {
10525
10583
  try {
10526
- const code = await promises.readFile(file, "utf-8");
10584
+ const code = await promises$1.readFile(file, "utf-8");
10527
10585
  if (this.isInSourceTestFile(code))
10528
10586
  testFiles.push(file);
10529
10587
  } catch {
@@ -10554,7 +10612,7 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
10554
10612
  if (mm.isMatch(relativeId, this.config.include))
10555
10613
  return true;
10556
10614
  if (((_a = this.config.includeSource) == null ? void 0 : _a.length) && mm.isMatch(relativeId, this.config.includeSource)) {
10557
- source = source || await promises.readFile(id, "utf-8");
10615
+ source = source || await promises$1.readFile(id, "utf-8");
10558
10616
  return this.isInSourceTestFile(source);
10559
10617
  }
10560
10618
  return false;
@@ -10690,11 +10748,18 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
10690
10748
  this.closingPromise = Promise.all([
10691
10749
  this.server.close(),
10692
10750
  (_a = this.typechecker) == null ? void 0 : _a.stop(),
10693
- (_b = this.browser) == null ? void 0 : _b.close()
10751
+ (_b = this.browser) == null ? void 0 : _b.close(),
10752
+ this.clearTmpDir()
10694
10753
  ].filter(Boolean)).then(() => this._provided = {});
10695
10754
  }
10696
10755
  return this.closingPromise;
10697
10756
  }
10757
+ async clearTmpDir() {
10758
+ try {
10759
+ await rm(this.tmpDir, { force: true, recursive: true });
10760
+ } catch {
10761
+ }
10762
+ }
10698
10763
  async initBrowserProvider() {
10699
10764
  if (!this.isBrowserEnabled())
10700
10765
  return;
@@ -10799,6 +10864,7 @@ class Vitest {
10799
10864
  this.pool = void 0;
10800
10865
  this.coverageProvider = void 0;
10801
10866
  this.runningPromise = void 0;
10867
+ this.distPath = void 0;
10802
10868
  this.projectsTestFiles.clear();
10803
10869
  const resolved = resolveConfig(this.mode, options, server.config, this.logger);
10804
10870
  this.server = server;
@@ -10809,9 +10875,6 @@ class Vitest {
10809
10875
  if (this.config.watch)
10810
10876
  this.registerWatcher();
10811
10877
  this.vitenode = new ViteNodeServer(server, this.config.server);
10812
- const projectVitestPath = await this.vitenode.resolveId("vitest");
10813
- const vitestDir = projectVitestPath ? resolve(projectVitestPath.id, "../..") : rootDir;
10814
- this.distPath = join(vitestDir, "dist");
10815
10878
  const node = this.vitenode;
10816
10879
  this.runner = new ViteNodeRunner({
10817
10880
  root: server.config.root,
@@ -10880,7 +10943,7 @@ class Vitest {
10880
10943
  if (this.config.workspace)
10881
10944
  return this.config.workspace;
10882
10945
  const configDir = this.server.config.configFile ? dirname(this.server.config.configFile) : this.config.root;
10883
- const rootFiles = await promises.readdir(configDir);
10946
+ const rootFiles = await promises$1.readdir(configDir);
10884
10947
  const workspaceConfigName = workspacesFiles.find((configFile) => {
10885
10948
  return rootFiles.includes(configFile);
10886
10949
  });
@@ -10931,7 +10994,7 @@ class Vitest {
10931
10994
  return CONFIG_NAMES.some((configName) => filename.startsWith(configName));
10932
10995
  }).map(async (filepath) => {
10933
10996
  if (filepath.endsWith("/")) {
10934
- const filesInside = await promises.readdir(filepath);
10997
+ const filesInside = await promises$1.readdir(filepath);
10935
10998
  const configFile = configFiles.find((config) => filesInside.includes(config));
10936
10999
  return configFile ? join(filepath, configFile) : filepath;
10937
11000
  }
@@ -11050,6 +11113,20 @@ class Vitest {
11050
11113
  if (this.config.watch)
11051
11114
  await this.report("onWatcherStart");
11052
11115
  }
11116
+ async init() {
11117
+ var _a;
11118
+ this._onClose = [];
11119
+ try {
11120
+ await this.initCoverageProvider();
11121
+ await ((_a = this.coverageProvider) == null ? void 0 : _a.clean(this.config.coverage.clean));
11122
+ await this.initBrowserProviders();
11123
+ } finally {
11124
+ await this.report("onInit", this);
11125
+ }
11126
+ await this.globTestFiles();
11127
+ if (this.config.watch)
11128
+ await this.report("onWatcherStart");
11129
+ }
11053
11130
  async getTestDependencies(filepath, deps = /* @__PURE__ */ new Set()) {
11054
11131
  const addImports = async ([project, filepath2]) => {
11055
11132
  if (deps.has(filepath2))
@@ -11119,7 +11196,15 @@ class Vitest {
11119
11196
  for await (const project of projects)
11120
11197
  await project.initializeGlobalSetup();
11121
11198
  }
11199
+ async initializeDistPath() {
11200
+ if (this.distPath)
11201
+ return;
11202
+ const projectVitestPath = await this.vitenode.resolveId("vitest");
11203
+ const vitestDir = projectVitestPath ? resolve(projectVitestPath.id, "../..") : rootDir;
11204
+ this.distPath = join(vitestDir, "dist");
11205
+ }
11122
11206
  async runFiles(paths, allTestsRun) {
11207
+ await this.initializeDistPath();
11123
11208
  const filepaths = paths.map(([, file]) => file);
11124
11209
  this.state.collectPaths(filepaths);
11125
11210
  await this.report("onPathsCollected", filepaths);
@@ -11183,12 +11268,21 @@ class Vitest {
11183
11268
  async changeNamePattern(pattern, files = this.state.getFilepaths(), trigger) {
11184
11269
  if (pattern === "")
11185
11270
  this.filenamePattern = void 0;
11186
- this.configOverride.testNamePattern = pattern ? new RegExp(pattern) : void 0;
11271
+ const testNamePattern = pattern ? new RegExp(pattern) : void 0;
11272
+ this.configOverride.testNamePattern = testNamePattern;
11273
+ if (testNamePattern) {
11274
+ files = files.filter((filepath) => {
11275
+ const files2 = this.state.getFiles([filepath]);
11276
+ return !files2.length || files2.some((file) => {
11277
+ const tasks = getTasks(file);
11278
+ return !tasks.length || tasks.some((task) => testNamePattern.test(task.name));
11279
+ });
11280
+ });
11281
+ }
11187
11282
  await this.rerunFiles(files, trigger);
11188
11283
  }
11189
- async changeFilenamePattern(pattern) {
11284
+ async changeFilenamePattern(pattern, files = this.state.getFilepaths()) {
11190
11285
  this.filenamePattern = pattern;
11191
- const files = this.state.getFilepaths();
11192
11286
  const trigger = this.filenamePattern ? "change filename pattern" : "reset filename pattern";
11193
11287
  await this.rerunFiles(files, trigger);
11194
11288
  }
@@ -11300,8 +11394,11 @@ class Vitest {
11300
11394
  updateLastChanged(id);
11301
11395
  const matchingProjects = [];
11302
11396
  await Promise.all(this.projects.map(async (project) => {
11303
- if (await project.isTargetFile(id))
11397
+ var _a;
11398
+ if (await project.isTargetFile(id)) {
11304
11399
  matchingProjects.push(project);
11400
+ (_a = project.testFilesList) == null ? void 0 : _a.push(id);
11401
+ }
11305
11402
  }));
11306
11403
  if (matchingProjects.length > 0) {
11307
11404
  this.projectsTestFiles.set(id, new Set(matchingProjects));
@@ -11445,6 +11542,9 @@ class Vitest {
11445
11542
  );
11446
11543
  }));
11447
11544
  }
11545
+ async getTestFilepaths() {
11546
+ return this.globTestFiles().then((files) => files.map(([, file]) => file));
11547
+ }
11448
11548
  async globTestFiles(filters = []) {
11449
11549
  const files = [];
11450
11550
  await Promise.all(this.projects.map(async (project) => {
@@ -18073,6 +18173,9 @@ ${resultBody}`;
18073
18173
  write(data) {
18074
18174
  this.stdout.write(data);
18075
18175
  }
18176
+ getLastResults() {
18177
+ return this.results;
18178
+ }
18076
18179
  }
18077
18180
 
18078
18181
  const keys = [
@@ -18124,8 +18227,10 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
18124
18227
  return printShortcutsHelp();
18125
18228
  if (name === "u")
18126
18229
  return ctx.updateSnapshot();
18127
- if (name === "a" || name === "return")
18128
- return ctx.changeNamePattern("");
18230
+ if (name === "a" || name === "return") {
18231
+ const files = await ctx.getTestFilepaths();
18232
+ return ctx.changeNamePattern("", files, "rerun all tests");
18233
+ }
18129
18234
  if (name === "r")
18130
18235
  return ctx.rerunFiles();
18131
18236
  if (name === "f")
@@ -18144,8 +18249,8 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
18144
18249
  off();
18145
18250
  const watchFilter = new WatchFilter("Input test name pattern (RegExp)", stdin, stdout2);
18146
18251
  const filter = await watchFilter.filter((str) => {
18147
- const files = ctx.state.getFiles();
18148
- const tests = getTests(files);
18252
+ const files2 = ctx.state.getFiles();
18253
+ const tests = getTests(files2);
18149
18254
  try {
18150
18255
  const reg = new RegExp(str);
18151
18256
  return tests.map((test) => test.name).filter((testName) => testName.match(reg));
@@ -18154,7 +18259,9 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
18154
18259
  }
18155
18260
  });
18156
18261
  on();
18157
- await ctx.changeNamePattern((filter == null ? void 0 : filter.trim()) || "", void 0, "change pattern");
18262
+ const files = ctx.state.getFilepaths();
18263
+ const cliFiles = ctx.config.standalone && !files.length ? await ctx.getTestFilepaths() : void 0;
18264
+ await ctx.changeNamePattern((filter == null ? void 0 : filter.trim()) || "", cliFiles, "change pattern");
18158
18265
  }
18159
18266
  async function inputProjectName() {
18160
18267
  off();
@@ -18178,7 +18285,11 @@ function registerConsoleShortcuts(ctx, stdin = process.stdin, stdout2) {
18178
18285
  });
18179
18286
  on();
18180
18287
  latestFilename = (filter == null ? void 0 : filter.trim()) || "";
18181
- await ctx.changeFilenamePattern(latestFilename);
18288
+ const lastResults = watchFilter.getLastResults();
18289
+ await ctx.changeFilenamePattern(
18290
+ latestFilename,
18291
+ filter && lastResults.length ? lastResults.map((i) => resolve(ctx.config.root, i)) : void 0
18292
+ );
18182
18293
  }
18183
18294
  let rl;
18184
18295
  function on() {
@@ -18241,10 +18352,16 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
18241
18352
  process.exit(EXIT_CODE_RESTART);
18242
18353
  });
18243
18354
  ctx.onAfterSetServer(() => {
18244
- ctx.start(cliFilters);
18355
+ if (ctx.config.standalone)
18356
+ ctx.init();
18357
+ else
18358
+ ctx.start(cliFilters);
18245
18359
  });
18246
18360
  try {
18247
- await ctx.start(cliFilters);
18361
+ if (ctx.config.standalone)
18362
+ await ctx.init();
18363
+ else
18364
+ await ctx.start(cliFilters);
18248
18365
  } catch (e) {
18249
18366
  process.exitCode = 1;
18250
18367
  await ctx.logger.printError(e, { fullStack: true, type: "Unhandled Error" });
@@ -1,13 +1,13 @@
1
1
  import vm from 'node:vm';
2
2
  import { pathToFileURL } from 'node:url';
3
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
3
4
  import { ViteNodeRunner, DEFAULT_REQUEST_STUBS } from 'vite-node/client';
4
5
  import { isNodeBuiltin, isInternalRequest, toFilePath, isPrimitive } from 'vite-node/utils';
5
6
  import { resolve, isAbsolute, dirname, join, basename, extname, normalize, relative } from 'pathe';
6
7
  import { processError } from '@vitest/utils/error';
7
8
  import { distDir } from '../path.js';
8
- import { existsSync, readdirSync } from 'node:fs';
9
9
  import { highlight, getType } from '@vitest/utils';
10
- import { g as getAllMockableProperties } from './base.Xt0Omgh7.js';
10
+ import { g as getAllMockableProperties } from './base.5NT-gWu5.js';
11
11
 
12
12
  const spyModulePath = resolve(distDir, "spy.js");
13
13
  class RefTracker {
@@ -418,7 +418,12 @@ async function startVitestExecutor(options) {
418
418
  externalizeMap.set(id, id);
419
419
  return { externalize: id };
420
420
  }
421
- return rpc().fetch(id, getTransformMode());
421
+ const result = await rpc().fetch(id, getTransformMode());
422
+ if (result.id && !result.externalize) {
423
+ const code = readFileSync(result.id, "utf-8");
424
+ return { code };
425
+ }
426
+ return result;
422
427
  },
423
428
  resolveId(id, importer) {
424
429
  return rpc().resolveId(id, importer, getTransformMode());