vitest 0.30.0 → 0.31.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.
Files changed (32) hide show
  1. package/LICENSE.md +331 -594
  2. package/dist/browser.d.ts +3 -4
  3. package/dist/browser.js +2 -2
  4. package/dist/child.js +12 -4
  5. package/dist/{chunk-api-setup.6662587e.js → chunk-api-setup.df3106cd.js} +14 -5
  6. package/dist/{chunk-install-pkg.6450b372.js → chunk-install-pkg.e0e70dba.js} +4 -5
  7. package/dist/{chunk-integrations-globals.d419838f.js → chunk-integrations-globals.88c8a0cf.js} +2 -2
  8. package/dist/cli.js +6 -7
  9. package/dist/config.cjs +1 -0
  10. package/dist/config.d.ts +11 -8
  11. package/dist/config.js +1 -0
  12. package/dist/coverage.d.ts +5 -5
  13. package/dist/coverage.js +6 -6
  14. package/dist/entry.js +22 -5
  15. package/dist/environments.d.ts +3 -4
  16. package/dist/index.d.ts +14 -6
  17. package/dist/index.js +3 -3
  18. package/dist/node.d.ts +4 -5
  19. package/dist/node.js +6 -7
  20. package/dist/runners.d.ts +7 -5
  21. package/dist/runners.js +12 -1
  22. package/dist/{types-f03c83c4.d.ts → types-b7007192.d.ts} +84 -328
  23. package/dist/{vendor-cli-api.c04eaa34.js → vendor-cli-api.de0530cb.js} +2061 -2353
  24. package/dist/{vendor-coverage.a585b712.js → vendor-coverage.c8fd34c3.js} +2 -0
  25. package/dist/{vendor-execute.8eaab47b.js → vendor-execute.a08cff9c.js} +2 -2
  26. package/dist/{vendor-index.4f82d248.js → vendor-index.7dcbfa46.js} +7 -1
  27. package/dist/{vendor-index.81b9e499.js → vendor-index.b0b501c8.js} +1 -1
  28. package/dist/{vendor-setup.common.cef38f4e.js → vendor-setup.common.266b69fb.js} +1 -1
  29. package/dist/{vendor-vi.a3ff54b1.js → vendor-vi.458e47b1.js} +9 -1
  30. package/dist/worker.js +13 -4
  31. package/package.json +11 -10
  32. package/suppress-warnings.cjs +1 -0
@@ -8,6 +8,8 @@ async function resolveCoverageProviderModule(options, loader) {
8
8
  const provider = options.provider;
9
9
  if (provider === "c8" || provider === "istanbul") {
10
10
  const { default: coverageModule } = await loader.executeId(CoverageProviderMap[provider]);
11
+ if (!coverageModule)
12
+ throw new Error(`Failed to load ${CoverageProviderMap[provider]}. Default export is missing.`);
11
13
  return coverageModule;
12
14
  }
13
15
  let customProviderModule;
@@ -7,7 +7,7 @@ import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global
7
7
  import { d as distDir } from './vendor-paths.84fc7a99.js';
8
8
  import { existsSync, readdirSync } from 'node:fs';
9
9
  import { getColors, getType } from '@vitest/utils';
10
- import { e as getAllMockableProperties } from './vendor-index.4f82d248.js';
10
+ import { e as getAllMockableProperties } from './vendor-index.7dcbfa46.js';
11
11
  import { spyOn } from '@vitest/spy';
12
12
  import { r as rpc } from './vendor-rpc.4d3d7a54.js';
13
13
 
@@ -93,7 +93,7 @@ const _VitestMocker = class {
93
93
  exports = await mock();
94
94
  } catch (err) {
95
95
  const vitestError = new Error(
96
- '[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/#vi-mock'
96
+ '[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock'
97
97
  );
98
98
  vitestError.cause = err;
99
99
  throw vitestError;
@@ -87,6 +87,12 @@ function getEnvironmentTransformMode(config, environment) {
87
87
  return void 0;
88
88
  return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
89
89
  }
90
+ class AggregateErrorPonyfill extends Error {
91
+ constructor(errors, message = "") {
92
+ super(message);
93
+ this.errors = [...errors];
94
+ }
95
+ }
90
96
 
91
97
  const DEFAULT_TIMEOUT = 6e4;
92
98
  function createBirpc(functions, options) {
@@ -158,4 +164,4 @@ function nanoid(size = 21) {
158
164
  return id;
159
165
  }
160
166
 
161
- export { getEnvironmentTransformMode as a, stdout as b, createBirpc as c, deepMerge as d, getAllMockableProperties as e, groupBy as g, isPrimitive as i, noop as n, slash as s, toArray as t };
167
+ export { AggregateErrorPonyfill as A, getEnvironmentTransformMode as a, stdout as b, createBirpc as c, deepMerge as d, getAllMockableProperties as e, groupBy as g, isPrimitive as i, noop as n, slash as s, toArray as t };
@@ -1,5 +1,5 @@
1
1
  import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
2
- import { e as bench, c as createExpect, d as globalExpect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.a3ff54b1.js';
2
+ import { e as bench, c as createExpect, d as globalExpect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.458e47b1.js';
3
3
  import { i as isFirstRun, a as runOnce } from './vendor-run-once.69ce7172.js';
4
4
  import * as chai from 'chai';
5
5
  import { assert, should } from 'chai';
@@ -10,7 +10,7 @@ async function setupCommonEnv(config) {
10
10
  globalSetup = true;
11
11
  setSafeTimers();
12
12
  if (config.globals)
13
- (await import('./chunk-integrations-globals.d419838f.js')).registerApiGlobally();
13
+ (await import('./chunk-integrations-globals.88c8a0cf.js')).registerApiGlobally();
14
14
  }
15
15
  function setupDefines(defines) {
16
16
  for (const key in defines)
@@ -1,6 +1,6 @@
1
1
  import { getCurrentSuite, getCurrentTest } from '@vitest/runner';
2
2
  import { createChainable, getNames } from '@vitest/runner/utils';
3
- import { getSafeTimers, noop, createSimpleStackTrace, parseSingleStack } from '@vitest/utils';
3
+ import { getSafeTimers, noop, assertTypes, createSimpleStackTrace, parseSingleStack } from '@vitest/utils';
4
4
  import { d as isRunningInBenchmark, c as resetModules } from './vendor-index.fad2598b.js';
5
5
  import * as chai$1 from 'chai';
6
6
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.76cdd49e.js';
@@ -3116,6 +3116,10 @@ function createVitest() {
3116
3116
  let _mockedDate = null;
3117
3117
  let _config = null;
3118
3118
  const workerState = getWorkerState();
3119
+ if (!workerState) {
3120
+ const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
3121
+ throw new Error(errorMsg);
3122
+ }
3119
3123
  const _timers = new FakeTimers({
3120
3124
  global: globalThis,
3121
3125
  config: workerState.config.fakeTimers
@@ -3202,6 +3206,10 @@ function createVitest() {
3202
3206
  // mocks
3203
3207
  spyOn,
3204
3208
  fn,
3209
+ hoisted(factory) {
3210
+ assertTypes(factory, '"vi.hoisted" factory', ["function"]);
3211
+ return factory();
3212
+ },
3205
3213
  mock(path, factory) {
3206
3214
  const importer = getImporter();
3207
3215
  _mocker.queueMock(
package/dist/worker.js CHANGED
@@ -1,7 +1,8 @@
1
- import { c as createBirpc } from './vendor-index.4f82d248.js';
1
+ import { performance } from 'node:perf_hooks';
2
+ import { c as createBirpc } from './vendor-index.7dcbfa46.js';
2
3
  import { workerId } from 'tinypool';
3
4
  import { g as getWorkerState } from './vendor-global.6795f91f.js';
4
- import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.8eaab47b.js';
5
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.a08cff9c.js';
5
6
  import { s as setupInspect } from './vendor-inspector.47fc8cbb.js';
6
7
  import { a as rpcDone } from './vendor-rpc.4d3d7a54.js';
7
8
  import '@vitest/utils';
@@ -21,20 +22,28 @@ function init(ctx) {
21
22
  const { config, port, workerId: workerId$1 } = ctx;
22
23
  process.env.VITEST_WORKER_ID = String(workerId$1);
23
24
  process.env.VITEST_POOL_ID = String(workerId);
25
+ let setCancel = (_reason) => {
26
+ };
27
+ const onCancel = new Promise((resolve) => {
28
+ setCancel = resolve;
29
+ });
24
30
  globalThis.__vitest_environment__ = config.environment;
25
31
  globalThis.__vitest_worker__ = {
26
32
  ctx,
27
33
  moduleCache,
28
34
  config,
29
35
  mockMap,
36
+ onCancel,
30
37
  durations: {
31
38
  environment: 0,
32
39
  prepare: performance.now()
33
40
  },
34
41
  rpc: createBirpc(
35
- {},
36
42
  {
37
- eventNames: ["onUserConsoleLog", "onFinished", "onCollected", "onWorkerExit"],
43
+ onCancel: setCancel
44
+ },
45
+ {
46
+ eventNames: ["onUserConsoleLog", "onFinished", "onCollected", "onWorkerExit", "onCancel"],
38
47
  post(v) {
39
48
  port.postMessage(v);
40
49
  },
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.30.0",
4
+ "version": "0.31.0",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
8
- "funding": "https://github.com/sponsors/antfu",
8
+ "funding": "https://opencollective.com/vitest",
9
9
  "homepage": "https://github.com/vitest-dev/vitest#readme",
10
10
  "repository": {
11
11
  "type": "git",
@@ -142,26 +142,27 @@
142
142
  "magic-string": "^0.30.0",
143
143
  "pathe": "^1.1.0",
144
144
  "picocolors": "^1.0.0",
145
- "source-map": "^0.6.1",
146
145
  "std-env": "^3.3.2",
147
146
  "strip-literal": "^1.0.1",
148
147
  "tinybench": "^2.4.0",
149
- "tinypool": "^0.4.0",
148
+ "tinypool": "^0.5.0",
150
149
  "vite": "^3.0.0 || ^4.0.0",
151
150
  "why-is-node-running": "^2.2.2",
152
- "vite-node": "0.30.0",
153
- "@vitest/spy": "0.30.0",
154
- "@vitest/expect": "0.30.0",
155
- "@vitest/runner": "0.30.0",
156
- "@vitest/utils": "0.30.0",
157
- "@vitest/snapshot": "0.30.0"
151
+ "@vitest/expect": "0.31.0",
152
+ "@vitest/runner": "0.31.0",
153
+ "vite-node": "0.31.0",
154
+ "@vitest/spy": "0.31.0",
155
+ "@vitest/utils": "0.31.0",
156
+ "@vitest/snapshot": "0.31.0"
158
157
  },
159
158
  "devDependencies": {
160
159
  "@ampproject/remapping": "^2.2.0",
161
160
  "@antfu/install-pkg": "^0.1.1",
162
161
  "@edge-runtime/vm": "2.1.2",
162
+ "@jridgewell/trace-mapping": "^0.3.17",
163
163
  "@sinonjs/fake-timers": "^10.0.2",
164
164
  "@types/diff": "^5.0.3",
165
+ "@types/estree": "^1.0.1",
165
166
  "@types/istanbul-lib-coverage": "^2.0.4",
166
167
  "@types/istanbul-reports": "^3.0.1",
167
168
  "@types/jsdom": "^21.1.1",
@@ -4,6 +4,7 @@
4
4
  const ignoreWarnings = new Set([
5
5
  '--experimental-loader is an experimental feature. This feature could change at any time',
6
6
  'Custom ESM Loaders is an experimental feature. This feature could change at any time',
7
+ 'Custom ESM Loaders is an experimental feature and might change at any time',
7
8
  ])
8
9
 
9
10
  const { emit } = process