vitest 0.15.2 → 0.17.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 (26) hide show
  1. package/dist/{chunk-api-setup.8cd5e92a.mjs → chunk-api-setup.c728e251.mjs} +4 -4
  2. package/dist/{chunk-constants.7b9cfc82.mjs → chunk-constants.27550afb.mjs} +8 -2
  3. package/dist/chunk-env-node.aa51c4cc.mjs +675 -0
  4. package/dist/{chunk-install-pkg.3fa50769.mjs → chunk-install-pkg.6f5930c3.mjs} +1 -1
  5. package/dist/{chunk-integrations-globals.d0c363a6.mjs → chunk-integrations-globals.3df36e26.mjs} +8 -8
  6. package/dist/{chunk-runtime-chain.7103058b.mjs → chunk-runtime-chain.6d23d202.mjs} +55 -188
  7. package/dist/{chunk-runtime-mocker.d3ca0a4e.mjs → chunk-runtime-mocker.34b9d585.mjs} +36 -62
  8. package/dist/{chunk-runtime-rpc.5e78af38.mjs → chunk-runtime-rpc.d986adb9.mjs} +1 -1
  9. package/dist/{chunk-utils-global.79a8b1cc.mjs → chunk-utils-global.4828c2e2.mjs} +66 -2
  10. package/dist/{chunk-utils-source-map.2556cba8.mjs → chunk-utils-source-map.a9047343.mjs} +9 -23
  11. package/dist/{chunk-vite-node-externalize.0ec89ad1.mjs → chunk-vite-node-externalize.0fc8ed68.mjs} +242 -206
  12. package/dist/{chunk-vite-node-utils.1bbdb2c1.mjs → chunk-vite-node-utils.0f776286.mjs} +29 -14
  13. package/dist/cli.mjs +12 -12
  14. package/dist/config.cjs +5 -1
  15. package/dist/config.d.ts +1 -1
  16. package/dist/config.mjs +5 -1
  17. package/dist/entry.mjs +8 -8
  18. package/dist/index.d.ts +201 -24
  19. package/dist/index.mjs +4 -4
  20. package/dist/node.d.ts +187 -20
  21. package/dist/node.mjs +13 -13
  22. package/dist/{vendor-entry.efeeaa5c.mjs → vendor-entry.1ad8a08d.mjs} +18 -424
  23. package/dist/{vendor-index.e5dc6622.mjs → vendor-index.a2a385d8.mjs} +0 -0
  24. package/dist/worker.mjs +12 -11
  25. package/package.json +10 -5
  26. package/dist/chunk-defaults.dc6dc23d.mjs +0 -302
@@ -1,32 +1,32 @@
1
- import { j as join, l as basename, d as dirname, m as resolve, s as slash$2, A as AggregateErrorPonyfill, p as picocolors, o as isAbsolute, q as relative, t as isNode, u as getTests, e as getFullName, v as hasFailed, x as hasFailedSnapshot, y as getSuites, z as safeSetInterval, B as safeClearInterval, f as safeSetTimeout, C as toArray$1, D as normalize, n as noop$1, h as safeClearTimeout, E as deepMerge, F as toNamespacedPath, g as getCallLastIndex, k as notNullish, G as ensurePackageInstalled, H as stdout } from './chunk-utils-global.79a8b1cc.mjs';
2
- import { createServer, mergeConfig } from 'vite';
1
+ import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage, e as envPackageNames } from './chunk-env-node.aa51c4cc.mjs';
2
+ import { j as join, o as basename, d as dirname, q as resolve, A as AggregateErrorPonyfill, p as picocolors, s as slash$2, t as isAbsolute, u as relative, v as isNode, x as getTests, e as getFullName, y as hasFailed, z as hasFailedSnapshot, B as getSuites, C as safeSetInterval, D as safeClearInterval, f as safeSetTimeout, E as shuffle, F as toArray$1, G as normalize, n as noop$1, h as safeClearTimeout, H as deepMerge, I as toNamespacedPath, g as getCallLastIndex, l as notNullish, J as ensurePackageInstalled, K as stdout } from './chunk-utils-global.4828c2e2.mjs';
3
+ import { loadConfigFromFile, createServer, mergeConfig } from 'vite';
3
4
  import path$a from 'path';
4
5
  import url, { fileURLToPath, pathToFileURL } from 'url';
5
6
  import process$1 from 'process';
6
7
  import fs$8, { promises, existsSync, readFileSync } from 'fs';
7
- import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage } from './chunk-defaults.dc6dc23d.mjs';
8
- import { d as distDir, a as defaultPort, c as configFiles } from './chunk-constants.7b9cfc82.mjs';
8
+ import { d as distDir, c as configFiles, a as defaultPort } from './chunk-constants.27550afb.mjs';
9
9
  import readline from 'readline';
10
10
  import require$$0, { cpus, hostname, constants as constants$5 } from 'os';
11
11
  import require$$0$1 from 'util';
12
12
  import require$$0$2 from 'stream';
13
13
  import require$$2 from 'events';
14
14
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
15
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.1bbdb2c1.mjs';
15
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.0f776286.mjs';
16
16
  import createDebug from 'debug';
17
17
  import { MessageChannel } from 'worker_threads';
18
- import { createHash } from 'crypto';
19
18
  import { Tinypool } from 'tinypool';
20
19
  import { performance } from 'perf_hooks';
21
- import { c as stripAnsi, d as stringWidth, e as ansiStyles, h as sliceAnsi, i as cliTruncate, b as parseStacktrace, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, a as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.2556cba8.mjs';
22
- import { o as onetime$1, s as signalExit, m as mergeStream, g as getStream, c as crossSpawn } from './vendor-index.e5dc6622.mjs';
20
+ import { c as stripAnsi, d as stringWidth, e as ansiStyles, h as sliceAnsi, i as cliTruncate, b as parseStacktrace, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, a as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.a9047343.mjs';
21
+ import { o as onetime$1, s as signalExit, m as mergeStream, g as getStream, c as crossSpawn } from './vendor-index.a2a385d8.mjs';
23
22
  import { resolveModule } from 'local-pkg';
23
+ import { createHash } from 'crypto';
24
24
  import { Buffer } from 'buffer';
25
25
  import childProcess from 'child_process';
26
26
  import MagicString from './chunk-magic-string.efe26975.mjs';
27
27
  import { p as prompts } from './vendor-index.98e769c1.mjs';
28
28
 
29
- var version = "0.15.2";
29
+ var version = "0.17.1";
30
30
 
31
31
  class EndError extends Error {
32
32
  constructor(value) {
@@ -6820,25 +6820,6 @@ function patchWindowsImportPath(path) {
6820
6820
  return path;
6821
6821
  }
6822
6822
 
6823
- var __defProp$6 = Object.defineProperty;
6824
- var __defProps$5 = Object.defineProperties;
6825
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
6826
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
6827
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
6828
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
6829
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6830
- var __spreadValues$6 = (a, b) => {
6831
- for (var prop in b || (b = {}))
6832
- if (__hasOwnProp$6.call(b, prop))
6833
- __defNormalProp$6(a, prop, b[prop]);
6834
- if (__getOwnPropSymbols$6)
6835
- for (var prop of __getOwnPropSymbols$6(b)) {
6836
- if (__propIsEnum$6.call(b, prop))
6837
- __defNormalProp$6(a, prop, b[prop]);
6838
- }
6839
- return a;
6840
- };
6841
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
6842
6823
  const debugRequest = createDebug("vite-node:server:request");
6843
6824
  const RealDate = Date;
6844
6825
  class ViteNodeServer {
@@ -6872,7 +6853,7 @@ class ViteNodeServer {
6872
6853
  async fetchModule(id) {
6873
6854
  if (!this.fetchPromiseMap.has(id)) {
6874
6855
  this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
6875
- return this.options.sourcemap !== true ? __spreadProps$5(__spreadValues$6({}, r), { map: void 0 }) : r;
6856
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
6876
6857
  }).finally(() => {
6877
6858
  this.fetchPromiseMap.delete(id);
6878
6859
  }));
@@ -6998,26 +6979,10 @@ function addSnapshotResult(summary, result) {
6998
6979
  summary.total += result.added + result.matched + result.unmatched + result.updated;
6999
6980
  }
7000
6981
 
7001
- var __defProp$5 = Object.defineProperty;
7002
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
7003
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
7004
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
7005
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7006
- var __spreadValues$5 = (a, b) => {
7007
- for (var prop in b || (b = {}))
7008
- if (__hasOwnProp$5.call(b, prop))
7009
- __defNormalProp$5(a, prop, b[prop]);
7010
- if (__getOwnPropSymbols$5)
7011
- for (var prop of __getOwnPropSymbols$5(b)) {
7012
- if (__propIsEnum$5.call(b, prop))
7013
- __defNormalProp$5(a, prop, b[prop]);
7014
- }
7015
- return a;
7016
- };
7017
6982
  const workerPath = pathToFileURL(resolve(distDir, "./worker.mjs")).href;
7018
6983
  function createPool(ctx) {
7019
6984
  var _a;
7020
- const threadsCount = ctx.config.watch ? Math.max(cpus().length / 2, 1) : Math.max(cpus().length - 1, 1);
6985
+ const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
7021
6986
  const maxThreads = ctx.config.maxThreads ?? threadsCount;
7022
6987
  const minThreads = ctx.config.minThreads ?? threadsCount;
7023
6988
  const options = {
@@ -7037,12 +7002,14 @@ function createPool(ctx) {
7037
7002
  }
7038
7003
  if (ctx.config.coverage.enabled)
7039
7004
  (_a = process.env).NODE_V8_COVERAGE || (_a.NODE_V8_COVERAGE = ctx.config.coverage.tempDirectory);
7040
- options.env = __spreadValues$5(__spreadValues$5({
7005
+ options.env = {
7041
7006
  TEST: "true",
7042
7007
  VITEST: "true",
7043
7008
  NODE_ENV: ctx.config.mode || "test",
7044
- VITEST_MODE: ctx.config.watch ? "WATCH" : "RUN"
7045
- }, process.env), ctx.config.env);
7009
+ VITEST_MODE: ctx.config.watch ? "WATCH" : "RUN",
7010
+ ...process.env,
7011
+ ...ctx.config.env
7012
+ };
7046
7013
  const pool = new Tinypool(options);
7047
7014
  const runWithFiles = (name) => {
7048
7015
  let id = 0;
@@ -7054,8 +7021,7 @@ function createPool(ctx) {
7054
7021
  config,
7055
7022
  files,
7056
7023
  invalidates,
7057
- workerId,
7058
- poolId: !ctx.config.threads ? 1 : (workerId - 1) % maxThreads + 1
7024
+ workerId
7059
7025
  };
7060
7026
  try {
7061
7027
  await pool.run(data, { transferList: [workerPort], name });
@@ -7064,22 +7030,13 @@ function createPool(ctx) {
7064
7030
  workerPort.close();
7065
7031
  }
7066
7032
  }
7033
+ const Sequencer = ctx.config.sequence.sequencer;
7034
+ const sequencer = new Sequencer(ctx);
7067
7035
  return async (files, invalidates) => {
7068
7036
  const config = ctx.getSerializableConfig();
7069
- if (config.shard) {
7070
- const { index, count } = config.shard;
7071
- const shardSize = Math.ceil(files.length / count);
7072
- const shardStart = shardSize * (index - 1);
7073
- const shardEnd = shardSize * index;
7074
- files = files.map((file) => {
7075
- const fullPath = resolve(slash$2(config.root), slash$2(file));
7076
- const specPath = fullPath.slice(config.root.length);
7077
- return {
7078
- file,
7079
- hash: createHash("sha1").update(specPath).digest("hex")
7080
- };
7081
- }).sort((a, b) => a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0).slice(shardStart, shardEnd).map(({ file }) => file);
7082
- }
7037
+ if (config.shard)
7038
+ files = await sequencer.shard(files);
7039
+ files = await sequencer.sort(files);
7083
7040
  if (!ctx.config.threads) {
7084
7041
  await runFiles(config, files);
7085
7042
  } else {
@@ -7326,7 +7283,7 @@ class BaseReporter {
7326
7283
  const mode = this.ctx.config.watch ? picocolors.exports.blue(" DEV ") : picocolors.exports.cyan(" RUN ");
7327
7284
  this.ctx.log(`${picocolors.exports.inverse(picocolors.exports.bold(mode))} ${versionTest} ${picocolors.exports.gray(this.ctx.config.root)}`);
7328
7285
  if (this.ctx.config.ui)
7329
- this.ctx.log(picocolors.exports.dim(picocolors.exports.green(` UI started at http://${((_a2 = this.ctx.config.api) == null ? void 0 : _a2.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.server.config.server.port}`)}`)));
7286
+ this.ctx.log(picocolors.exports.dim(picocolors.exports.green(` UI started at http://${((_a2 = this.ctx.config.api) == null ? void 0 : _a2.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`)));
7330
7287
  else if (this.ctx.config.api)
7331
7288
  this.ctx.log(picocolors.exports.dim(picocolors.exports.green(` API started at http://${((_b = this.ctx.config.api) == null ? void 0 : _b.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.config.api.port}`)}`)));
7332
7289
  this.ctx.log();
@@ -8486,33 +8443,15 @@ class TapReporter {
8486
8443
  }
8487
8444
  }
8488
8445
 
8489
- var __defProp$4 = Object.defineProperty;
8490
- var __defProps$4 = Object.defineProperties;
8491
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
8492
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
8493
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
8494
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
8495
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8496
- var __spreadValues$4 = (a, b) => {
8497
- for (var prop in b || (b = {}))
8498
- if (__hasOwnProp$4.call(b, prop))
8499
- __defNormalProp$4(a, prop, b[prop]);
8500
- if (__getOwnPropSymbols$4)
8501
- for (var prop of __getOwnPropSymbols$4(b)) {
8502
- if (__propIsEnum$4.call(b, prop))
8503
- __defNormalProp$4(a, prop, b[prop]);
8504
- }
8505
- return a;
8506
- };
8507
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
8508
8446
  function flattenTasks$1(task, baseName = "") {
8509
8447
  const base = baseName ? `${baseName} > ` : "";
8510
8448
  if (task.type === "suite") {
8511
8449
  return task.tasks.flatMap((child) => flattenTasks$1(child, `${base}${task.name}`));
8512
8450
  } else {
8513
- return [__spreadProps$4(__spreadValues$4({}, task), {
8451
+ return [{
8452
+ ...task,
8514
8453
  name: `${base}${task.name}`
8515
- })];
8454
+ }];
8516
8455
  }
8517
8456
  }
8518
8457
  function removeInvalidXMLCharacters(value, removeDiscouragedChars) {
@@ -8628,10 +8567,11 @@ class JUnitReporter {
8628
8567
  failures: 0,
8629
8568
  skipped: 0
8630
8569
  });
8631
- return __spreadProps$4(__spreadValues$4({}, file), {
8570
+ return {
8571
+ ...file,
8632
8572
  tasks,
8633
8573
  stats
8634
- });
8574
+ };
8635
8575
  });
8636
8576
  await this.writeElement("testsuites", {}, async () => {
8637
8577
  for (const file of transformed) {
@@ -8654,33 +8594,15 @@ class JUnitReporter {
8654
8594
  }
8655
8595
  }
8656
8596
 
8657
- var __defProp$3 = Object.defineProperty;
8658
- var __defProps$3 = Object.defineProperties;
8659
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
8660
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
8661
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
8662
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
8663
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8664
- var __spreadValues$3 = (a, b) => {
8665
- for (var prop in b || (b = {}))
8666
- if (__hasOwnProp$3.call(b, prop))
8667
- __defNormalProp$3(a, prop, b[prop]);
8668
- if (__getOwnPropSymbols$3)
8669
- for (var prop of __getOwnPropSymbols$3(b)) {
8670
- if (__propIsEnum$3.call(b, prop))
8671
- __defNormalProp$3(a, prop, b[prop]);
8672
- }
8673
- return a;
8674
- };
8675
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
8676
8597
  function flattenTasks(task, baseName = "") {
8677
8598
  const base = baseName ? `${baseName} > ` : "";
8678
8599
  if (task.type === "suite" && task.tasks.length > 0) {
8679
8600
  return task.tasks.flatMap((child) => flattenTasks(child, `${base}${task.name}`));
8680
8601
  } else {
8681
- return [__spreadProps$3(__spreadValues$3({}, task), {
8602
+ return [{
8603
+ ...task,
8682
8604
  name: `${base}${task.name}`
8683
- })];
8605
+ }];
8684
8606
  }
8685
8607
  }
8686
8608
  class TapFlatReporter extends TapReporter {
@@ -8731,12 +8653,95 @@ function createReporters(reporterReferences, runner) {
8731
8653
  return Promise.all(promisedReporters);
8732
8654
  }
8733
8655
 
8656
+ class FilesStatsCache {
8657
+ constructor() {
8658
+ this.cache = /* @__PURE__ */ new Map();
8659
+ }
8660
+ getStats(fsPath) {
8661
+ return this.cache.get(fsPath);
8662
+ }
8663
+ async updateStats(fsPath) {
8664
+ if (!fs$8.existsSync(fsPath))
8665
+ return;
8666
+ const stats = await fs$8.promises.stat(fsPath);
8667
+ this.cache.set(fsPath, { size: stats.size });
8668
+ }
8669
+ removeStats(fsPath) {
8670
+ this.cache.delete(fsPath);
8671
+ }
8672
+ }
8673
+
8674
+ class ResultsCache {
8675
+ constructor() {
8676
+ this.cache = /* @__PURE__ */ new Map();
8677
+ this.cachePath = null;
8678
+ this.version = version;
8679
+ this.root = "/";
8680
+ }
8681
+ setConfig(root, config) {
8682
+ this.root = root;
8683
+ if (config)
8684
+ this.cachePath = resolve(config.dir, "results.json");
8685
+ }
8686
+ getResults(fsPath) {
8687
+ return this.cache.get(fsPath == null ? void 0 : fsPath.slice(this.root.length));
8688
+ }
8689
+ async readFromCache() {
8690
+ if (!this.cachePath)
8691
+ return;
8692
+ if (fs$8.existsSync(this.cachePath)) {
8693
+ const resultsCache = await fs$8.promises.readFile(this.cachePath, "utf8");
8694
+ const { results, version: version2 } = JSON.parse(resultsCache);
8695
+ this.cache = new Map(results);
8696
+ this.version = version2;
8697
+ }
8698
+ }
8699
+ updateResults(files) {
8700
+ files.forEach((file) => {
8701
+ var _a;
8702
+ const result = file.result;
8703
+ if (!result)
8704
+ return;
8705
+ const duration = result.duration || 0;
8706
+ const relativePath = (_a = file.filepath) == null ? void 0 : _a.slice(this.root.length);
8707
+ this.cache.set(relativePath, {
8708
+ duration: duration >= 0 ? duration : 0,
8709
+ failed: result.state === "fail"
8710
+ });
8711
+ });
8712
+ }
8713
+ removeFromCache(filepath) {
8714
+ this.cache.delete(filepath);
8715
+ }
8716
+ async writeToCache() {
8717
+ if (!this.cachePath)
8718
+ return;
8719
+ const results = Array.from(this.cache.entries());
8720
+ const cacheDirname = dirname(this.cachePath);
8721
+ if (!fs$8.existsSync(cacheDirname))
8722
+ await fs$8.promises.mkdir(cacheDirname, { recursive: true });
8723
+ const cache = JSON.stringify({
8724
+ version: this.version,
8725
+ results
8726
+ });
8727
+ await fs$8.promises.writeFile(this.cachePath, cache);
8728
+ }
8729
+ }
8730
+
8734
8731
  class StateManager {
8735
8732
  constructor() {
8736
8733
  this.filesMap = /* @__PURE__ */ new Map();
8737
8734
  this.idMap = /* @__PURE__ */ new Map();
8738
8735
  this.taskFileMap = /* @__PURE__ */ new WeakMap();
8739
8736
  this.errorsSet = /* @__PURE__ */ new Set();
8737
+ this.results = new ResultsCache();
8738
+ this.stats = new FilesStatsCache();
8739
+ }
8740
+ getFileTestResults(id) {
8741
+ return this.results.getResults(id);
8742
+ }
8743
+ getFileStats(id) {
8744
+ return this.stats.getStats(id);
8740
8745
  }
8741
8746
  catchError(err, type) {
8742
8747
  err.type = type;
@@ -8750,7 +8755,7 @@ class StateManager {
8750
8755
  }
8751
8756
  getFiles(keys) {
8752
8757
  if (keys)
8753
- return keys.map((key) => this.filesMap.get(key));
8758
+ return keys.map((key) => this.filesMap.get(key)).filter(Boolean);
8754
8759
  return Array.from(this.filesMap.values());
8755
8760
  }
8756
8761
  getFilepaths() {
@@ -8794,28 +8799,80 @@ class StateManager {
8794
8799
  }
8795
8800
  }
8796
8801
 
8797
- var __defProp$2 = Object.defineProperty;
8798
- var __defProps$2 = Object.defineProperties;
8799
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
8800
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
8801
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
8802
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
8803
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8804
- var __spreadValues$2 = (a, b) => {
8805
- for (var prop in b || (b = {}))
8806
- if (__hasOwnProp$2.call(b, prop))
8807
- __defNormalProp$2(a, prop, b[prop]);
8808
- if (__getOwnPropSymbols$2)
8809
- for (var prop of __getOwnPropSymbols$2(b)) {
8810
- if (__propIsEnum$2.call(b, prop))
8811
- __defNormalProp$2(a, prop, b[prop]);
8802
+ class VitestCache {
8803
+ static resolveCacheDir(root, dir) {
8804
+ return resolve(root, slash$2(dir || "node_modules/.vitest"));
8805
+ }
8806
+ static async clearCache(options) {
8807
+ var _a;
8808
+ const root = resolve(options.root || process.cwd());
8809
+ const configPath = options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
8810
+ const config = await loadConfigFromFile({ command: "serve", mode: "test" }, configPath);
8811
+ const cache = (_a = config == null ? void 0 : config.config.test) == null ? void 0 : _a.cache;
8812
+ if (cache === false)
8813
+ throw new Error("Cache is disabled");
8814
+ const cachePath = VitestCache.resolveCacheDir(root, cache == null ? void 0 : cache.dir);
8815
+ let cleared = false;
8816
+ if (fs$8.existsSync(cachePath)) {
8817
+ fs$8.rmSync(cachePath, { recursive: true, force: true });
8818
+ cleared = true;
8812
8819
  }
8813
- return a;
8814
- };
8815
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
8820
+ return { dir: cachePath, cleared };
8821
+ }
8822
+ }
8823
+
8824
+ class BaseSequencer {
8825
+ constructor(ctx) {
8826
+ this.ctx = ctx;
8827
+ }
8828
+ async shard(files) {
8829
+ const { config } = this.ctx;
8830
+ const { index, count } = config.shard;
8831
+ const shardSize = Math.ceil(files.length / count);
8832
+ const shardStart = shardSize * (index - 1);
8833
+ const shardEnd = shardSize * index;
8834
+ return [...files].map((file) => {
8835
+ const fullPath = resolve(slash$1(config.root), slash$1(file));
8836
+ const specPath = fullPath == null ? void 0 : fullPath.slice(config.root.length);
8837
+ return {
8838
+ file,
8839
+ hash: createHash("sha1").update(specPath).digest("hex")
8840
+ };
8841
+ }).sort((a, b) => a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0).slice(shardStart, shardEnd).map(({ file }) => file);
8842
+ }
8843
+ async sort(files) {
8844
+ const { state } = this.ctx;
8845
+ return [...files].sort((a, b) => {
8846
+ const aState = state.getFileTestResults(a);
8847
+ const bState = state.getFileTestResults(b);
8848
+ if (!aState || !bState) {
8849
+ const statsA = state.getFileStats(a);
8850
+ const statsB = state.getFileStats(b);
8851
+ if (!statsA || !statsB)
8852
+ return !statsA && statsB ? -1 : !statsB && statsA ? 1 : 0;
8853
+ return statsB.size - statsA.size;
8854
+ }
8855
+ if (aState.failed && !bState.failed)
8856
+ return -1;
8857
+ if (!aState.failed && bState.failed)
8858
+ return 1;
8859
+ return bState.duration - aState.duration;
8860
+ });
8861
+ }
8862
+ }
8863
+
8864
+ class RandomSequencer extends BaseSequencer {
8865
+ async sort(files) {
8866
+ const { sequence } = this.ctx.config;
8867
+ const seed = (sequence == null ? void 0 : sequence.seed) ?? Date.now();
8868
+ return shuffle(files, seed);
8869
+ }
8870
+ }
8871
+
8816
8872
  const extraInlineDeps = [
8817
8873
  /^(?!.*(?:node_modules)).*\.mjs$/,
8818
8874
  /^(?!.*(?:node_modules)).*\.cjs\.js$/,
8875
+ /vite\w*\/dist\/client\/env.mjs/,
8819
8876
  /\/vitest\/dist\//,
8820
8877
  /vitest-virtual-\w+\/dist/,
8821
8878
  /@vitest\/dist/,
@@ -8838,7 +8895,7 @@ function resolveApiConfig(options) {
8838
8895
  if (options.api.host)
8839
8896
  api.host = options.api.host;
8840
8897
  } else {
8841
- api = __spreadValues$2({}, options.api);
8898
+ api = { ...options.api };
8842
8899
  }
8843
8900
  }
8844
8901
  if (api) {
@@ -8848,16 +8905,18 @@ function resolveApiConfig(options) {
8848
8905
  return api;
8849
8906
  }
8850
8907
  function resolveConfig(options, viteConfig) {
8851
- var _a, _b, _c;
8908
+ var _a, _b, _c, _d;
8852
8909
  if (options.dom) {
8853
8910
  if (((_a = viteConfig.test) == null ? void 0 : _a.environment) != null && viteConfig.test.environment !== "happy-dom") {
8854
8911
  console.warn(picocolors.exports.yellow(`${picocolors.exports.inverse(picocolors.exports.yellow(" Vitest "))} Your config.test.environment ("${viteConfig.test.environment}") conflicts with --dom flag ("happy-dom"), ignoring "${viteConfig.test.environment}"`));
8855
8912
  }
8856
8913
  options.environment = "happy-dom";
8857
8914
  }
8858
- const resolved = __spreadProps$2(__spreadValues$2(__spreadValues$2({}, configDefaults), options), {
8915
+ const resolved = {
8916
+ ...configDefaults,
8917
+ ...options,
8859
8918
  root: viteConfig.root
8860
- });
8919
+ };
8861
8920
  if (viteConfig.base !== "/")
8862
8921
  resolved.base = viteConfig.base;
8863
8922
  resolved.coverage = resolveC8Options(options.coverage || {}, resolved.root);
@@ -8875,8 +8934,8 @@ function resolveConfig(options, viteConfig) {
8875
8934
  }
8876
8935
  resolved.deps = resolved.deps || {};
8877
8936
  if (resolved.deps.inline !== true) {
8878
- const ssrOptions = viteConfig.ssr || {};
8879
- if (ssrOptions.noExternal === true && resolved.deps.inline == null) {
8937
+ const ssrOptions = viteConfig.ssr;
8938
+ if ((ssrOptions == null ? void 0 : ssrOptions.noExternal) === true && resolved.deps.inline == null) {
8880
8939
  resolved.deps.inline = true;
8881
8940
  } else {
8882
8941
  (_b = resolved.deps).inline ?? (_b.inline = []);
@@ -8912,6 +8971,13 @@ function resolveConfig(options, viteConfig) {
8912
8971
  resolved.css ?? (resolved.css = {});
8913
8972
  if (typeof resolved.css === "object")
8914
8973
  (_c = resolved.css).include ?? (_c.include = [/\.module\./]);
8974
+ resolved.cache ?? (resolved.cache = { dir: "" });
8975
+ if (resolved.cache)
8976
+ resolved.cache.dir = VitestCache.resolveCacheDir(resolved.root, resolved.cache.dir);
8977
+ if (!((_d = resolved.sequence) == null ? void 0 : _d.sequencer)) {
8978
+ resolved.sequence ?? (resolved.sequence = {});
8979
+ resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
8980
+ }
8915
8981
  return resolved;
8916
8982
  }
8917
8983
 
@@ -10204,25 +10270,6 @@ class VitestGit {
10204
10270
  }
10205
10271
  }
10206
10272
 
10207
- var __defProp$1 = Object.defineProperty;
10208
- var __defProps$1 = Object.defineProperties;
10209
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
10210
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
10211
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
10212
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
10213
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10214
- var __spreadValues$1 = (a, b) => {
10215
- for (var prop in b || (b = {}))
10216
- if (__hasOwnProp$1.call(b, prop))
10217
- __defNormalProp$1(a, prop, b[prop]);
10218
- if (__getOwnPropSymbols$1)
10219
- for (var prop of __getOwnPropSymbols$1(b)) {
10220
- if (__propIsEnum$1.call(b, prop))
10221
- __defNormalProp$1(a, prop, b[prop]);
10222
- }
10223
- return a;
10224
- };
10225
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
10226
10273
  const WATCHER_DEBOUNCE = 100;
10227
10274
  const CLOSE_TIMEOUT = 1e3;
10228
10275
  class Vitest {
@@ -10255,7 +10302,7 @@ class Vitest {
10255
10302
  this.server = server;
10256
10303
  this.config = resolved;
10257
10304
  this.state = new StateManager();
10258
- this.snapshot = new SnapshotManager(__spreadValues$1({}, resolved.snapshotOptions));
10305
+ this.snapshot = new SnapshotManager({ ...resolved.snapshotOptions });
10259
10306
  if (this.config.watch)
10260
10307
  this.registerWatcher();
10261
10308
  this.vitenode = new ViteNodeServer(server, this.config);
@@ -10275,15 +10322,23 @@ class Vitest {
10275
10322
  this._onRestartListeners.forEach((fn) => fn());
10276
10323
  if (resolved.coverage.enabled)
10277
10324
  await cleanCoverage(resolved.coverage, resolved.coverage.clean);
10325
+ this.state.results.setConfig(resolved.root, resolved.cache);
10326
+ await this.state.results.readFromCache();
10278
10327
  }
10279
10328
  getSerializableConfig() {
10280
- return deepMerge(__spreadProps$1(__spreadValues$1({}, this.config), {
10329
+ return deepMerge({
10330
+ ...this.config,
10281
10331
  reporters: [],
10282
- snapshotOptions: __spreadProps$1(__spreadValues$1({}, this.config.snapshotOptions), {
10332
+ snapshotOptions: {
10333
+ ...this.config.snapshotOptions,
10283
10334
  resolveSnapshotPath: void 0
10284
- }),
10285
- onConsoleLog: void 0
10286
- }), this.configOverride || {});
10335
+ },
10336
+ onConsoleLog: void 0,
10337
+ sequence: {
10338
+ ...this.config.sequence,
10339
+ sequencer: void 0
10340
+ }
10341
+ }, this.configOverride || {});
10287
10342
  }
10288
10343
  async start(filters) {
10289
10344
  await this.report("onInit", this);
@@ -10303,6 +10358,7 @@ class Vitest {
10303
10358
  this.error(picocolors.exports.red("\nNo test files found, exiting with code 1"));
10304
10359
  process.exit(exitCode);
10305
10360
  }
10361
+ await Promise.all(files.map((file) => this.state.stats.updateStats(file)));
10306
10362
  await this.runFiles(files);
10307
10363
  if (this.config.coverage.enabled)
10308
10364
  await reportCoverage(this);
@@ -10343,6 +10399,9 @@ class Vitest {
10343
10399
  const related = this.config.related;
10344
10400
  if (!related)
10345
10401
  return tests;
10402
+ const forceRerunTriggers = this.config.forceRerunTriggers;
10403
+ if (forceRerunTriggers.length && micromatch_1(related, forceRerunTriggers).length)
10404
+ return tests;
10346
10405
  if (!related.length)
10347
10406
  return [];
10348
10407
  const testDeps = await Promise.all(tests.map(async (filepath) => {
@@ -10356,7 +10415,7 @@ class Vitest {
10356
10415
  }
10357
10416
  return runningTests;
10358
10417
  }
10359
- async runFiles(files) {
10418
+ async runFiles(paths) {
10360
10419
  await this.runningPromise;
10361
10420
  this.runningPromise = (async () => {
10362
10421
  if (!this.pool)
@@ -10366,13 +10425,16 @@ class Vitest {
10366
10425
  this.snapshot.clear();
10367
10426
  this.state.clearErrors();
10368
10427
  try {
10369
- await this.pool.runTests(files, invalidates);
10428
+ await this.pool.runTests(paths, invalidates);
10370
10429
  } catch (err) {
10371
10430
  this.state.catchError(err, "Unhandled Error");
10372
10431
  }
10373
- if (hasFailed(this.state.getFiles()))
10432
+ const files = this.state.getFiles();
10433
+ if (hasFailed(files))
10374
10434
  process.exitCode = 1;
10375
- await this.report("onFinished", this.state.getFiles(), this.state.getUnhandledErrors());
10435
+ await this.report("onFinished", files, this.state.getUnhandledErrors());
10436
+ this.state.results.updateResults(files);
10437
+ await this.state.results.writeToCache();
10376
10438
  })().finally(() => {
10377
10439
  this.runningPromise = void 0;
10378
10440
  });
@@ -10461,6 +10523,8 @@ class Vitest {
10461
10523
  this.invalidates.add(id);
10462
10524
  if (this.state.filesMap.has(id)) {
10463
10525
  this.state.filesMap.delete(id);
10526
+ this.state.results.removeFromCache(id);
10527
+ this.state.stats.removeStats(id);
10464
10528
  this.changedTests.delete(id);
10465
10529
  this.report("onTestRemoved", id);
10466
10530
  }
@@ -10469,6 +10533,7 @@ class Vitest {
10469
10533
  id = slash$2(id);
10470
10534
  if (await this.isTargetFile(id)) {
10471
10535
  this.changedTests.add(id);
10536
+ await this.state.stats.updateStats(id);
10472
10537
  this.scheduleRerun(id);
10473
10538
  }
10474
10539
  };
@@ -10824,37 +10889,6 @@ function CSSEnablerPlugin(ctx) {
10824
10889
  };
10825
10890
  }
10826
10891
 
10827
- var __defProp = Object.defineProperty;
10828
- var __defProps = Object.defineProperties;
10829
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10830
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10831
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10832
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10833
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10834
- var __spreadValues = (a, b) => {
10835
- for (var prop in b || (b = {}))
10836
- if (__hasOwnProp.call(b, prop))
10837
- __defNormalProp(a, prop, b[prop]);
10838
- if (__getOwnPropSymbols)
10839
- for (var prop of __getOwnPropSymbols(b)) {
10840
- if (__propIsEnum.call(b, prop))
10841
- __defNormalProp(a, prop, b[prop]);
10842
- }
10843
- return a;
10844
- };
10845
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
10846
- var __objRest = (source, exclude) => {
10847
- var target = {};
10848
- for (var prop in source)
10849
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
10850
- target[prop] = source[prop];
10851
- if (source != null && __getOwnPropSymbols)
10852
- for (var prop of __getOwnPropSymbols(source)) {
10853
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
10854
- target[prop] = source[prop];
10855
- }
10856
- return target;
10857
- };
10858
10892
  async function VitestPlugin(options = {}, ctx = new Vitest()) {
10859
10893
  let haveStarted = false;
10860
10894
  async function UIPlugin() {
@@ -10900,14 +10934,15 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10900
10934
  resolve: {
10901
10935
  mainFields: []
10902
10936
  },
10903
- server: __spreadProps(__spreadValues({}, preOptions.api), {
10937
+ server: {
10938
+ ...preOptions.api,
10904
10939
  watch: {
10905
10940
  ignored: preOptions.watchExclude
10906
10941
  },
10907
10942
  open,
10908
10943
  hmr: false,
10909
10944
  preTransformRequests: false
10910
- }),
10945
+ },
10911
10946
  cacheDir: void 0,
10912
10947
  optimizeDeps: {
10913
10948
  disabled: true,
@@ -10917,18 +10952,18 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10917
10952
  return config;
10918
10953
  },
10919
10954
  async configResolved(viteConfig) {
10920
- var _b, _c, _d, _e;
10955
+ var _a, _b, _c, _d;
10921
10956
  const viteConfigTest = viteConfig.test || {};
10922
10957
  if (viteConfigTest.watch === false)
10923
10958
  viteConfigTest.run = true;
10924
10959
  options = deepMerge({}, configDefaults, viteConfigTest, options);
10925
10960
  options.api = resolveApiConfig(options);
10926
- const _a = viteConfig.env, { PROD, DEV } = _a, envs = __objRest(_a, ["PROD", "DEV"]);
10927
- (_b = process.env).PROD ?? (_b.PROD = PROD ? "1" : "");
10928
- (_c = process.env).DEV ?? (_c.DEV = DEV ? "1" : "");
10929
- (_d = process.env).SSR ?? (_d.SSR = "1");
10961
+ const { PROD, DEV, ...envs } = viteConfig.env;
10962
+ (_a = process.env).PROD ?? (_a.PROD = PROD ? "1" : "");
10963
+ (_b = process.env).DEV ?? (_b.DEV = DEV ? "1" : "");
10964
+ (_c = process.env).SSR ?? (_c.SSR = "1");
10930
10965
  for (const name in envs)
10931
- (_e = process.env)[name] ?? (_e[name] = envs[name]);
10966
+ (_d = process.env)[name] ?? (_d[name] = envs[name]);
10932
10967
  },
10933
10968
  async configureServer(server) {
10934
10969
  if (haveStarted)
@@ -10937,7 +10972,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10937
10972
  await ctx.setServer(options, server);
10938
10973
  haveStarted = true;
10939
10974
  if (options.api && options.watch)
10940
- (await import('./chunk-api-setup.8cd5e92a.mjs')).setup(ctx);
10975
+ (await import('./chunk-api-setup.c728e251.mjs')).setup(ctx);
10941
10976
  } catch (err) {
10942
10977
  ctx.printError(err, true);
10943
10978
  process.exit(1);
@@ -11060,7 +11095,8 @@ async function startVitest(cliFilters, options, viteOverrides) {
11060
11095
  }
11061
11096
  }
11062
11097
  if (ctx.config.environment && ctx.config.environment !== "node") {
11063
- if (!await ensurePackageInstalled(ctx.config.environment)) {
11098
+ const packageName = envPackageNames[ctx.config.environment];
11099
+ if (!await ensurePackageInstalled(packageName)) {
11064
11100
  process.exitCode = 1;
11065
11101
  return false;
11066
11102
  }
@@ -11085,4 +11121,4 @@ async function startVitest(cliFilters, options, viteOverrides) {
11085
11121
  return true;
11086
11122
  }
11087
11123
 
11088
- export { VitestPlugin as V, createVitest as c, divider as d, startVitest as s, version as v };
11124
+ export { BaseSequencer as B, VitestPlugin as V, createVitest as c, divider as d, startVitest as s, version as v };