vitest 0.10.5 → 0.11.0

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.
@@ -1,5 +1,5 @@
1
1
  import { promises } from 'fs';
2
- import { c as createBirpc } from './chunk-vite-node-utils.6b0ec89a.js';
2
+ import { c as createBirpc } from './chunk-vite-node-utils.20782527.js';
3
3
  import require$$0$1 from 'stream';
4
4
  import require$$0 from 'zlib';
5
5
  import require$$3 from 'net';
@@ -9,11 +9,11 @@ import require$$2 from 'events';
9
9
  import require$$1 from 'https';
10
10
  import require$$2$1 from 'http';
11
11
  import url from 'url';
12
- import { A as API_PATH } from './chunk-constants.54c46a47.js';
13
- import { r as interpretSourcePos, b as parseStacktrace } from './chunk-utils-timers.27e0c6e9.js';
12
+ import { A as API_PATH } from './chunk-constants.0567483c.js';
13
+ import { r as interpretSourcePos, b as parseStacktrace } from './chunk-utils-timers.f25e8f44.js';
14
14
  import 'module';
15
15
  import 'vm';
16
- import './chunk-utils-global.eb31f3da.js';
16
+ import './chunk-utils-global.a5a8641f.js';
17
17
  import 'tty';
18
18
  import 'local-pkg';
19
19
  import 'path';
@@ -1,5 +1,5 @@
1
1
  import { fileURLToPath } from 'url';
2
- import { k as resolve } from './chunk-utils-global.eb31f3da.js';
2
+ import { h as resolve } from './chunk-utils-global.a5a8641f.js';
3
3
 
4
4
  const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
5
5
  const defaultPort = 51204;
@@ -1,7 +1,7 @@
1
1
  import { existsSync, promises } from 'fs';
2
2
  import { createRequire } from 'module';
3
3
  import { pathToFileURL } from 'url';
4
- import { t as toArray, k as resolve } from './chunk-utils-global.eb31f3da.js';
4
+ import { t as toArray, h as resolve } from './chunk-utils-global.a5a8641f.js';
5
5
 
6
6
  const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
7
7
  const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
@@ -119,7 +119,7 @@ async function reportCoverage(ctx) {
119
119
  })
120
120
  };
121
121
  }));
122
- const offset = 203;
122
+ const offset = 224;
123
123
  report._getSourceMap = (coverage) => {
124
124
  const path = pathToFileURL(coverage.url).href;
125
125
  const data = sourceMapMeta[path];
@@ -1,22 +1,22 @@
1
- import { g as globalApis } from './chunk-constants.54c46a47.js';
2
- import { i as index } from './vendor-entry.9551d577.js';
1
+ import { g as globalApis } from './chunk-constants.0567483c.js';
2
+ import { i as index } from './vendor-entry.1b0b46f1.js';
3
3
  import 'url';
4
- import './chunk-utils-global.eb31f3da.js';
4
+ import './chunk-utils-global.a5a8641f.js';
5
5
  import 'tty';
6
6
  import 'local-pkg';
7
7
  import 'path';
8
8
  import 'fs';
9
9
  import 'console';
10
10
  import 'stream';
11
- import './chunk-runtime-chain.d0bd6df6.js';
11
+ import './chunk-runtime-chain.8a313ffb.js';
12
12
  import 'chai';
13
13
  import './vendor-_commonjsHelpers.addc3445.js';
14
- import './chunk-runtime-rpc.710f6f7f.js';
15
- import './chunk-utils-timers.27e0c6e9.js';
16
- import './chunk-integrations-spy.f036df6f.js';
14
+ import './chunk-runtime-rpc.63398738.js';
15
+ import './chunk-utils-timers.f25e8f44.js';
16
+ import './chunk-integrations-spy.bee66426.js';
17
17
  import 'tinyspy';
18
18
  import 'util';
19
- import './chunk-defaults.c143550b.js';
19
+ import './chunk-defaults.23b3ae8a.js';
20
20
  import 'module';
21
21
  import 'crypto';
22
22
 
@@ -36,7 +36,7 @@ function enhanceSpy(spy) {
36
36
  });
37
37
  },
38
38
  get lastCall() {
39
- return stub.calls.at(-1);
39
+ return stub.calls[stub.calls.length - 1];
40
40
  }
41
41
  };
42
42
  let onceImplementations = [];
@@ -1,10 +1,10 @@
1
1
  import chai$1, { expect as expect$1, util } from 'chai';
2
2
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
3
- import { r as rpc } from './chunk-runtime-rpc.710f6f7f.js';
4
- import { i as isObject, a as index, g as getCallLastIndex, s as slash, b as getWorkerState, c as getNames, d as assertTypes, p as picocolors, n as noop, t as toArray, r as resetModules } from './chunk-utils-global.eb31f3da.js';
3
+ import { r as rpc } from './chunk-runtime-rpc.63398738.js';
4
+ import { i as isObject, j as join, d as dirname, g as getCallLastIndex, s as slash, a as getWorkerState, b as getNames, c as assertTypes, p as picocolors, n as noop, t as toArray, r as resetModules } from './chunk-utils-global.a5a8641f.js';
5
5
  import fs, { promises } from 'fs';
6
- import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils, c as setTimeout, d as clearTimeout } from './chunk-utils-timers.27e0c6e9.js';
7
- import { i as isMockFunction, s as spyOn, f as fn, a as spies } from './chunk-integrations-spy.f036df6f.js';
6
+ import { p as plugins_1, f as format_1, g as getOriginalPos, a as posToNumber, n as numberToPos, l as lineSplitRE, b as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils, c as setTimeout, d as clearTimeout } from './chunk-utils-timers.f25e8f44.js';
7
+ import { i as isMockFunction, s as spyOn, f as fn, a as spies } from './chunk-integrations-spy.bee66426.js';
8
8
  import require$$0, { format } from 'util';
9
9
 
10
10
  var __defProp$4 = Object.defineProperty;
@@ -517,7 +517,7 @@ function printBacktickString(str) {
517
517
  }
518
518
  function ensureDirectoryExists(filePath) {
519
519
  try {
520
- fs.mkdirSync(index.join(index.dirname(filePath)), { recursive: true });
520
+ fs.mkdirSync(join(dirname(filePath)), { recursive: true });
521
521
  } catch {
522
522
  }
523
523
  }
@@ -4778,9 +4778,11 @@ class VitestUtils {
4778
4778
  return this;
4779
4779
  }
4780
4780
  stubGlobal(name, value) {
4781
- globalThis[name] = value;
4782
- if (globalThis.window)
4781
+ if (globalThis.window) {
4783
4782
  globalThis.window[name] = value;
4783
+ } else {
4784
+ globalThis[name] = value;
4785
+ }
4784
4786
  return this;
4785
4787
  }
4786
4788
  resetModules() {
@@ -1,8 +1,8 @@
1
- import { n as normalizeRequestId, i as isNodeBuiltin, t as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.6b0ec89a.js';
1
+ import { n as normalizeRequestId, i as isNodeBuiltin, t as toFilePath, V as ViteNodeRunner } from './chunk-vite-node-utils.20782527.js';
2
2
  import { normalizePath } from 'vite';
3
- import { b as getWorkerState, D as isWindows, E as mergeSlashes, h as dirname, f as basename, k as resolve, F as getType, G as getAllProperties, s as slash } from './chunk-utils-global.eb31f3da.js';
3
+ import { a as getWorkerState, C as isWindows, D as mergeSlashes, d as dirname, f as basename, h as resolve, E as getType, F as getAllProperties, s as slash } from './chunk-utils-global.a5a8641f.js';
4
4
  import { existsSync, readdirSync } from 'fs';
5
- import { d as distDir } from './chunk-constants.54c46a47.js';
5
+ import { d as distDir } from './chunk-constants.0567483c.js';
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -177,6 +177,7 @@ const _VitestMocker = class {
177
177
  await this.ensureSpy();
178
178
  await this.resolveMocks();
179
179
  const mock = this.getDependencyMock(dep);
180
+ const callstack = this.request.callstack;
180
181
  if (mock === null) {
181
182
  const cacheName = `${dep}__mock`;
182
183
  const cache = this.moduleCache.get(cacheName);
@@ -188,9 +189,11 @@ const _VitestMocker = class {
188
189
  this.emit("mocked", cacheName, { exports });
189
190
  return exports;
190
191
  }
191
- if (typeof mock === "function")
192
+ if (typeof mock === "function" && !callstack.includes(`mock:${dep}`)) {
193
+ callstack.push(`mock:${dep}`);
192
194
  return this.callFunctionMock(dep, mock);
193
- if (typeof mock === "string")
195
+ }
196
+ if (typeof mock === "string" && !callstack.includes(mock))
194
197
  dep = mock;
195
198
  return this.request(dep);
196
199
  }
@@ -224,6 +227,7 @@ class VitestRunner extends ViteNodeRunner {
224
227
  }
225
228
  prepareContext(context) {
226
229
  const request = context.__vite_ssr_import__;
230
+ const resolveId = context.__vitest_resolve_id__;
227
231
  const mocker = this.mocker.withRequest(request);
228
232
  mocker.on("mocked", (dep, module) => {
229
233
  this.moduleCache.set(dep, module);
@@ -233,8 +237,8 @@ class VitestRunner extends ViteNodeRunner {
233
237
  Object.defineProperty(context.__vite_ssr_import_meta__, "vitest", { get: () => globalThis.__vitest_index__ });
234
238
  }
235
239
  return Object.assign(context, {
236
- __vite_ssr_import__: (dep) => mocker.requestWithMock(dep),
237
- __vite_ssr_dynamic_import__: (dep) => mocker.requestWithMock(dep),
240
+ __vite_ssr_import__: async (dep) => mocker.requestWithMock(await resolveId(dep)),
241
+ __vite_ssr_dynamic_import__: async (dep) => mocker.requestWithMock(await resolveId(dep)),
238
242
  __vitest_mocker__: mocker
239
243
  });
240
244
  }
@@ -1,4 +1,4 @@
1
- import { b as getWorkerState } from './chunk-utils-global.eb31f3da.js';
1
+ import { a as getWorkerState } from './chunk-utils-global.a5a8641f.js';
2
2
 
3
3
  const rpc = () => {
4
4
  return getWorkerState().rpc;
@@ -242,9 +242,9 @@ const _path = /*#__PURE__*/Object.freeze({
242
242
  parse: parse
243
243
  });
244
244
 
245
- const index = {
245
+ ({
246
246
  ..._path
247
- };
247
+ });
248
248
 
249
249
  function getWorkerState() {
250
250
  return globalThis.__vitest_worker__;
@@ -457,4 +457,4 @@ function getCallLastIndex(code) {
457
457
  return null;
458
458
  }
459
459
 
460
- export { ensurePackageInstalled as A, stdout as B, extname as C, isWindows as D, mergeSlashes as E, getType as F, getAllProperties as G, clone as H, partitionSuiteChildren as I, hasTests as J, index as a, getWorkerState as b, getNames as c, assertTypes as d, notNullish as e, basename as f, getCallLastIndex as g, dirname as h, isObject as i, join as j, resolve as k, isAbsolute as l, relative as m, noop as n, getTests as o, picocolors as p, getFullName as q, resetModules as r, slash as s, toArray as t, hasFailed as u, hasFailedSnapshot as v, getSuites as w, normalize as x, deepMerge as y, toNamespacedPath as z };
460
+ export { stdout as A, extname as B, isWindows as C, mergeSlashes as D, getType as E, getAllProperties as F, clone as G, partitionSuiteChildren as H, hasTests as I, getWorkerState as a, getNames as b, assertTypes as c, dirname as d, notNullish as e, basename as f, getCallLastIndex as g, resolve as h, isObject as i, join as j, isAbsolute as k, relative as l, getTests as m, noop as n, getFullName as o, picocolors as p, hasFailed as q, resetModules as r, slash as s, toArray as t, hasFailedSnapshot as u, getSuites as v, normalize as w, deepMerge as x, toNamespacedPath as y, ensurePackageInstalled as z };
@@ -1,4 +1,4 @@
1
- import { s as slash, e as notNullish, p as picocolors } from './chunk-utils-global.eb31f3da.js';
1
+ import { s as slash, e as notNullish, p as picocolors } from './chunk-utils-global.a5a8641f.js';
2
2
 
3
3
  const setTimeout$1 = globalThis.setTimeout;
4
4
  const setInterval = globalThis.setInterval;
@@ -5,25 +5,25 @@ import process$1 from 'process';
5
5
  import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn, o as onetime$1 } from './vendor-index.40be925a.js';
6
6
  import url, { fileURLToPath, pathToFileURL } from 'url';
7
7
  import require$$0, { constants as constants$5, cpus, hostname } from 'os';
8
- import { j as join, f as basename, h as dirname, k as resolve, p as picocolors, s as slash$2, l as isAbsolute, m as relative, o as getTests, q as getFullName, u as hasFailed, v as hasFailedSnapshot, w as getSuites, t as toArray, x as normalize, n as noop$1, y as deepMerge, z as toNamespacedPath, g as getCallLastIndex, e as notNullish, A as ensurePackageInstalled, B as stdout } from './chunk-utils-global.eb31f3da.js';
8
+ import { j as join, f as basename, d as dirname, h as resolve, p as picocolors, s as slash$2, k as isAbsolute, l as relative, m as getTests, o as getFullName, q as hasFailed, u as hasFailedSnapshot, v as getSuites, t as toArray, w as normalize, n as noop$1, x as deepMerge, y as toNamespacedPath, g as getCallLastIndex, e as notNullish, z as ensurePackageInstalled, A as stdout } from './chunk-utils-global.a5a8641f.js';
9
9
  import { createServer, mergeConfig } from 'vite';
10
10
  import fs$8, { promises, existsSync, readFileSync } from 'fs';
11
- import { d as distDir, a as defaultPort, c as configFiles } from './chunk-constants.54c46a47.js';
11
+ import { d as distDir, a as defaultPort, c as configFiles } from './chunk-constants.0567483c.js';
12
12
  import readline from 'readline';
13
13
  import require$$0$1 from 'util';
14
14
  import require$$0$2 from 'stream';
15
15
  import require$$2 from 'events';
16
16
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
17
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.6b0ec89a.js';
18
- import { c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage } from './chunk-defaults.c143550b.js';
17
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.20782527.js';
18
+ import { c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage } from './chunk-defaults.23b3ae8a.js';
19
19
  import { MessageChannel } from 'worker_threads';
20
20
  import { Tinypool } from 'tinypool';
21
21
  import { performance } from 'perf_hooks';
22
- import { e as stripAnsi, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as setInterval, o as clearInterval, q as cliTruncate, c as setTimeout$1, b as parseStacktrace, r as interpretSourcePos, s as stringify$5, u as unifiedDiff, a as posToNumber, l as lineSplitRE, d as clearTimeout$1 } from './chunk-utils-timers.27e0c6e9.js';
22
+ import { e as stripAnsi, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as setInterval, o as clearInterval, q as cliTruncate, c as setTimeout$1, b as parseStacktrace, r as interpretSourcePos, s as stringify$5, u as unifiedDiff, a as posToNumber, l as lineSplitRE, d as clearTimeout$1 } from './chunk-utils-timers.f25e8f44.js';
23
23
  import MagicString from './chunk-magic-string.d5e0e473.js';
24
24
  import { p as prompts } from './vendor-index.405e58ef.js';
25
25
 
26
- var version = "0.10.5";
26
+ var version = "0.11.0";
27
27
 
28
28
  function stripFinalNewline(input) {
29
29
  const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
@@ -9838,10 +9838,10 @@ const ReportersMap = {
9838
9838
  "junit": JUnitReporter
9839
9839
  };
9840
9840
 
9841
- async function loadCustomReporterModule(path, fetchModule) {
9841
+ async function loadCustomReporterModule(path, runner) {
9842
9842
  let customReporterModule;
9843
9843
  try {
9844
- customReporterModule = await fetchModule(path);
9844
+ customReporterModule = await runner.executeId(path);
9845
9845
  } catch (customReporterModuleError) {
9846
9846
  throw new Error(`Failed to load custom Reporter from ${path}`, { cause: customReporterModuleError });
9847
9847
  }
@@ -9849,14 +9849,14 @@ async function loadCustomReporterModule(path, fetchModule) {
9849
9849
  throw new Error(`Custom reporter loaded from ${path} was not the default export`);
9850
9850
  return customReporterModule.default;
9851
9851
  }
9852
- function createReporters(reporterReferences, fetchModule) {
9852
+ function createReporters(reporterReferences, runner) {
9853
9853
  const promisedReporters = reporterReferences.map(async (referenceOrInstance) => {
9854
9854
  if (typeof referenceOrInstance === "string") {
9855
9855
  if (referenceOrInstance in ReportersMap) {
9856
9856
  const BuiltinReporter = ReportersMap[referenceOrInstance];
9857
9857
  return new BuiltinReporter();
9858
9858
  } else {
9859
- const CustomReporter = await loadCustomReporterModule(referenceOrInstance, fetchModule);
9859
+ const CustomReporter = await loadCustomReporterModule(referenceOrInstance, runner);
9860
9860
  return new CustomReporter();
9861
9861
  }
9862
9862
  }
@@ -10310,7 +10310,7 @@ class Vitest {
10310
10310
  return node.resolveId(id, importer);
10311
10311
  }
10312
10312
  });
10313
- this.reporters = await createReporters(resolved.reporters, this.runner.executeFile.bind(this.runner));
10313
+ this.reporters = await createReporters(resolved.reporters, this.runner);
10314
10314
  this.runningPromise = void 0;
10315
10315
  this._onRestartListeners.forEach((fn) => fn());
10316
10316
  if (resolved.coverage.enabled)
@@ -10938,7 +10938,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
10938
10938
  await ctx.setServer(options, server);
10939
10939
  haveStarted = true;
10940
10940
  if (options.api && options.watch)
10941
- (await import('./chunk-api-setup.2c4e9375.js')).setup(ctx);
10941
+ (await import('./chunk-api-setup.87a943bf.js')).setup(ctx);
10942
10942
  if (!options.watch)
10943
10943
  await server.watcher.close();
10944
10944
  }
@@ -1,7 +1,7 @@
1
1
  import { builtinModules, createRequire } from 'module';
2
2
  import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
3
3
  import vm from 'vm';
4
- import { l as isAbsolute$2, k as resolve, j as join$2, C as extname$2, h as dirname$2 } from './chunk-utils-global.eb31f3da.js';
4
+ import { k as isAbsolute$2, h as resolve, j as join$2, B as extname$2, d as dirname$2 } from './chunk-utils-global.a5a8641f.js';
5
5
  import path from 'path';
6
6
  import fs, { realpathSync, statSync, Stats, promises, existsSync } from 'fs';
7
7
  import assert from 'assert';
@@ -8945,15 +8945,11 @@ class ViteNodeRunner {
8945
8945
  async directRequest(id, fsPath, _callstack) {
8946
8946
  const callstack = [..._callstack, normalizeModuleId(id)];
8947
8947
  const request = async (dep) => {
8948
- var _a, _b;
8948
+ var _a;
8949
8949
  const getStack = () => {
8950
8950
  return `stack:
8951
8951
  ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`;
8952
8952
  };
8953
- if (this.options.resolveId && this.shouldResolveId(dep)) {
8954
- const resolvedDep = await this.options.resolveId(dep, id);
8955
- dep = ((_a = resolvedDep == null ? void 0 : resolvedDep.id) == null ? void 0 : _a.replace(this.root, "")) || dep;
8956
- }
8957
8953
  let debugTimer;
8958
8954
  if (this.debug)
8959
8955
  debugTimer = setTimeout(() => this.debugLog(() => `module ${dep} takes over 2s to load.
@@ -8961,7 +8957,7 @@ ${getStack()}`), 2e3);
8961
8957
  try {
8962
8958
  if (callstack.includes(normalizeModuleId(dep))) {
8963
8959
  this.debugLog(() => `circular dependency, ${getStack()}`);
8964
- const depExports = (_b = this.moduleCache.get(dep)) == null ? void 0 : _b.exports;
8960
+ const depExports = (_a = this.moduleCache.get(dep)) == null ? void 0 : _a.exports;
8965
8961
  if (depExports)
8966
8962
  return depExports;
8967
8963
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
@@ -8973,6 +8969,18 @@ ${getStack()}`), 2e3);
8973
8969
  clearTimeout(debugTimer);
8974
8970
  }
8975
8971
  };
8972
+ Object.defineProperty(request, "callstack", { get: () => callstack });
8973
+ const resolveId = async (dep, callstackPosition = 1) => {
8974
+ if (this.options.resolveId && this.shouldResolveId(dep)) {
8975
+ let importer = callstack[callstack.length - callstackPosition];
8976
+ if (importer && importer.startsWith("mock:"))
8977
+ importer = importer.slice(5);
8978
+ const { id: id2 } = await this.options.resolveId(dep, importer) || {};
8979
+ dep = id2 && isAbsolute$2(id2) ? `/@fs/${id2}` : id2 || dep;
8980
+ }
8981
+ return dep;
8982
+ };
8983
+ id = await resolveId(id, 2);
8976
8984
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
8977
8985
  if (id in requestStubs)
8978
8986
  return requestStubs[id];
@@ -8998,13 +9006,19 @@ ${getStack()}`), 2e3);
8998
9006
  return exports.default;
8999
9007
  }
9000
9008
  };
9009
+ let require;
9001
9010
  const context = this.prepareContext({
9002
9011
  __vite_ssr_import__: request,
9003
9012
  __vite_ssr_dynamic_import__: request,
9004
9013
  __vite_ssr_exports__: exports,
9005
9014
  __vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
9006
9015
  __vite_ssr_import_meta__: { url },
9007
- require: createRequire(url),
9016
+ __vitest_resolve_id__: resolveId,
9017
+ require: (path) => {
9018
+ if (!require)
9019
+ require = createRequire(url);
9020
+ return require(path);
9021
+ },
9008
9022
  exports,
9009
9023
  module: moduleProxy,
9010
9024
  __filename,
@@ -9024,7 +9038,7 @@ ${getStack()}`), 2e3);
9024
9038
  return context;
9025
9039
  }
9026
9040
  shouldResolveId(dep) {
9027
- if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS))
9041
+ if (isNodeBuiltin(dep) || dep in (this.options.requestStubs || DEFAULT_REQUEST_STUBS) || dep.startsWith("/@vite"))
9028
9042
  return false;
9029
9043
  return !isAbsolute$2(dep) || !extname$2(dep);
9030
9044
  }
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
- import { p as picocolors } from './chunk-utils-global.eb31f3da.js';
3
- import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.965e6527.js';
2
+ import { p as picocolors } from './chunk-utils-global.a5a8641f.js';
3
+ import { v as version, s as startVitest, d as divider } from './chunk-vite-node-externalize.d6642729.js';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
@@ -16,16 +16,16 @@ import 'util';
16
16
  import 'url';
17
17
  import 'os';
18
18
  import 'vite';
19
- import './chunk-constants.54c46a47.js';
19
+ import './chunk-constants.0567483c.js';
20
20
  import 'readline';
21
- import './chunk-vite-node-utils.6b0ec89a.js';
21
+ import './chunk-vite-node-utils.20782527.js';
22
22
  import 'module';
23
23
  import 'vm';
24
- import './chunk-defaults.c143550b.js';
24
+ import './chunk-defaults.23b3ae8a.js';
25
25
  import 'worker_threads';
26
26
  import 'tinypool';
27
27
  import 'perf_hooks';
28
- import './chunk-utils-timers.27e0c6e9.js';
28
+ import './chunk-utils-timers.f25e8f44.js';
29
29
  import './chunk-magic-string.d5e0e473.js';
30
30
  import './vendor-index.405e58ef.js';
31
31
 
package/dist/entry.js CHANGED
@@ -1,20 +1,20 @@
1
- export { r as run } from './vendor-entry.9551d577.js';
1
+ export { r as run } from './vendor-entry.1b0b46f1.js';
2
2
  import 'fs';
3
- import './chunk-utils-global.eb31f3da.js';
3
+ import './chunk-utils-global.a5a8641f.js';
4
4
  import 'tty';
5
5
  import 'local-pkg';
6
6
  import 'path';
7
7
  import 'console';
8
8
  import 'stream';
9
- import './chunk-runtime-chain.d0bd6df6.js';
9
+ import './chunk-runtime-chain.8a313ffb.js';
10
10
  import 'chai';
11
11
  import './vendor-_commonjsHelpers.addc3445.js';
12
- import './chunk-runtime-rpc.710f6f7f.js';
13
- import './chunk-utils-timers.27e0c6e9.js';
14
- import './chunk-integrations-spy.f036df6f.js';
12
+ import './chunk-runtime-rpc.63398738.js';
13
+ import './chunk-utils-timers.f25e8f44.js';
14
+ import './chunk-integrations-spy.bee66426.js';
15
15
  import 'tinyspy';
16
16
  import 'util';
17
- import './chunk-defaults.c143550b.js';
17
+ import './chunk-defaults.23b3ae8a.js';
18
18
  import 'module';
19
19
  import 'url';
20
20
  import 'crypto';
package/dist/index.d.ts CHANGED
@@ -636,6 +636,7 @@ interface C8Options {
636
636
  skipFull?: boolean;
637
637
  extension?: string | string[];
638
638
  all?: boolean;
639
+ src?: string[];
639
640
  100?: boolean;
640
641
  lines?: number;
641
642
  functions?: number;
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- export { c as afterAll, f as afterEach, b as beforeAll, e as beforeEach, g as createExpect, d as describe, h as expect, k as getRunningMode, a as isFirstRun, l as isWatchMode, i as it, r as runOnce, s as suite, t as test, j as vi, v as vitest, w as withCallback } from './chunk-runtime-chain.d0bd6df6.js';
1
+ export { c as afterAll, f as afterEach, b as beforeAll, e as beforeEach, g as createExpect, d as describe, h as expect, k as getRunningMode, a as isFirstRun, l as isWatchMode, i as it, r as runOnce, s as suite, t as test, j as vi, v as vitest, w as withCallback } from './chunk-runtime-chain.8a313ffb.js';
2
2
  export { assert, default as chai, should } from 'chai';
3
3
  import './vendor-_commonjsHelpers.addc3445.js';
4
- import './chunk-runtime-rpc.710f6f7f.js';
5
- import './chunk-utils-global.eb31f3da.js';
4
+ import './chunk-runtime-rpc.63398738.js';
5
+ import './chunk-utils-global.a5a8641f.js';
6
6
  import 'tty';
7
7
  import 'local-pkg';
8
8
  import 'path';
9
9
  import 'fs';
10
- import './chunk-utils-timers.27e0c6e9.js';
11
- import './chunk-integrations-spy.f036df6f.js';
10
+ import './chunk-utils-timers.f25e8f44.js';
11
+ import './chunk-integrations-spy.bee66426.js';
12
12
  import 'tinyspy';
13
13
  import 'util';
package/dist/node.d.ts CHANGED
@@ -405,6 +405,7 @@ interface C8Options {
405
405
  skipFull?: boolean;
406
406
  extension?: string | string[];
407
407
  all?: boolean;
408
+ src?: string[];
408
409
  100?: boolean;
409
410
  lines?: number;
410
411
  functions?: number;
@@ -1016,6 +1017,10 @@ interface CliOptions extends UserConfig {
1016
1017
  declare function startVitest(cliFilters: string[], options: CliOptions, viteOverrides?: UserConfig$1): Promise<boolean>;
1017
1018
 
1018
1019
  declare type Callback = (...args: any[]) => unknown;
1020
+ interface ViteRunnerRequest {
1021
+ (dep: string): any;
1022
+ callstack: string[];
1023
+ }
1019
1024
  declare class VitestMocker {
1020
1025
  options: ExecuteOptions;
1021
1026
  private moduleCache;
@@ -1024,7 +1029,7 @@ declare class VitestMocker {
1024
1029
  private request;
1025
1030
  private root;
1026
1031
  private callbacks;
1027
- constructor(options: ExecuteOptions, moduleCache: ModuleCacheMap, request?: (dep: string) => unknown);
1032
+ constructor(options: ExecuteOptions, moduleCache: ModuleCacheMap, request?: ViteRunnerRequest);
1028
1033
  get mockMap(): MockMap;
1029
1034
  on(event: string, cb: Callback): void;
1030
1035
  private emit;
@@ -1049,7 +1054,7 @@ declare class VitestMocker {
1049
1054
  requestWithMock(dep: string): Promise<any>;
1050
1055
  queueMock(id: string, importer: string, factory?: () => unknown): void;
1051
1056
  queueUnmock(id: string, importer: string): void;
1052
- withRequest(request: (dep: string) => unknown): VitestMocker;
1057
+ withRequest(request: ViteRunnerRequest): VitestMocker;
1053
1058
  }
1054
1059
 
1055
1060
  interface ExecuteOptions extends ViteNodeRunnerOptions {
package/dist/node.js CHANGED
@@ -1,5 +1,5 @@
1
- export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.965e6527.js';
2
- export { V as VitestRunner } from './chunk-runtime-mocker.0871693a.js';
1
+ export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.d6642729.js';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.ee72d19a.js';
3
3
  import 'buffer';
4
4
  import 'path';
5
5
  import 'child_process';
@@ -13,19 +13,19 @@ import 'stream';
13
13
  import 'util';
14
14
  import 'url';
15
15
  import 'os';
16
- import './chunk-utils-global.eb31f3da.js';
16
+ import './chunk-utils-global.a5a8641f.js';
17
17
  import 'tty';
18
18
  import 'local-pkg';
19
19
  import 'vite';
20
- import './chunk-constants.54c46a47.js';
20
+ import './chunk-constants.0567483c.js';
21
21
  import 'readline';
22
- import './chunk-vite-node-utils.6b0ec89a.js';
22
+ import './chunk-vite-node-utils.20782527.js';
23
23
  import 'module';
24
24
  import 'vm';
25
- import './chunk-defaults.c143550b.js';
25
+ import './chunk-defaults.23b3ae8a.js';
26
26
  import 'worker_threads';
27
27
  import 'tinypool';
28
28
  import 'perf_hooks';
29
- import './chunk-utils-timers.27e0c6e9.js';
29
+ import './chunk-utils-timers.f25e8f44.js';
30
30
  import './chunk-magic-string.d5e0e473.js';
31
31
  import './vendor-index.405e58ef.js';
package/dist/spy.js CHANGED
@@ -1,2 +1,2 @@
1
- export { f as fn, i as isMockFunction, a as spies, s as spyOn } from './chunk-integrations-spy.f036df6f.js';
1
+ export { f as fn, i as isMockFunction, a as spies, s as spyOn } from './chunk-integrations-spy.bee66426.js';
2
2
  import 'tinyspy';
@@ -1,13 +1,13 @@
1
1
  import { promises } from 'fs';
2
- import { b as getWorkerState, t as toArray, H as clone, F as getType, m as relative, B as stdout, I as partitionSuiteChildren, J as hasTests, u as hasFailed, q as getFullName, r as resetModules } from './chunk-utils-global.eb31f3da.js';
2
+ import { a as getWorkerState, t as toArray, G as clone, E as getType, l as relative, A as stdout, H as partitionSuiteChildren, I as hasTests, q as hasFailed, o as getFullName, r as resetModules } from './chunk-utils-global.a5a8641f.js';
3
3
  import { Console } from 'console';
4
4
  import { Writable } from 'stream';
5
5
  import { importModule } from 'local-pkg';
6
- import { s as suite, t as test, d as describe, i as it, r as runOnce, a as isFirstRun, b as beforeAll, c as afterAll, e as beforeEach, f as afterEach, w as withCallback, g as createExpect, h as expect, v as vitest, j as vi, k as getRunningMode, l as isWatchMode, m as resetRunOnceCounter, R as RealDate, n as clearCollectorContext, o as defaultSuite, p as setHooks, q as getHooks, u as collectorContext, x as getSnapshotClient, y as setState, z as getFn, A as getState } from './chunk-runtime-chain.d0bd6df6.js';
6
+ import { s as suite, t as test, d as describe, i as it, r as runOnce, a as isFirstRun, b as beforeAll, c as afterAll, e as beforeEach, f as afterEach, w as withCallback, g as createExpect, h as expect, v as vitest, j as vi, k as getRunningMode, l as isWatchMode, m as resetRunOnceCounter, R as RealDate, n as clearCollectorContext, o as defaultSuite, p as setHooks, q as getHooks, u as collectorContext, x as getSnapshotClient, y as setState, z as getFn, A as getState } from './chunk-runtime-chain.8a313ffb.js';
7
7
  import chai, { assert, should, util } from 'chai';
8
- import { r as rpc } from './chunk-runtime-rpc.710f6f7f.js';
9
- import { d as clearTimeout, c as setTimeout, s as stringify } from './chunk-utils-timers.27e0c6e9.js';
10
- import { t as takeCoverage } from './chunk-defaults.c143550b.js';
8
+ import { r as rpc } from './chunk-runtime-rpc.63398738.js';
9
+ import { d as clearTimeout, c as setTimeout, s as stringify } from './chunk-utils-timers.f25e8f44.js';
10
+ import { t as takeCoverage } from './chunk-defaults.23b3ae8a.js';
11
11
  import { createHash } from 'crypto';
12
12
  import { format } from 'util';
13
13
 
@@ -212,6 +212,7 @@ const OTHER_KEYS = [
212
212
  "atob",
213
213
  "blur",
214
214
  "btoa",
215
+ "cancelAnimationFrame",
215
216
  "close",
216
217
  "confirm",
217
218
  "createPopup",
@@ -240,6 +241,7 @@ const OTHER_KEYS = [
240
241
  "print",
241
242
  "prompt",
242
243
  "removeEventListener",
244
+ "requestAnimationFrame",
243
245
  "resizeBy",
244
246
  "resizeTo",
245
247
  "screen",
@@ -262,20 +264,109 @@ const OTHER_KEYS = [
262
264
  ];
263
265
  const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
264
266
 
265
- const allowRewrite = /* @__PURE__ */ new Set([
267
+ const allowRewrite = [
266
268
  "Event",
267
269
  "EventTarget"
268
- ]);
270
+ ];
271
+ const skipKeys = [
272
+ "window",
273
+ "self"
274
+ ];
269
275
  function getWindowKeys(global, win) {
270
276
  const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
271
- if (k.startsWith("_"))
277
+ if (k.startsWith("_") || skipKeys.includes(k))
272
278
  return false;
273
279
  if (k in global)
274
- return allowRewrite.has(k);
280
+ return allowRewrite.includes(k);
275
281
  return true;
276
282
  }));
277
283
  return keys;
278
284
  }
285
+ function populateGlobal(global, win) {
286
+ const keys = getWindowKeys(global, win);
287
+ const overrideObject = /* @__PURE__ */ new Map();
288
+ for (const key of keys) {
289
+ Object.defineProperty(global, key, {
290
+ get() {
291
+ if (overrideObject.has(key))
292
+ return overrideObject.get(key);
293
+ return win[key];
294
+ },
295
+ set(v) {
296
+ overrideObject.set(key, v);
297
+ },
298
+ configurable: true
299
+ });
300
+ }
301
+ const globalKeys = /* @__PURE__ */ new Set(["window", "self", "GLOBAL", "global"]);
302
+ globalKeys.forEach((key) => {
303
+ if (!win[key])
304
+ return;
305
+ const proxy = new Proxy(win[key], {
306
+ get(target, p, receiver) {
307
+ if (overrideObject.has(p))
308
+ return overrideObject.get(p);
309
+ return Reflect.get(target, p, receiver);
310
+ },
311
+ set(target, p, value, receiver) {
312
+ try {
313
+ Object.defineProperty(global, p, {
314
+ get: () => overrideObject.get(p),
315
+ set: (value2) => overrideObject.set(p, value2),
316
+ configurable: true
317
+ });
318
+ overrideObject.set(p, value);
319
+ Reflect.set(target, p, value, receiver);
320
+ } catch {
321
+ }
322
+ return true;
323
+ },
324
+ deleteProperty(target, p) {
325
+ Reflect.deleteProperty(global, p);
326
+ overrideObject.delete(p);
327
+ return Reflect.deleteProperty(target, p);
328
+ },
329
+ defineProperty(target, p, attributes) {
330
+ if (attributes.writable && "value" in attributes) ; else if (attributes.get) {
331
+ overrideObject.delete(p);
332
+ Reflect.defineProperty(global, p, attributes);
333
+ }
334
+ return Reflect.defineProperty(target, p, attributes);
335
+ }
336
+ });
337
+ Object.defineProperty(global, key, {
338
+ get() {
339
+ return proxy;
340
+ },
341
+ configurable: true
342
+ });
343
+ });
344
+ global.globalThis = new Proxy(global.globalThis, {
345
+ set(target, key, value, receiver) {
346
+ overrideObject.set(key, value);
347
+ return Reflect.set(target, key, value, receiver);
348
+ },
349
+ deleteProperty(target, key) {
350
+ overrideObject.delete(key);
351
+ return Reflect.deleteProperty(target, key);
352
+ },
353
+ defineProperty(target, p, attributes) {
354
+ if (attributes.writable && "value" in attributes) ; else if (attributes.get && !globalKeys.has(p)) {
355
+ globalKeys.forEach((key) => {
356
+ if (win[key])
357
+ Object.defineProperty(win[key], p, attributes);
358
+ });
359
+ }
360
+ return Reflect.defineProperty(target, p, attributes);
361
+ }
362
+ });
363
+ skipKeys.forEach((k) => keys.add(k));
364
+ return {
365
+ keys,
366
+ skipKeys,
367
+ allowRewrite
368
+ };
369
+ }
279
370
 
280
371
  var __defProp$1 = Object.defineProperty;
281
372
  var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
@@ -348,24 +439,12 @@ var jsdom = {
348
439
  contentType,
349
440
  userAgent
350
441
  }, restOptions));
351
- const keys = getWindowKeys(global, dom.window);
352
- const overrideObject = /* @__PURE__ */ new Map();
353
- for (const key of keys) {
354
- Object.defineProperty(global, key, {
355
- get() {
356
- if (overrideObject.has(key))
357
- return overrideObject.get(key);
358
- return dom.window[key];
359
- },
360
- set(v) {
361
- overrideObject.set(key, v);
362
- },
363
- configurable: true
364
- });
365
- }
442
+ const { keys, allowRewrite } = populateGlobal(global, dom.window);
443
+ const originals = new Map(allowRewrite.map(([key]) => [key, global[key]]));
366
444
  return {
367
445
  teardown(global2) {
368
446
  keys.forEach((key) => delete global2[key]);
447
+ originals.forEach((v, k) => global2[k] = v);
369
448
  }
370
449
  };
371
450
  }
@@ -376,25 +455,13 @@ var happy = {
376
455
  async setup(global) {
377
456
  const { Window, GlobalWindow } = await importModule("happy-dom");
378
457
  const win = new (GlobalWindow || Window)();
379
- const keys = getWindowKeys(global, win);
380
- const overrideObject = /* @__PURE__ */ new Map();
381
- for (const key of keys) {
382
- Object.defineProperty(global, key, {
383
- get() {
384
- if (overrideObject.has(key))
385
- return overrideObject.get(key);
386
- return win[key];
387
- },
388
- set(v) {
389
- overrideObject.set(key, v);
390
- },
391
- configurable: true
392
- });
393
- }
458
+ const { keys, allowRewrite } = populateGlobal(global, win);
459
+ const originals = new Map(allowRewrite.map(([key]) => [key, global[key]]));
394
460
  return {
395
461
  teardown(global2) {
396
462
  win.happyDOM.cancelAsync();
397
463
  keys.forEach((key) => delete global2[key]);
464
+ originals.forEach((v, k) => global2[k] = v);
398
465
  }
399
466
  };
400
467
  }
@@ -419,7 +486,7 @@ async function setupGlobalEnv(config) {
419
486
  globalSetup = true;
420
487
  setupConsoleLogSpy();
421
488
  if (config.globals)
422
- (await import('./chunk-integrations-globals.d3383e75.js')).registerApiGlobally();
489
+ (await import('./chunk-integrations-globals.1ce15dfd.js')).registerApiGlobally();
423
490
  }
424
491
  function setupDefines(defines) {
425
492
  for (const key in defines)
package/dist/worker.js CHANGED
@@ -1,8 +1,8 @@
1
- import { k as resolve, b as getWorkerState, B as stdout } from './chunk-utils-global.eb31f3da.js';
2
- import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.6b0ec89a.js';
3
- import { d as distDir } from './chunk-constants.54c46a47.js';
4
- import { e as executeInViteNode } from './chunk-runtime-mocker.0871693a.js';
5
- import { r as rpc } from './chunk-runtime-rpc.710f6f7f.js';
1
+ import { h as resolve, a as getWorkerState, A as stdout } from './chunk-utils-global.a5a8641f.js';
2
+ import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.20782527.js';
3
+ import { d as distDir } from './chunk-constants.0567483c.js';
4
+ import { e as executeInViteNode } from './chunk-runtime-mocker.ee72d19a.js';
5
+ import { r as rpc } from './chunk-runtime-rpc.63398738.js';
6
6
  import 'tty';
7
7
  import 'local-pkg';
8
8
  import 'path';
@@ -32,7 +32,7 @@ async function startViteNode(ctx) {
32
32
  rpc().onUnhandledRejection(err);
33
33
  });
34
34
  const { config } = ctx;
35
- const { run: run2, collect: collect2 } = (await executeInViteNode({
35
+ const { run: run2 } = (await executeInViteNode({
36
36
  files: [
37
37
  resolve(distDir, "entry.js")
38
38
  ],
@@ -48,7 +48,7 @@ async function startViteNode(ctx) {
48
48
  root: config.root,
49
49
  base: config.base
50
50
  }))[0];
51
- _viteNode = { run: run2, collect: collect2 };
51
+ _viteNode = { run: run2 };
52
52
  return _viteNode;
53
53
  }
54
54
  function init(ctx) {
@@ -72,19 +72,18 @@ function init(ctx) {
72
72
  }
73
73
  })
74
74
  };
75
- if (ctx.invalidates)
76
- ctx.invalidates.forEach((i) => moduleCache.delete(i));
75
+ if (ctx.invalidates) {
76
+ ctx.invalidates.forEach((i) => {
77
+ moduleCache.delete(i);
78
+ moduleCache.delete(`${i}__mock`);
79
+ });
80
+ }
77
81
  ctx.files.forEach((i) => moduleCache.delete(i));
78
82
  }
79
- async function collect(ctx) {
80
- init(ctx);
81
- const { collect: collect2 } = await startViteNode(ctx);
82
- return collect2(ctx.files, ctx.config);
83
- }
84
83
  async function run(ctx) {
85
84
  init(ctx);
86
85
  const { run: run2 } = await startViteNode(ctx);
87
86
  return run2(ctx.files, ctx.config);
88
87
  }
89
88
 
90
- export { collect, run };
89
+ export { run };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.10.5",
4
+ "version": "0.11.0",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "keywords": [
7
7
  "vite",
@@ -93,7 +93,7 @@
93
93
  "@types/node": "^17.0.31",
94
94
  "@types/prompts": "^2.4.0",
95
95
  "@types/sinonjs__fake-timers": "^8.1.2",
96
- "@vitest/ui": "0.10.5",
96
+ "@vitest/ui": "0.11.0",
97
97
  "birpc": "^0.2.2",
98
98
  "c8": "^7.11.2",
99
99
  "cac": "^6.7.12",
@@ -116,11 +116,11 @@
116
116
  "pkg-types": "^0.3.2",
117
117
  "pretty-format": "^27.5.1",
118
118
  "prompts": "^2.4.2",
119
- "rollup": "^2.71.1",
119
+ "rollup": "^2.72.1",
120
120
  "source-map-js": "^1.0.2",
121
121
  "strip-ansi": "^7.0.1",
122
122
  "typescript": "^4.6.4",
123
- "vite-node": "0.10.5",
123
+ "vite-node": "0.11.0",
124
124
  "ws": "^8.6.0"
125
125
  },
126
126
  "engines": {