vitest 0.34.0 → 0.34.2

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 (35) hide show
  1. package/LICENSE.md +28 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +1 -1
  4. package/dist/child.js +11 -6
  5. package/dist/{chunk-api-setup.644415c3.js → chunk-api-setup.cc5282f7.js} +25 -15
  6. package/dist/{chunk-install-pkg.dd70081b.js → chunk-install-pkg.7e19b3a0.js} +6 -3
  7. package/dist/{chunk-integrations-globals.877c84db.js → chunk-integrations-globals.522ae1ae.js} +4 -3
  8. package/dist/cli.js +6 -3
  9. package/dist/config.d.ts +1 -1
  10. package/dist/coverage.d.ts +1 -1
  11. package/dist/entry-vm.js +4 -3
  12. package/dist/entry.js +4 -3
  13. package/dist/environments.d.ts +1 -1
  14. package/dist/environments.js +11 -2
  15. package/dist/execute.d.ts +139 -0
  16. package/dist/execute.js +1 -1
  17. package/dist/index.d.ts +10 -9
  18. package/dist/index.js +5 -4
  19. package/dist/loader.js +9 -528
  20. package/dist/node.d.ts +2 -2
  21. package/dist/node.js +6 -3
  22. package/dist/runners.d.ts +1 -1
  23. package/dist/runners.js +3 -2
  24. package/dist/{types-3c7dbfa5.d.ts → types-63abf2e0.d.ts} +63 -2
  25. package/dist/{vendor-environments.443ecd82.js → vendor-environments.37f266a9.js} +13 -6
  26. package/dist/{vendor-execute.9ab1c1a7.js → vendor-execute.4fc8203a.js} +409 -206
  27. package/dist/vendor-index.0b5b3600.js +2062 -0
  28. package/dist/{vendor-index.eff408fd.js → vendor-index.b5efbd68.js} +1 -1
  29. package/dist/{vendor-node.00226ab1.js → vendor-node.7b1bd3c5.js} +196 -122
  30. package/dist/vendor-tasks.f9d75aed.js +14 -0
  31. package/dist/{vendor-vi.271667ef.js → vendor-vi.f8055ff2.js} +2 -1
  32. package/dist/vm.js +14 -6
  33. package/dist/worker.js +12 -6
  34. package/package.json +7 -7
  35. package/dist/vendor-source-map.e6c1997b.js +0 -747
@@ -1,5 +1,5 @@
1
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
- import { e as bench, c as createExpect, d as globalExpect, v as vi, f as vitest } from './vendor-vi.271667ef.js';
2
+ import { e as bench, c as createExpect, d as globalExpect, v as vi, f as vitest } from './vendor-vi.f8055ff2.js';
3
3
  import { i as isFirstRun, r as runOnce } from './vendor-run-once.3e5ef7d7.js';
4
4
  import * as chai from 'chai';
5
5
  import { assert, should } from 'chai';
@@ -1,5 +1,5 @@
1
1
  import { resolve, relative, isAbsolute, dirname, basename, normalize, join, extname, toNamespacedPath } from 'pathe';
2
- import { loadConfigFromFile, createServer, version as version$2, mergeConfig } from 'vite';
2
+ import { loadConfigFromFile, version as version$2, searchForWorkspaceRoot, createServer, mergeConfig } from 'vite';
3
3
  import path$a from 'node:path';
4
4
  import url, { fileURLToPath, pathToFileURL } from 'node:url';
5
5
  import process$1 from 'node:process';
@@ -31,8 +31,9 @@ import { createDefer, getSafeTimers, notNullish, shuffle, inspect, positionToOff
31
31
  import { isPackageExists, resolveModule } from 'local-pkg';
32
32
  import { isCI } from 'std-env';
33
33
  import { performance } from 'node:perf_hooks';
34
- import { g as getFullName, h as hasFailedSnapshot, p as parseErrorStacktrace, T as TraceMap, b as generatedPositionFor } from './vendor-source-map.e6c1997b.js';
34
+ import { g as getFullName, h as hasFailedSnapshot } from './vendor-tasks.f9d75aed.js';
35
35
  import { getTests, hasFailed, getSuites, generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, getTasks } from '@vitest/runner/utils';
36
+ import { parseErrorStacktrace, TraceMap, generatedPositionFor } from '@vitest/utils/source-map';
36
37
  import { createRequire, builtinModules } from 'node:module';
37
38
  import { createHash } from 'node:crypto';
38
39
  import { o as onExit, e as execa } from './vendor-index.1f85e5f1.js';
@@ -42,7 +43,7 @@ import { parse as parse$4 } from 'acorn';
42
43
  import { ancestor, simple, findNodeAround } from 'acorn-walk';
43
44
  import MagicString from 'magic-string';
44
45
  import { stripLiteral } from 'strip-literal';
45
- import { g as getEnvPackageName } from './vendor-environments.443ecd82.js';
46
+ import { g as getEnvPackageName } from './vendor-environments.37f266a9.js';
46
47
  import readline from 'node:readline';
47
48
  import require$$0$2 from 'readline';
48
49
 
@@ -61,7 +62,7 @@ function _mergeNamespaces(n, m) {
61
62
  return Object.freeze(n);
62
63
  }
63
64
 
64
- var version$1 = "0.34.0";
65
+ var version$1 = "0.34.2";
65
66
 
66
67
  const __dirname$1 = url.fileURLToPath(new URL(".", import.meta.url));
67
68
  async function ensurePackageInstalled(dependency, root) {
@@ -80,7 +81,7 @@ async function ensurePackageInstalled(dependency, root) {
80
81
  message: c.reset(`Do you want to install ${c.green(dependency)}?`)
81
82
  });
82
83
  if (install) {
83
- await (await import('./chunk-install-pkg.dd70081b.js')).installPackage(dependency, { dev: true });
84
+ await (await import('./chunk-install-pkg.7e19b3a0.js')).installPackage(dependency, { dev: true });
84
85
  process.stderr.write(c.yellow(`
85
86
  Package ${dependency} installed, re-run the command to start.
86
87
  `));
@@ -7085,13 +7086,14 @@ async function groupFilesByEnv(files) {
7085
7086
  env || (env = project.config.environment || "node");
7086
7087
  const transformMode = getTransformMode(project.config.testTransformMode, file);
7087
7088
  const envOptions = JSON.parse(((_b = code.match(/@(?:vitest|jest)-environment-options\s+?(.+)/)) == null ? void 0 : _b[1]) || "null");
7089
+ const envKey = env === "happy-dom" ? "happyDOM" : env;
7088
7090
  return {
7089
7091
  file,
7090
7092
  project,
7091
7093
  environment: {
7092
7094
  name: env,
7093
7095
  transformMode,
7094
- options: envOptions ? { [env]: envOptions } : null
7096
+ options: envOptions ? { [envKey]: envOptions } : null
7095
7097
  }
7096
7098
  };
7097
7099
  }));
@@ -7126,6 +7128,9 @@ function createMethodsRPC(project) {
7126
7128
  resolveId(id, importer, transformMode) {
7127
7129
  return project.vitenode.resolveId(id, importer, transformMode);
7128
7130
  },
7131
+ transform(id, environment) {
7132
+ return project.vitenode.transformModule(id, environment);
7133
+ },
7129
7134
  onPathsCollected(paths) {
7130
7135
  ctx.state.collectPaths(paths);
7131
7136
  project.report("onPathsCollected", paths);
@@ -7479,7 +7484,7 @@ function createBrowserPool(ctx) {
7479
7484
  }
7480
7485
 
7481
7486
  const workerPath = pathToFileURL(resolve(distDir, "./vm.js")).href;
7482
- const suppressLoaderWarningsPath$1 = resolve(rootDir, "./suppress-warnings.cjs");
7487
+ const suppressWarningsPath = resolve(rootDir, "./suppress-warnings.cjs");
7483
7488
  function createWorkerChannel(project) {
7484
7489
  const channel = new MessageChannel();
7485
7490
  const port = channel.port2;
@@ -7515,10 +7520,11 @@ function createVmThreadsPool(ctx, { execArgv, env }) {
7515
7520
  "--experimental-import-meta-resolve",
7516
7521
  "--experimental-vm-modules",
7517
7522
  "--require",
7518
- suppressLoaderWarningsPath$1,
7523
+ suppressWarningsPath,
7519
7524
  ...execArgv
7520
7525
  ],
7521
- terminateTimeout: ctx.config.teardownTimeout
7526
+ terminateTimeout: ctx.config.teardownTimeout,
7527
+ maxMemoryLimitBeforeRecycle: ctx.config.experimentalVmWorkerMemoryLimit || void 0
7522
7528
  };
7523
7529
  if (ctx.config.singleThread) {
7524
7530
  options.concurrentTasksPerWorker = 1;
@@ -10300,6 +10306,16 @@ class StateManager {
10300
10306
  err.type = type;
10301
10307
  else
10302
10308
  err = { type, message: err };
10309
+ const _err = err;
10310
+ if (_err && typeof _err === "object" && _err.code === "VITEST_PENDING") {
10311
+ const task = this.idMap.get(_err.taskId);
10312
+ if (task) {
10313
+ task.mode = "skip";
10314
+ task.result ?? (task.result = { state: "skip" });
10315
+ task.result.state = "skip";
10316
+ }
10317
+ return;
10318
+ }
10303
10319
  this.errorsSet.add(err);
10304
10320
  }
10305
10321
  clearErrors() {
@@ -10375,6 +10391,8 @@ class StateManager {
10375
10391
  if (task) {
10376
10392
  task.result = result;
10377
10393
  task.meta = meta;
10394
+ if ((result == null ? void 0 : result.state) === "skip")
10395
+ task.mode = "skip";
10378
10396
  }
10379
10397
  }
10380
10398
  }
@@ -10773,7 +10791,7 @@ function resolveApiServerConfig(options) {
10773
10791
  return api;
10774
10792
  }
10775
10793
  function resolveConfig(mode, options, viteConfig) {
10776
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
10794
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
10777
10795
  if (options.dom) {
10778
10796
  if (((_a = viteConfig.test) == null ? void 0 : _a.environment) != null && viteConfig.test.environment !== "happy-dom") {
10779
10797
  console.warn(
@@ -10828,8 +10846,12 @@ function resolveConfig(mode, options, viteConfig) {
10828
10846
  });
10829
10847
  if (!resolved.deps.moduleDirectories.includes("/node_modules/"))
10830
10848
  resolved.deps.moduleDirectories.push("/node_modules/");
10849
+ (_c = resolved.deps).web ?? (_c.web = {});
10850
+ (_d = resolved.deps.web).transformAssets ?? (_d.transformAssets = true);
10851
+ (_e = resolved.deps.web).transformCss ?? (_e.transformCss = true);
10852
+ (_f = resolved.deps.web).transformGlobPattern ?? (_f.transformGlobPattern = []);
10831
10853
  resolved.server ?? (resolved.server = {});
10832
- (_c = resolved.server).deps ?? (_c.deps = {});
10854
+ (_g = resolved.server).deps ?? (_g.deps = {});
10833
10855
  const deprecatedDepsOptions = ["inline", "external", "fallbackCJS"];
10834
10856
  deprecatedDepsOptions.forEach((option) => {
10835
10857
  if (resolved.deps[option] === void 0)
@@ -10852,11 +10874,11 @@ function resolveConfig(mode, options, viteConfig) {
10852
10874
  if ((ssrOptions == null ? void 0 : ssrOptions.noExternal) === true && resolved.server.deps.inline == null) {
10853
10875
  resolved.server.deps.inline = true;
10854
10876
  } else {
10855
- (_d = resolved.server.deps).inline ?? (_d.inline = []);
10877
+ (_h = resolved.server.deps).inline ?? (_h.inline = []);
10856
10878
  resolved.server.deps.inline.push(...extraInlineDeps);
10857
10879
  }
10858
10880
  }
10859
- (_e = resolved.server.deps).moduleDirectories ?? (_e.moduleDirectories = []);
10881
+ (_i = resolved.server.deps).moduleDirectories ?? (_i.moduleDirectories = []);
10860
10882
  resolved.server.deps.moduleDirectories.push(...resolved.deps.moduleDirectories);
10861
10883
  if (resolved.runner) {
10862
10884
  resolved.runner = resolveModule(resolved.runner, { paths: [resolved.root] }) ?? resolve(resolved.root, resolved.runner);
@@ -10878,10 +10900,16 @@ function resolveConfig(mode, options, viteConfig) {
10878
10900
  // resolved inside the worker
10879
10901
  snapshotEnvironment: null
10880
10902
  };
10881
- resolved.experimentalVmWorkerMemoryLimit = stringToBytes(
10882
- getWorkerMemoryLimit(resolved),
10883
- totalmem()
10884
- );
10903
+ const memory = totalmem();
10904
+ const limit = getWorkerMemoryLimit(resolved);
10905
+ if (typeof memory === "number") {
10906
+ resolved.experimentalVmWorkerMemoryLimit = stringToBytes(
10907
+ limit,
10908
+ resolved.watch ? memory / 2 : memory
10909
+ );
10910
+ } else if (limit > 1) {
10911
+ resolved.experimentalVmWorkerMemoryLimit = stringToBytes(limit);
10912
+ } else ;
10885
10913
  if (options.resolveSnapshotPath)
10886
10914
  delete resolved.resolveSnapshotPath;
10887
10915
  if (process.env.VITEST_MAX_THREADS)
@@ -10937,19 +10965,19 @@ function resolveConfig(mode, options, viteConfig) {
10937
10965
  resolved.passWithNoTests ?? (resolved.passWithNoTests = true);
10938
10966
  resolved.css ?? (resolved.css = {});
10939
10967
  if (typeof resolved.css === "object") {
10940
- (_f = resolved.css).modules ?? (_f.modules = {});
10941
- (_g = resolved.css.modules).classNameStrategy ?? (_g.classNameStrategy = "stable");
10968
+ (_j = resolved.css).modules ?? (_j.modules = {});
10969
+ (_k = resolved.css.modules).classNameStrategy ?? (_k.classNameStrategy = "stable");
10942
10970
  }
10943
10971
  resolved.cache ?? (resolved.cache = { dir: "" });
10944
10972
  if (resolved.cache)
10945
10973
  resolved.cache.dir = VitestCache.resolveCacheDir(resolved.root, resolved.cache.dir);
10946
10974
  resolved.sequence ?? (resolved.sequence = {});
10947
- if (!((_h = resolved.sequence) == null ? void 0 : _h.sequencer)) {
10975
+ if (!((_l = resolved.sequence) == null ? void 0 : _l.sequencer)) {
10948
10976
  resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
10949
10977
  }
10950
- (_i = resolved.sequence).hooks ?? (_i.hooks = "parallel");
10978
+ (_m = resolved.sequence).hooks ?? (_m.hooks = "parallel");
10951
10979
  if (resolved.sequence.sequencer === RandomSequencer)
10952
- (_j = resolved.sequence).seed ?? (_j.seed = Date.now());
10980
+ (_n = resolved.sequence).seed ?? (_n.seed = Date.now());
10953
10981
  resolved.typecheck = {
10954
10982
  ...configDefaults.typecheck,
10955
10983
  ...resolved.typecheck
@@ -10960,9 +10988,9 @@ function resolveConfig(mode, options, viteConfig) {
10960
10988
  resolved.exclude = resolved.typecheck.exclude;
10961
10989
  }
10962
10990
  resolved.browser ?? (resolved.browser = {});
10963
- (_k = resolved.browser).enabled ?? (_k.enabled = false);
10964
- (_l = resolved.browser).headless ?? (_l.headless = isCI);
10965
- (_m = resolved.browser).slowHijackESM ?? (_m.slowHijackESM = true);
10991
+ (_o = resolved.browser).enabled ?? (_o.enabled = false);
10992
+ (_p = resolved.browser).headless ?? (_p.headless = isCI);
10993
+ (_q = resolved.browser).slowHijackESM ?? (_q.slowHijackESM = true);
10966
10994
  resolved.browser.api = resolveApiServerConfig(resolved.browser) || {
10967
10995
  port: defaultBrowserPort
10968
10996
  };
@@ -11527,7 +11555,7 @@ createLogUpdate(process$1.stdout);
11527
11555
 
11528
11556
  createLogUpdate(process$1.stderr);
11529
11557
 
11530
- var version = "0.34.0";
11558
+ var version = "0.34.2";
11531
11559
 
11532
11560
  const A=r=>r!==null&&typeof r=="object",a=(r,t)=>Object.assign(new Error(`[${r}]: ${t}`),{code:r}),_$1="ERR_INVALID_PACKAGE_CONFIG",E="ERR_INVALID_PACKAGE_TARGET",I="ERR_PACKAGE_PATH_NOT_EXPORTED",R$1=/^\d+$/,O=/^(\.{1,2}|node_modules)$/i,w=/\/|\\/;var h=(r=>(r.Export="exports",r.Import="imports",r))(h||{});const f=(r,t,e,o,c)=>{if(t==null)return [];if(typeof t=="string"){const[n,...i]=t.split(w);if(n===".."||i.some(l=>O.test(l)))throw a(E,`Invalid "${r}" target "${t}" defined in the package config`);return [c?t.replace(/\*/g,c):t]}if(Array.isArray(t))return t.flatMap(n=>f(r,n,e,o,c));if(A(t)){for(const n of Object.keys(t)){if(R$1.test(n))throw a(_$1,"Cannot contain numeric property keys");if(n==="default"||o.includes(n))return f(r,t[n],e,o,c)}return []}throw a(E,`Invalid "${r}" target "${t}"`)},s="*",m=(r,t)=>{const e=r.indexOf(s),o=t.indexOf(s);return e===o?t.length>r.length:o>e};function d$1(r,t){if(!t.includes(s)&&r.hasOwnProperty(t))return [t];let e,o;for(const c of Object.keys(r))if(c.includes(s)){const[n,i,l]=c.split(s);if(l===void 0&&t.startsWith(n)&&t.endsWith(i)){const g=t.slice(n.length,-i.length||void 0);g&&(!e||m(e,c))&&(e=c,o=g);}}return [e,o]}const p=r=>Object.keys(r).reduce((t,e)=>{const o=e===""||e[0]!==".";if(t===void 0||t===o)return o;throw a(_$1,'"exports" cannot contain some keys starting with "." and some not')},void 0),u=/^\w+:/,v=(r,t,e)=>{if(!r)throw new Error('"exports" is required');t=t===""?".":`./${t}`,(typeof r=="string"||Array.isArray(r)||A(r)&&p(r))&&(r={".":r});const[o,c]=d$1(r,t),n=f(h.Export,r[o],t,e,c);if(n.length===0)throw a(I,t==="."?'No "exports" main defined':`Package subpath '${t}' is not defined by "exports"`);for(const i of n)if(!i.startsWith("./")&&!u.test(i))throw a(E,`Invalid "exports" target "${i}" defined in the package config`);return n};
11533
11561
 
@@ -12125,10 +12153,12 @@ As a temporary workaround you can try to inline the package by updating your con
12125
12153
 
12126
12154
  ` + c.gray(c.dim("// vitest.config.js")) + "\n" + c.green(`export default {
12127
12155
  test: {
12128
- deps: {
12129
- inline: [
12130
- ${c.yellow(c.bold(`"${name}"`))}
12131
- ]
12156
+ server: {
12157
+ deps: {
12158
+ inline: [
12159
+ ${c.yellow(c.bold(`"${name}"`))}
12160
+ ]
12161
+ }
12132
12162
  }
12133
12163
  }
12134
12164
  }
@@ -12180,6 +12210,7 @@ function generateCodeFrame(source, indent = 0, lineNumber, columnNumber, range =
12180
12210
  const start = positionToOffset(source, lineNumber, columnNumber);
12181
12211
  const end = start;
12182
12212
  const lines = source.split(lineSplitRE);
12213
+ const nl = /\r\n/.test(source) ? 2 : 1;
12183
12214
  let count = 0;
12184
12215
  let res = [];
12185
12216
  const columns = ((_a = process.stdout) == null ? void 0 : _a.columns) || 80;
@@ -12187,7 +12218,7 @@ function generateCodeFrame(source, indent = 0, lineNumber, columnNumber, range =
12187
12218
  return c.gray(`${String(no).padStart(3, " ")}| `);
12188
12219
  }
12189
12220
  for (let i = 0; i < lines.length; i++) {
12190
- count += lines[i].length + 1;
12221
+ count += lines[i].length + nl;
12191
12222
  if (count >= start) {
12192
12223
  for (let j = i - range; j <= i + range || end > count; j++) {
12193
12224
  if (j < 0 || j >= lines.length)
@@ -12197,7 +12228,7 @@ function generateCodeFrame(source, indent = 0, lineNumber, columnNumber, range =
12197
12228
  return "";
12198
12229
  res.push(lineNo(j + 1) + cliTruncate(lines[j].replace(/\t/g, " "), columns - 5 - indent));
12199
12230
  if (j === i) {
12200
- const pad = start - (count - lineLength);
12231
+ const pad = start - (count - lineLength) + (nl - 1);
12201
12232
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
12202
12233
  res.push(lineNo() + " ".repeat(pad) + c.red("^".repeat(length)));
12203
12234
  } else if (j > i) {
@@ -12492,7 +12523,7 @@ ${err.message}`);
12492
12523
 
12493
12524
  function MocksPlugin() {
12494
12525
  return {
12495
- name: "vite:mocks",
12526
+ name: "vitest:mocks",
12496
12527
  enforce: "post",
12497
12528
  transform(code, id) {
12498
12529
  return hoistMocks(code, id, this.parse);
@@ -12500,6 +12531,84 @@ function MocksPlugin() {
12500
12531
  };
12501
12532
  }
12502
12533
 
12534
+ function resolveOptimizerConfig(_testOptions, viteOptions, testConfig) {
12535
+ var _a;
12536
+ const testOptions = _testOptions || {};
12537
+ const newConfig = {};
12538
+ const [major, minor] = version$2.split(".").map(Number);
12539
+ const allowed = major >= 5 || major === 4 && minor >= 3;
12540
+ if (!allowed && (testOptions == null ? void 0 : testOptions.enabled) === true)
12541
+ console.warn(`Vitest: "deps.optimizer" is only available in Vite >= 4.3.0, current Vite version: ${version$2}`);
12542
+ else
12543
+ testOptions.enabled ?? (testOptions.enabled = true);
12544
+ if (!allowed || (testOptions == null ? void 0 : testOptions.enabled) !== true) {
12545
+ newConfig.cacheDir = void 0;
12546
+ newConfig.optimizeDeps = {
12547
+ // experimental in Vite >2.9.2, entries remains to help with older versions
12548
+ disabled: true,
12549
+ entries: []
12550
+ };
12551
+ } else {
12552
+ const cacheDir = testConfig.cache !== false ? (_a = testConfig.cache) == null ? void 0 : _a.dir : null;
12553
+ newConfig.cacheDir = cacheDir ?? "node_modules/.vitest";
12554
+ newConfig.optimizeDeps = {
12555
+ ...viteOptions,
12556
+ ...testOptions,
12557
+ noDiscovery: true,
12558
+ disabled: false,
12559
+ entries: [],
12560
+ exclude: ["vitest", ...builtinModules, ...testOptions.exclude || (viteOptions == null ? void 0 : viteOptions.exclude) || []],
12561
+ include: (testOptions.include || (viteOptions == null ? void 0 : viteOptions.include) || []).filter((n) => n !== "vitest")
12562
+ };
12563
+ }
12564
+ return newConfig;
12565
+ }
12566
+ function deleteDefineConfig(viteConfig) {
12567
+ const defines = {};
12568
+ if (viteConfig.define) {
12569
+ delete viteConfig.define["import.meta.vitest"];
12570
+ delete viteConfig.define["process.env"];
12571
+ delete viteConfig.define.process;
12572
+ delete viteConfig.define.global;
12573
+ }
12574
+ for (const key in viteConfig.define) {
12575
+ const val = viteConfig.define[key];
12576
+ let replacement;
12577
+ try {
12578
+ replacement = typeof val === "string" ? JSON.parse(val) : val;
12579
+ } catch {
12580
+ continue;
12581
+ }
12582
+ if (key.startsWith("import.meta.env.")) {
12583
+ const envKey = key.slice("import.meta.env.".length);
12584
+ process.env[envKey] = replacement;
12585
+ delete viteConfig.define[key];
12586
+ } else if (key.startsWith("process.env.")) {
12587
+ const envKey = key.slice("process.env.".length);
12588
+ process.env[envKey] = replacement;
12589
+ delete viteConfig.define[key];
12590
+ } else if (!key.includes(".")) {
12591
+ defines[key] = replacement;
12592
+ delete viteConfig.define[key];
12593
+ }
12594
+ }
12595
+ return defines;
12596
+ }
12597
+ function hijackVitePluginInject(viteConfig) {
12598
+ const processEnvPlugin = viteConfig.plugins.find((p) => p.name === "vite:client-inject");
12599
+ if (processEnvPlugin) {
12600
+ const originalTransform = processEnvPlugin.transform;
12601
+ processEnvPlugin.transform = function transform(code, id, options) {
12602
+ return originalTransform.call(this, code, id, { ...options, ssr: true });
12603
+ };
12604
+ }
12605
+ }
12606
+ function resolveFsAllow(projectRoot, rootConfigFile) {
12607
+ if (!rootConfigFile)
12608
+ return [searchForWorkspaceRoot(projectRoot)];
12609
+ return [dirname(rootConfigFile), searchForWorkspaceRoot(projectRoot)];
12610
+ }
12611
+
12503
12612
  async function createBrowserServer(project, options) {
12504
12613
  const root = project.config.root;
12505
12614
  await ensurePackageInstalled("@vitest/browser", root);
@@ -12528,7 +12637,13 @@ async function createBrowserServer(project, options) {
12528
12637
  };
12529
12638
  config.server = server2;
12530
12639
  (_b = config.server).fs ?? (_b.fs = {});
12531
- config.server.fs.strict = false;
12640
+ config.server.fs.allow = config.server.fs.allow || [];
12641
+ config.server.fs.allow.push(
12642
+ ...resolveFsAllow(
12643
+ project.ctx.config.root,
12644
+ project.ctx.server.config.configFile
12645
+ )
12646
+ );
12532
12647
  return {
12533
12648
  resolve: {
12534
12649
  alias: (_c = config.test) == null ? void 0 : _c.alias
@@ -12541,7 +12656,7 @@ async function createBrowserServer(project, options) {
12541
12656
  });
12542
12657
  await server.listen();
12543
12658
  await server.watcher.close();
12544
- (await import('./chunk-api-setup.644415c3.js')).setup(project, server);
12659
+ (await import('./chunk-api-setup.cc5282f7.js')).setup(project, server);
12545
12660
  return server;
12546
12661
  }
12547
12662
 
@@ -12687,12 +12802,16 @@ function generateScopedClassName(strategy, name, filename) {
12687
12802
  const cssLangs = "\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)";
12688
12803
  const cssLangRE = new RegExp(cssLangs);
12689
12804
  const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
12805
+ const cssInlineRE = /[?&]inline(&|$)/;
12690
12806
  function isCSS(id) {
12691
12807
  return cssLangRE.test(id);
12692
12808
  }
12693
12809
  function isCSSModule(id) {
12694
12810
  return cssModuleRE.test(id);
12695
12811
  }
12812
+ function isInline(id) {
12813
+ return cssInlineRE.test(id);
12814
+ }
12696
12815
  function getCSSModuleProxyReturn(strategy, filename) {
12697
12816
  if (strategy === "non-scoped")
12698
12817
  return "style";
@@ -12728,7 +12847,7 @@ function CSSEnablerPlugin(ctx) {
12728
12847
  var _a;
12729
12848
  if (!isCSS(id) || shouldProcessCSS(id))
12730
12849
  return;
12731
- if (isCSSModule(id)) {
12850
+ if (isCSSModule(id) && !isInline(id)) {
12732
12851
  const scopeStrategy = typeof ctx.config.css !== "boolean" && ((_a = ctx.config.css.modules) == null ? void 0 : _a.classNameStrategy) || "stable";
12733
12852
  const proxyReturn = getCSSModuleProxyReturn(scopeStrategy, relative(ctx.config.root, id));
12734
12853
  const code = `export default new Proxy(Object.create(null), {
@@ -12746,7 +12865,7 @@ function CSSEnablerPlugin(ctx) {
12746
12865
 
12747
12866
  function SsrReplacerPlugin() {
12748
12867
  return {
12749
- name: "vitest:env-replacer",
12868
+ name: "vitest:ssr-replacer",
12750
12869
  enforce: "pre",
12751
12870
  transform(code, id) {
12752
12871
  if (!/\bimport\.meta\.env\b/.test(code) && !/\bimport\.meta\.url\b/.test(code))
@@ -12758,14 +12877,7 @@ function SsrReplacerPlugin() {
12758
12877
  s || (s = new MagicString(code));
12759
12878
  const startIndex = env.index;
12760
12879
  const endIndex = startIndex + env[0].length;
12761
- s.overwrite(startIndex, endIndex, "process.env");
12762
- }
12763
- const urls = cleanCode.matchAll(/\bimport\.meta\.url\b/g);
12764
- for (const env of urls) {
12765
- s || (s = new MagicString(code));
12766
- const startIndex = env.index;
12767
- const endIndex = startIndex + env[0].length;
12768
- s.overwrite(startIndex, endIndex, "__vite_ssr_import_meta__.url");
12880
+ s.overwrite(startIndex, endIndex, "__vite_ssr_import_meta__.env");
12769
12881
  }
12770
12882
  if (s) {
12771
12883
  return {
@@ -12850,70 +12962,6 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
12850
12962
  };
12851
12963
  }
12852
12964
 
12853
- function resolveOptimizerConfig(_testOptions, viteOptions, testConfig) {
12854
- var _a;
12855
- const testOptions = _testOptions || {};
12856
- const newConfig = {};
12857
- const [major, minor] = version$2.split(".").map(Number);
12858
- const allowed = major >= 5 || major === 4 && minor >= 3;
12859
- if (!allowed && (testOptions == null ? void 0 : testOptions.enabled) === true)
12860
- console.warn(`Vitest: "deps.optimizer" is only available in Vite >= 4.3.0, current Vite version: ${version$2}`);
12861
- else
12862
- testOptions.enabled ?? (testOptions.enabled = true);
12863
- if (!allowed || (testOptions == null ? void 0 : testOptions.enabled) !== true) {
12864
- newConfig.cacheDir = void 0;
12865
- newConfig.optimizeDeps = {
12866
- // experimental in Vite >2.9.2, entries remains to help with older versions
12867
- disabled: true,
12868
- entries: []
12869
- };
12870
- } else {
12871
- const cacheDir = testConfig.cache !== false ? (_a = testConfig.cache) == null ? void 0 : _a.dir : null;
12872
- newConfig.cacheDir = cacheDir ?? "node_modules/.vitest";
12873
- newConfig.optimizeDeps = {
12874
- ...viteOptions,
12875
- ...testOptions,
12876
- noDiscovery: true,
12877
- disabled: false,
12878
- entries: [],
12879
- exclude: ["vitest", ...builtinModules, ...testOptions.exclude || (viteOptions == null ? void 0 : viteOptions.exclude) || []],
12880
- include: (testOptions.include || (viteOptions == null ? void 0 : viteOptions.include) || []).filter((n) => n !== "vitest")
12881
- };
12882
- }
12883
- return newConfig;
12884
- }
12885
- function deleteDefineConfig(viteConfig) {
12886
- const defines = {};
12887
- if (viteConfig.define) {
12888
- delete viteConfig.define["import.meta.vitest"];
12889
- delete viteConfig.define["process.env"];
12890
- delete viteConfig.define.process;
12891
- delete viteConfig.define.global;
12892
- }
12893
- for (const key in viteConfig.define) {
12894
- const val = viteConfig.define[key];
12895
- let replacement;
12896
- try {
12897
- replacement = typeof val === "string" ? JSON.parse(val) : val;
12898
- } catch {
12899
- continue;
12900
- }
12901
- if (key.startsWith("import.meta.env.")) {
12902
- const envKey = key.slice("import.meta.env.".length);
12903
- process.env[envKey] = replacement;
12904
- delete viteConfig.define[key];
12905
- } else if (key.startsWith("process.env.")) {
12906
- const envKey = key.slice("process.env.".length);
12907
- process.env[envKey] = replacement;
12908
- delete viteConfig.define[key];
12909
- } else if (!key.includes(".")) {
12910
- defines[key] = replacement;
12911
- delete viteConfig.define[key];
12912
- }
12913
- }
12914
- return defines;
12915
- }
12916
-
12917
12965
  function VitestResolver(ctx) {
12918
12966
  return {
12919
12967
  name: "vitest:resolve-root",
@@ -12977,7 +13025,13 @@ function WorkspaceVitestPlugin(project, options) {
12977
13025
  },
12978
13026
  open: false,
12979
13027
  hmr: false,
12980
- preTransformRequests: false
13028
+ preTransformRequests: false,
13029
+ fs: {
13030
+ allow: resolveFsAllow(
13031
+ project.ctx.config.root,
13032
+ project.ctx.server.config.configFile
13033
+ )
13034
+ }
12981
13035
  },
12982
13036
  test: {
12983
13037
  env,
@@ -13004,6 +13058,9 @@ function WorkspaceVitestPlugin(project, options) {
13004
13058
  };
13005
13059
  return config;
13006
13060
  },
13061
+ configResolved(viteConfig) {
13062
+ hijackVitePluginInject(viteConfig);
13063
+ },
13007
13064
  async configureServer(server) {
13008
13065
  try {
13009
13066
  const options2 = deepMerge(
@@ -13117,12 +13174,12 @@ class WorkspaceProject {
13117
13174
  }
13118
13175
  async globFiles(include, exclude, cwd) {
13119
13176
  const globOptions = {
13120
- absolute: true,
13121
13177
  dot: true,
13122
13178
  cwd,
13123
13179
  ignore: exclude
13124
13180
  };
13125
- return fg(include, globOptions);
13181
+ const files = await fg(include, globOptions);
13182
+ return files.map((file) => resolve(cwd, file));
13126
13183
  }
13127
13184
  async isTargetFile(id, source) {
13128
13185
  var _a;
@@ -13251,10 +13308,10 @@ class WorkspaceProject {
13251
13308
  ...this.config.deps,
13252
13309
  optimizer: {
13253
13310
  web: {
13254
- enabled: ((_c = (_b = (_a = this.config.deps) == null ? void 0 : _a.optimizer) == null ? void 0 : _b.web) == null ? void 0 : _c.enabled) ?? false
13311
+ enabled: ((_c = (_b = (_a = this.config.deps) == null ? void 0 : _a.optimizer) == null ? void 0 : _b.web) == null ? void 0 : _c.enabled) ?? true
13255
13312
  },
13256
13313
  ssr: {
13257
- enabled: ((_f = (_e = (_d = this.config.deps) == null ? void 0 : _d.optimizer) == null ? void 0 : _e.ssr) == null ? void 0 : _f.enabled) ?? false
13314
+ enabled: ((_f = (_e = (_d = this.config.deps) == null ? void 0 : _d.optimizer) == null ? void 0 : _e.ssr) == null ? void 0 : _f.enabled) ?? true
13258
13315
  }
13259
13316
  }
13260
13317
  },
@@ -13332,7 +13389,7 @@ class Vitest {
13332
13389
  isFirstRun = true;
13333
13390
  restartsCount = 0;
13334
13391
  runner = void 0;
13335
- coreWorkspace;
13392
+ coreWorkspaceProject;
13336
13393
  projects = [];
13337
13394
  projectsTestFiles = /* @__PURE__ */ new Map();
13338
13395
  _onRestartListeners = [];
@@ -13400,11 +13457,11 @@ class Vitest {
13400
13457
  runner: this.runner,
13401
13458
  server: this.vitenode
13402
13459
  });
13403
- this.coreWorkspace = coreWorkspace;
13460
+ this.coreWorkspaceProject = coreWorkspace;
13404
13461
  return coreWorkspace;
13405
13462
  }
13406
13463
  getCoreWorkspaceProject() {
13407
- return this.coreWorkspace || null;
13464
+ return this.coreWorkspaceProject || null;
13408
13465
  }
13409
13466
  getProjectByTaskId(taskId) {
13410
13467
  var _a;
@@ -13438,7 +13495,7 @@ class Vitest {
13438
13495
  onlyFiles: false,
13439
13496
  markDirectories: true,
13440
13497
  cwd: this.config.root,
13441
- ignore: ["**/node_modules/**"]
13498
+ ignore: ["**/node_modules/**", "**/*.timestamp-*"]
13442
13499
  };
13443
13500
  const workspacesFs = await fg(workspaceGlobMatches, globOptions);
13444
13501
  const resolvedWorkspacesPaths = await Promise.all(workspacesFs.filter((file) => {
@@ -13458,6 +13515,18 @@ class Vitest {
13458
13515
  }
13459
13516
  return filepath;
13460
13517
  }));
13518
+ const workspacesByFolder = resolvedWorkspacesPaths.reduce((configByFolder, filepath) => {
13519
+ const dir = dirname(filepath);
13520
+ configByFolder[dir] ?? (configByFolder[dir] = []);
13521
+ configByFolder[dir].push(filepath);
13522
+ return configByFolder;
13523
+ }, {});
13524
+ const filteredWorkspaces = Object.values(workspacesByFolder).map((configFiles2) => {
13525
+ if (configFiles2.length === 1)
13526
+ return configFiles2[0];
13527
+ const vitestConfig = configFiles2.find((configFile) => basename(configFile).startsWith("vitest.config"));
13528
+ return vitestConfig || configFiles2[0];
13529
+ });
13461
13530
  const overridesOptions = [
13462
13531
  "logHeapUsage",
13463
13532
  "allowOnly",
@@ -13474,7 +13543,7 @@ class Vitest {
13474
13543
  acc[name] = cliOptions[name];
13475
13544
  return acc;
13476
13545
  }, {});
13477
- const projects = resolvedWorkspacesPaths.map(async (workspacePath) => {
13546
+ const projects = filteredWorkspaces.map(async (workspacePath) => {
13478
13547
  if (this.server.config.configFile === workspacePath)
13479
13548
  return this.createCoreWorkspace(options);
13480
13549
  return initializeProject(workspacePath, this, { workspaceConfigPath, test: cliOverrides });
@@ -13840,7 +13909,7 @@ class Vitest {
13840
13909
  async close() {
13841
13910
  if (!this.closingPromise) {
13842
13911
  const closePromises = this.projects.map((w) => w.close().then(() => w.server = void 0));
13843
- if (this.coreWorkspace && !this.projects.includes(this.coreWorkspace))
13912
+ if (!this.coreWorkspaceProject || !this.projects.includes(this.coreWorkspaceProject))
13844
13913
  closePromises.push(this.server.close().then(() => this.server = void 0));
13845
13914
  if (this.pool)
13846
13915
  closePromises.push(this.pool.close().then(() => this.pool = void 0));
@@ -13973,7 +14042,10 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
13973
14042
  },
13974
14043
  open,
13975
14044
  hmr: false,
13976
- preTransformRequests: false
14045
+ preTransformRequests: false,
14046
+ fs: {
14047
+ allow: resolveFsAllow(getRoot(), testConfig.config)
14048
+ }
13977
14049
  }
13978
14050
  };
13979
14051
  if (process.platform === "darwin" && process.env.VITE_TEST_WATCHER_DEBUG) {
@@ -14027,6 +14099,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
14027
14099
  ignored: ["**/*"]
14028
14100
  };
14029
14101
  }
14102
+ hijackVitePluginInject(viteConfig);
14030
14103
  },
14031
14104
  async configureServer(server) {
14032
14105
  if (options.watch && process.env.VITE_TEST_WATCHER_DEBUG) {
@@ -14037,7 +14110,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
14037
14110
  try {
14038
14111
  await ctx.setServer(options, server, userConfig);
14039
14112
  if (options.api && options.watch)
14040
- (await import('./chunk-api-setup.644415c3.js')).setup(ctx);
14113
+ (await import('./chunk-api-setup.cc5282f7.js')).setup(ctx);
14041
14114
  } catch (err) {
14042
14115
  await ctx.logger.printError(err, { fullStack: true });
14043
14116
  process.exit(1);
@@ -14061,6 +14134,7 @@ async function createVitest(mode, options, viteOverrides = {}) {
14061
14134
  const ctx = new Vitest(mode);
14062
14135
  const root = resolve(options.root || process.cwd());
14063
14136
  const configPath = options.config === false ? false : options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
14137
+ options.config = configPath;
14064
14138
  const config = {
14065
14139
  logLevel: "error",
14066
14140
  configFile: configPath,
@@ -0,0 +1,14 @@
1
+ import { getNames, getTests } from '@vitest/runner/utils';
2
+ import '@vitest/utils';
3
+
4
+ function hasFailedSnapshot(suite) {
5
+ return getTests(suite).some((s) => {
6
+ var _a, _b;
7
+ return (_b = (_a = s.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.some((e) => typeof (e == null ? void 0 : e.message) === "string" && e.message.match(/Snapshot .* mismatched/));
8
+ });
9
+ }
10
+ function getFullName(task, separator = " > ") {
11
+ return getNames(task).join(separator);
12
+ }
13
+
14
+ export { getFullName as g, hasFailedSnapshot as h };