vitest 1.0.1 → 1.0.3

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 (37) hide show
  1. package/LICENSE.md +0 -17
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +1 -1
  4. package/dist/child.js +3 -3
  5. package/dist/chunks/install-pkg.LE8oaA1t.js +319 -0
  6. package/dist/chunks/{integrations-globals.eip0xL77.js → integrations-globals.8mr2ENps.js} +2 -2
  7. package/dist/cli.js +3 -3
  8. package/dist/config.cjs +1 -1
  9. package/dist/config.d.ts +1 -1
  10. package/dist/config.js +1 -1
  11. package/dist/coverage.d.ts +1 -1
  12. package/dist/entry-vm.js +2 -2
  13. package/dist/entry.js +2 -2
  14. package/dist/environments.d.ts +2 -1
  15. package/dist/environments.js +1 -1
  16. package/dist/execute.d.ts +1 -1
  17. package/dist/execute.js +1 -1
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +3 -3
  20. package/dist/node.d.ts +2 -2
  21. package/dist/node.js +3 -3
  22. package/dist/{reporters-LLiOBu3g.d.ts → reporters-OH1c16Kq.d.ts} +1 -2
  23. package/dist/reporters.d.ts +1 -1
  24. package/dist/runners.d.ts +1 -1
  25. package/dist/runners.js +1 -1
  26. package/dist/{suite-SvxfaIxW.d.ts → suite-9ReVEt_h.d.ts} +1 -1
  27. package/dist/suite.d.ts +2 -2
  28. package/dist/vendor/{environments.hTqxBFDN.js → environments.v4R4vGad.js} +10 -5
  29. package/dist/vendor/{execute.ILey0jnF.js → execute.1R_t2FPL.js} +3 -1
  30. package/dist/vendor/{index.VL3WbvjT.js → index.uQelX_YY.js} +1 -1
  31. package/dist/vendor/{loader.w8KTtIkD.js → loader.zIj6SiI8.js} +1 -1
  32. package/dist/vendor/{node.mLeBfrTn.js → node.XBEcdByD.js} +18 -17
  33. package/dist/vendor/{vi.JXuS6emb.js → vi.pk4NToBt.js} +2 -0
  34. package/dist/vm.js +3 -3
  35. package/dist/worker.js +3 -3
  36. package/package.json +10 -10
  37. package/dist/chunks/install-pkg.ORGzQeqb.js +0 -457
package/dist/runners.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
2
- import { g as getSnapshotClient, c as createExpect, v as vi } from './vendor/vi.JXuS6emb.js';
2
+ import { g as getSnapshotClient, c as createExpect, v as vi } from './vendor/vi.pk4NToBt.js';
3
3
  import './vendor/index.XU72Rmy8.js';
4
4
  import { a as rpc } from './vendor/rpc.Bl-ysZIr.js';
5
5
  import { g as getFullName } from './vendor/tasks.IknbGB2n.js';
@@ -1,6 +1,6 @@
1
1
  import { Custom } from '@vitest/runner';
2
2
  import '@vitest/runner/utils';
3
- import { ak as BenchFunction, al as BenchmarkAPI } from './reporters-LLiOBu3g.js';
3
+ import { ak as BenchFunction, al as BenchmarkAPI } from './reporters-OH1c16Kq.js';
4
4
  import { Options } from 'tinybench';
5
5
 
6
6
  declare function getBenchOptions(key: Custom): Options;
package/dist/suite.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createTaskCollector, getCurrentSuite, getFn, setFn } from '@vitest/runner';
2
2
  export { createChainable } from '@vitest/runner/utils';
3
- export { g as getBenchFn, a as getBenchOptions } from './suite-SvxfaIxW.js';
4
- import './reporters-LLiOBu3g.js';
3
+ export { g as getBenchFn, a as getBenchOptions } from './suite-9ReVEt_h.js';
4
+ import './reporters-OH1c16Kq.js';
5
5
  import 'vite';
6
6
  import 'vite-node';
7
7
  import '@vitest/snapshot';
@@ -350,12 +350,13 @@ const skipKeys = [
350
350
  "top",
351
351
  "parent"
352
352
  ];
353
- function getWindowKeys(global, win) {
354
- const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => {
353
+ function getWindowKeys(global, win, additionalKeys = []) {
354
+ const keysArray = [...additionalKeys, ...KEYS];
355
+ const keys = new Set(keysArray.concat(Object.getOwnPropertyNames(win)).filter((k) => {
355
356
  if (skipKeys.includes(k))
356
357
  return false;
357
358
  if (k in global)
358
- return KEYS.includes(k);
359
+ return keysArray.includes(k);
359
360
  return true;
360
361
  }));
361
362
  return keys;
@@ -365,7 +366,7 @@ function isClassLikeName(name) {
365
366
  }
366
367
  function populateGlobal(global, win, options = {}) {
367
368
  const { bindFunctions = false } = options;
368
- const keys = getWindowKeys(global, win);
369
+ const keys = getWindowKeys(global, win, options.additionalKeys);
369
370
  const originals = /* @__PURE__ */ new Map();
370
371
  const overrideObject = /* @__PURE__ */ new Map();
371
372
  for (const key of keys) {
@@ -581,7 +582,11 @@ var happy = {
581
582
  disableErrorCapturing: true
582
583
  }
583
584
  });
584
- const { keys, originals } = populateGlobal(global, win, { bindFunctions: true });
585
+ const { keys, originals } = populateGlobal(global, win, {
586
+ bindFunctions: true,
587
+ // jsdom doesn't support Request and Response, but happy-dom does
588
+ additionalKeys: ["Request", "Response"]
589
+ });
585
590
  return {
586
591
  teardown(global2) {
587
592
  win.happyDOM.cancelAsync();
@@ -244,7 +244,9 @@ ${c.green(`vi.mock("${mockpath}", async () => {
244
244
  if (isFunction) {
245
245
  let mockFunction2 = function() {
246
246
  if (this instanceof newContainer[property]) {
247
- for (const { key } of getAllMockableProperties(this, false, primitives)) {
247
+ for (const { key, descriptor: descriptor2 } of getAllMockableProperties(this, false, primitives)) {
248
+ if (descriptor2.get)
249
+ continue;
248
250
  const value2 = this[key];
249
251
  const type2 = getType(value2);
250
252
  const isFunction2 = type2.includes("Function") && typeof value2 === "function";
@@ -1,7 +1,7 @@
1
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
2
  import { b as bench } from './benchmark.WVm6DARl.js';
3
3
  import { i as isFirstRun, r as runOnce } from './run-once.X3E7xx3F.js';
4
- import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.JXuS6emb.js';
4
+ import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.pk4NToBt.js';
5
5
  import { g as getWorkerState } from './global.L7JRz1qU.js';
6
6
  import * as chai from 'chai';
7
7
  import { assert, should } from 'chai';
@@ -1,6 +1,6 @@
1
1
  import { resolve, normalize } from 'pathe';
2
2
  import { ViteNodeRunner } from 'vite-node/client';
3
- import { e as environments } from './environments.hTqxBFDN.js';
3
+ import { e as environments } from './environments.v4R4vGad.js';
4
4
 
5
5
  function isBuiltinEnvironment(env) {
6
6
  return env in environments;
@@ -33,6 +33,7 @@ import { writeFile, rm } from 'node:fs/promises';
33
33
  import { performance } from 'node:perf_hooks';
34
34
  import { execa } from 'execa';
35
35
  import { TraceMap, generatedPositionFor, parseErrorStacktrace } from '@vitest/utils/source-map';
36
+ import { createRequire } from 'node:module';
36
37
  import { isPackageExists, resolveModule } from 'local-pkg';
37
38
  import { isCI, provider as provider$1 } from 'std-env';
38
39
  import ge from 'module';
@@ -43,7 +44,7 @@ import crypto, { createHash } from 'node:crypto';
43
44
  import require$$0$3 from 'assert';
44
45
  import MagicString from 'magic-string';
45
46
  import { stripLiteral } from 'strip-literal';
46
- import { g as getEnvPackageName } from './environments.hTqxBFDN.js';
47
+ import { g as getEnvPackageName } from './environments.v4R4vGad.js';
47
48
  import readline from 'node:readline';
48
49
  import require$$0$4 from 'readline';
49
50
 
@@ -62,14 +63,22 @@ function _mergeNamespaces(n, m) {
62
63
  return Object.freeze(n);
63
64
  }
64
65
 
65
- var version$1 = "1.0.1";
66
+ var version$1 = "1.0.3";
66
67
 
67
68
  const __dirname$1 = url.fileURLToPath(new URL(".", import.meta.url));
68
69
  async function ensurePackageInstalled(dependency, root) {
70
+ if (process.versions.pnp) {
71
+ const targetRequire = createRequire(__dirname$1);
72
+ try {
73
+ targetRequire.resolve(dependency, { paths: [root, __dirname$1] });
74
+ return true;
75
+ } catch (error) {
76
+ }
77
+ }
69
78
  if (isPackageExists(dependency, { paths: [root, __dirname$1] }))
70
79
  return true;
71
80
  const promptInstall = !isCI && process.stdout.isTTY;
72
- process.stderr.write(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
81
+ process.stderr.write(c.red(`${c.inverse(c.red(" MISSING DEPENDENCY "))} Cannot find dependency '${dependency}'
73
82
 
74
83
  `));
75
84
  if (!promptInstall)
@@ -81,7 +90,7 @@ async function ensurePackageInstalled(dependency, root) {
81
90
  message: c.reset(`Do you want to install ${c.green(dependency)}?`)
82
91
  });
83
92
  if (install) {
84
- await (await import('../chunks/install-pkg.ORGzQeqb.js')).installPackage(dependency, { dev: true });
93
+ await (await import('../chunks/install-pkg.LE8oaA1t.js')).installPackage(dependency, { dev: true });
85
94
  process.stderr.write(c.yellow(`
86
95
  Package ${dependency} installed, re-run the command to start.
87
96
  `));
@@ -4687,7 +4696,7 @@ class StateManager {
4687
4696
 
4688
4697
  var _a, _b;
4689
4698
  const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
4690
- const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**", "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*"];
4699
+ const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**", "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*"];
4691
4700
  const benchmarkConfigDefaults = {
4692
4701
  include: ["**/*.{bench,benchmark}.?(c|m)[jt]s?(x)"],
4693
4702
  exclude: defaultExclude,
@@ -6283,7 +6292,7 @@ createLogUpdate(process$2.stdout);
6283
6292
 
6284
6293
  createLogUpdate(process$2.stderr);
6285
6294
 
6286
- var version = "1.0.1";
6295
+ var version = "1.0.3";
6287
6296
 
6288
6297
  async function printError(error, project, options) {
6289
6298
  const { showCodeFrame = true, fullStack = false, type } = options;
@@ -7606,7 +7615,6 @@ class Vitest {
7606
7615
  _onClose = [];
7607
7616
  _onSetServer = [];
7608
7617
  _onCancelListeners = [];
7609
- _poolClosePromise;
7610
7618
  async setServer(options, server, cliOptions) {
7611
7619
  var _a, _b, _c, _d;
7612
7620
  (_a = this.unregisterWatcher) == null ? void 0 : _a.call(this);
@@ -7797,7 +7805,7 @@ class Vitest {
7797
7805
  return Promise.all(this.projects.map((w) => w.initBrowserProvider()));
7798
7806
  }
7799
7807
  async start(filters) {
7800
- var _a, _b, _c;
7808
+ var _a, _b;
7801
7809
  this._onClose = [];
7802
7810
  try {
7803
7811
  await this.initCoverageProvider();
@@ -7823,8 +7831,6 @@ class Vitest {
7823
7831
  await this.cache.stats.populateStats(this.config.root, files);
7824
7832
  await this.runFiles(files);
7825
7833
  }
7826
- if (!this.config.watch && ((_c = this.pool) == null ? void 0 : _c.close))
7827
- this._poolClosePromise = this.pool.close();
7828
7834
  await this.reportCoverage(true);
7829
7835
  if (this.config.watch)
7830
7836
  await this.report("onWatcherStart");
@@ -7839,7 +7845,7 @@ class Vitest {
7839
7845
  return;
7840
7846
  const dependencies = [...transformed.deps || [], ...transformed.dynamicDeps || []];
7841
7847
  await Promise.all(dependencies.map(async (dep) => {
7842
- const path = await this.server.pluginContainer.resolveId(dep, filepath2, { ssr: true });
7848
+ const path = await project.server.pluginContainer.resolveId(dep, filepath2, { ssr: true });
7843
7849
  const fsPath = path && !path.external && path.id.split("?")[0];
7844
7850
  if (fsPath && !fsPath.includes("node_modules") && !deps.has(fsPath) && existsSync(fsPath)) {
7845
7851
  deps.add(fsPath);
@@ -8145,8 +8151,7 @@ class Vitest {
8145
8151
  if (this.pool) {
8146
8152
  closePromises.push((async () => {
8147
8153
  var _a, _b;
8148
- await (this._poolClosePromise || ((_b = (_a = this.pool) == null ? void 0 : _a.close) == null ? void 0 : _b.call(_a)));
8149
- this._poolClosePromise = void 0;
8154
+ await ((_b = (_a = this.pool) == null ? void 0 : _a.close) == null ? void 0 : _b.call(_a));
8150
8155
  this.pool = void 0;
8151
8156
  })());
8152
8157
  }
@@ -14779,10 +14784,6 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides) {
14779
14784
  if (options.run)
14780
14785
  options.watch = false;
14781
14786
  const root = resolve(options.root || process.cwd());
14782
- if (!await ensurePackageInstalled("vite", root)) {
14783
- process.exitCode = 1;
14784
- return;
14785
- }
14786
14787
  if (typeof options.coverage === "boolean")
14787
14788
  options.coverage = { enabled: options.coverage };
14788
14789
  if (typeof options.browser === "boolean")
@@ -316,6 +316,8 @@ const SnapshotPlugin = (chai, utils) => {
316
316
  const error = utils.flag(this, "error");
317
317
  const promise = utils.flag(this, "promise");
318
318
  const errorMessage = utils.flag(this, "message");
319
+ if (inlineSnapshot)
320
+ inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
319
321
  getSnapshotClient().assert({
320
322
  received: getError(expected, promise),
321
323
  message,
package/dist/vm.js CHANGED
@@ -7,11 +7,11 @@ import { c as createBirpc } from './vendor/index.cAUulNDf.js';
7
7
  import { resolve } from 'pathe';
8
8
  import { installSourcemapsSupport } from 'vite-node/source-map';
9
9
  import { distDir } from './paths.js';
10
- import { l as loadEnvironment } from './vendor/loader.w8KTtIkD.js';
11
- import { b as startVitestExecutor } from './vendor/execute.ILey0jnF.js';
10
+ import { l as loadEnvironment } from './vendor/loader.zIj6SiI8.js';
11
+ import { b as startVitestExecutor } from './vendor/execute.1R_t2FPL.js';
12
12
  import { createCustomConsole } from './chunks/runtime-console.hf2msWA9.js';
13
13
  import { c as createSafeRpc } from './vendor/rpc.Bl-ysZIr.js';
14
- import './vendor/environments.hTqxBFDN.js';
14
+ import './vendor/environments.v4R4vGad.js';
15
15
  import 'node:console';
16
16
  import 'local-pkg';
17
17
  import 'vite-node/utils';
package/dist/worker.js CHANGED
@@ -2,13 +2,13 @@ import { performance } from 'node:perf_hooks';
2
2
  import { c as createBirpc } from './vendor/index.cAUulNDf.js';
3
3
  import { workerId } from 'tinypool';
4
4
  import { g as getWorkerState } from './vendor/global.L7JRz1qU.js';
5
- import { l as loadEnvironment } from './vendor/loader.w8KTtIkD.js';
6
- import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor/execute.ILey0jnF.js';
5
+ import { l as loadEnvironment } from './vendor/loader.zIj6SiI8.js';
6
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor/execute.1R_t2FPL.js';
7
7
  import { s as setupInspect } from './vendor/inspector.lFAeuaAt.js';
8
8
  import { r as rpcDone, c as createSafeRpc } from './vendor/rpc.Bl-ysZIr.js';
9
9
  import 'pathe';
10
10
  import 'vite-node/client';
11
- import './vendor/environments.hTqxBFDN.js';
11
+ import './vendor/environments.v4R4vGad.js';
12
12
  import 'node:console';
13
13
  import 'local-pkg';
14
14
  import 'node:url';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "description": "Next generation testing framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -145,18 +145,18 @@
145
145
  "strip-literal": "^1.3.0",
146
146
  "tinybench": "^2.5.1",
147
147
  "tinypool": "^0.8.1",
148
- "vite": "^5.0.0-beta.19 || ^5.0.0",
148
+ "vite": "^5.0.0",
149
149
  "why-is-node-running": "^2.2.2",
150
- "@vitest/expect": "1.0.1",
151
- "@vitest/snapshot": "1.0.1",
152
- "@vitest/spy": "1.0.1",
153
- "@vitest/runner": "1.0.1",
154
- "@vitest/utils": "1.0.1",
155
- "vite-node": "1.0.1"
150
+ "@vitest/expect": "1.0.3",
151
+ "@vitest/utils": "1.0.3",
152
+ "@vitest/spy": "1.0.3",
153
+ "@vitest/snapshot": "1.0.3",
154
+ "vite-node": "1.0.3",
155
+ "@vitest/runner": "1.0.3"
156
156
  },
157
157
  "devDependencies": {
158
158
  "@ampproject/remapping": "^2.2.1",
159
- "@antfu/install-pkg": "^0.1.1",
159
+ "@antfu/install-pkg": "^0.3.1",
160
160
  "@edge-runtime/vm": "^3.1.7",
161
161
  "@sinonjs/fake-timers": "11.1.0",
162
162
  "@types/estree": "^1.0.5",
@@ -176,7 +176,7 @@
176
176
  "get-tsconfig": "^4.7.2",
177
177
  "happy-dom": "^12.10.3",
178
178
  "jsdom": "^23.0.1",
179
- "log-update": "^6.0.0",
179
+ "log-update": "^5.0.1",
180
180
  "micromatch": "^4.0.5",
181
181
  "p-limit": "^5.0.0",
182
182
  "pretty-format": "^29.7.0",