vitest 1.0.0-beta.3 → 1.0.0-beta.4

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 (44) hide show
  1. package/LICENSE.md +17 -0
  2. package/dist/browser.d.ts +1 -2
  3. package/dist/browser.js +3 -3
  4. package/dist/child.js +5 -4
  5. package/dist/{chunk-api-setup.37a43981.js → chunk-api-setup.6d19ab38.js} +6 -2
  6. package/dist/{chunk-install-pkg.6349b322.js → chunk-install-pkg.e1d6323e.js} +4 -4
  7. package/dist/{chunk-integrations-globals.9df12d91.js → chunk-integrations-globals.2b099e04.js} +6 -6
  8. package/dist/cli.js +8 -5
  9. package/dist/config.cjs +1 -0
  10. package/dist/config.d.ts +1 -2
  11. package/dist/config.js +1 -0
  12. package/dist/coverage.d.ts +1 -2
  13. package/dist/entry-vm.js +8 -8
  14. package/dist/entry.js +8 -8
  15. package/dist/environments.d.ts +1 -2
  16. package/dist/execute.d.ts +2 -3
  17. package/dist/execute.js +1 -2
  18. package/dist/index.d.ts +233 -60
  19. package/dist/index.js +7 -7
  20. package/dist/node.d.ts +8 -4
  21. package/dist/node.js +4 -4
  22. package/dist/{reporters-1678fe04.d.ts → reporters-50c2bd49.d.ts} +39 -6
  23. package/dist/reporters.d.ts +1 -2
  24. package/dist/reporters.js +3 -3
  25. package/dist/runners.d.ts +1 -2
  26. package/dist/runners.js +5 -6
  27. package/dist/{suite-0579b50d.d.ts → suite-ad69b7cd.d.ts} +1 -1
  28. package/dist/suite.d.ts +2 -3
  29. package/dist/suite.js +3 -3
  30. package/dist/{vendor-benchmark.44931cfa.js → vendor-benchmark.b6befc50.js} +1 -1
  31. package/dist/{vendor-execute.e6e4e89b.js → vendor-execute.157302d6.js} +2 -3
  32. package/dist/vendor-global.c3664e75.js +14 -0
  33. package/dist/{vendor-index.29282562.js → vendor-index.2b92937b.js} +1 -1
  34. package/dist/{vendor-index.3d079eea.js → vendor-index.57925a34.js} +2 -2
  35. package/dist/{vendor-index.68ecee35.js → vendor-index.72df742e.js} +11 -4
  36. package/dist/{vendor-node.327f8f1f.js → vendor-node.65461b16.js} +762 -98
  37. package/dist/{vendor-reporters.b9600369.js → vendor-reporters.d24d80a4.js} +2 -2
  38. package/dist/{vendor-rpc.cbd8e972.js → vendor-rpc.171f65fb.js} +1 -1
  39. package/dist/{vendor-run-once.3e5ef7d7.js → vendor-run-once.fb836747.js} +1 -1
  40. package/dist/{vendor-vi.d30b47ae.js → vendor-vi.3baa7c4a.js} +32 -35
  41. package/dist/vm.js +6 -5
  42. package/dist/worker.js +6 -5
  43. package/package.json +8 -8
  44. package/dist/vendor-global.97e4527c.js +0 -9
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import c from 'picocolors';
3
- import { b as isNode, c as relativePath } from './vendor-index.29282562.js';
3
+ import { b as isNode, c as relativePath } from './vendor-index.2b92937b.js';
4
4
  import { UNKNOWN_TEST_ID } from './chunk-runtime-console.f3263f87.js';
5
5
  import { isAbsolute, relative, dirname, basename, resolve } from 'pathe';
6
6
  import { s as slash } from './vendor-base.9c08bbd0.js';
@@ -2599,4 +2599,4 @@ const ReportersMap = {
2599
2599
  "hanging-process": HangingProcessReporter
2600
2600
  };
2601
2601
 
2602
- export { BenchmarkReportsMap as B, DefaultReporter as D, F_POINTER as F, HangingProcessReporter as H, JsonReporter$1 as J, ReportersMap as R, TapReporter as T, VerboseReporter as V, ansiStyles as a, stripAnsi as b, sliceAnsi as c, divider as d, cliTruncate as e, BasicReporter as f, DotReporter as g, JUnitReporter as h, TapFlatReporter as i, stringWidth as s };
2602
+ export { BenchmarkReportsMap as B, DefaultReporter as D, F_POINTER as F, HangingProcessReporter as H, JsonReporter$1 as J, ReportersMap as R, TapReporter as T, VerboseReporter as V, ansiStyles as a, BasicReporter as b, cliTruncate as c, divider as d, DotReporter as e, JUnitReporter as f, TapFlatReporter as g, stripAnsi as s };
@@ -1,5 +1,5 @@
1
1
  import { getSafeTimers } from '@vitest/utils';
2
- import { g as getWorkerState } from './vendor-global.97e4527c.js';
2
+ import { g as getWorkerState } from './vendor-global.c3664e75.js';
3
3
 
4
4
  const { get } = Reflect;
5
5
  function withSafeTimers(fn) {
@@ -1,4 +1,4 @@
1
- import { g as getWorkerState } from './vendor-global.97e4527c.js';
1
+ import { g as getWorkerState } from './vendor-global.c3664e75.js';
2
2
 
3
3
  const filesCount = /* @__PURE__ */ new Map();
4
4
  const cache = /* @__PURE__ */ new Map();
@@ -1,16 +1,16 @@
1
1
  import * as chai$1 from 'chai';
2
2
  import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './vendor-_commonjsHelpers.7d1333e8.js';
3
- import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, getState, setState } from '@vitest/expect';
3
+ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, ASYMMETRIC_MATCHERS_OBJECT as ASYMMETRIC_MATCHERS_OBJECT$1, getState, setState } from '@vitest/expect';
4
4
  import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
5
5
  import { getNames } from '@vitest/runner/utils';
6
6
  import '@vitest/utils/error';
7
7
  import { getCurrentTest } from '@vitest/runner';
8
8
  import { g as getFullName } from './vendor-tasks.f9d75aed.js';
9
- import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.97e4527c.js';
9
+ import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.c3664e75.js';
10
10
  import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
11
11
  import { parseSingleStack } from '@vitest/utils/source-map';
12
12
  import { R as RealDate, r as resetDate, m as mockDate } from './vendor-date.6e993429.js';
13
- import { spyOn, fn, isMockFunction, spies } from '@vitest/spy';
13
+ import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
14
14
 
15
15
  function resetModules(modules, resetMocks = false) {
16
16
  const skipPaths = [
@@ -144,10 +144,12 @@ var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
144
144
  const MATCHERS_OBJECT = Symbol.for("matchers-object");
145
145
  const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
146
146
  const GLOBAL_EXPECT = Symbol.for("expect-global");
147
+ const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
147
148
 
148
149
  if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
149
150
  const globalState = /* @__PURE__ */ new WeakMap();
150
151
  const matchers = /* @__PURE__ */ Object.create(null);
152
+ const assymetricMatchers = /* @__PURE__ */ Object.create(null);
151
153
  Object.defineProperty(globalThis, MATCHERS_OBJECT, {
152
154
  get: () => globalState
153
155
  });
@@ -158,6 +160,9 @@ if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
158
160
  matchers
159
161
  })
160
162
  });
163
+ Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
164
+ get: () => assymetricMatchers
165
+ });
161
166
  }
162
167
 
163
168
  function recordAsyncExpect(test, promise) {
@@ -185,21 +190,16 @@ function getSnapshotClient() {
185
190
  }
186
191
  return _client;
187
192
  }
188
- function getErrorMessage(err) {
189
- if (err instanceof Error)
190
- return err.message;
191
- return err;
192
- }
193
- function getErrorString(expected, promise) {
193
+ function getError(expected, promise) {
194
194
  if (typeof expected !== "function") {
195
195
  if (!promise)
196
196
  throw new Error(`expected must be a function, received ${typeof expected}`);
197
- return getErrorMessage(expected);
197
+ return expected;
198
198
  }
199
199
  try {
200
200
  expected();
201
201
  } catch (e) {
202
- return getErrorMessage(e);
202
+ return e;
203
203
  }
204
204
  throw new Error("snapshot function didn't throw");
205
205
  }
@@ -296,7 +296,7 @@ const SnapshotPlugin = (chai, utils) => {
296
296
  const promise = utils.flag(this, "promise");
297
297
  const errorMessage = utils.flag(this, "message");
298
298
  getSnapshotClient().assert({
299
- received: getErrorString(expected, promise),
299
+ received: getError(expected, promise),
300
300
  message,
301
301
  errorMessage,
302
302
  ...getTestNames(test)
@@ -317,7 +317,7 @@ const SnapshotPlugin = (chai, utils) => {
317
317
  const promise = utils.flag(this, "promise");
318
318
  const errorMessage = utils.flag(this, "message");
319
319
  getSnapshotClient().assert({
320
- received: getErrorString(expected, promise),
320
+ received: getError(expected, promise),
321
321
  message,
322
322
  inlineSnapshot,
323
323
  isInline: true,
@@ -353,6 +353,7 @@ function createExpect(test) {
353
353
  return assert2;
354
354
  };
355
355
  Object.assign(expect, chai$1.expect);
356
+ Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT$1]);
356
357
  expect.getState = () => getState(expect);
357
358
  expect.setState = (state) => setState(state, expect);
358
359
  const globalState = getState(globalThis[GLOBAL_EXPECT$1]) || {};
@@ -3297,10 +3298,6 @@ function createVitest() {
3297
3298
  let _mockedDate = null;
3298
3299
  let _config = null;
3299
3300
  const workerState = getWorkerState();
3300
- if (!workerState) {
3301
- 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';
3302
- throw new Error(errorMsg);
3303
- }
3304
3301
  const _timers = new FakeTimers({
3305
3302
  global: globalThis,
3306
3303
  config: workerState.config.fakeTimers
@@ -3316,18 +3313,17 @@ function createVitest() {
3316
3313
  const utils = {
3317
3314
  useFakeTimers(config) {
3318
3315
  var _a, _b, _c, _d;
3319
- const workerState2 = getWorkerState();
3320
- if (workerState2.isChildProcess) {
3321
- if (((_a = config == null ? void 0 : config.toFake) == null ? void 0 : _a.includes("nextTick")) || ((_d = (_c = (_b = workerState2.config) == null ? void 0 : _b.fakeTimers) == null ? void 0 : _c.toFake) == null ? void 0 : _d.includes("nextTick"))) {
3316
+ if (workerState.isChildProcess) {
3317
+ if (((_a = config == null ? void 0 : config.toFake) == null ? void 0 : _a.includes("nextTick")) || ((_d = (_c = (_b = workerState.config) == null ? void 0 : _b.fakeTimers) == null ? void 0 : _c.toFake) == null ? void 0 : _d.includes("nextTick"))) {
3322
3318
  throw new Error(
3323
3319
  'vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.'
3324
3320
  );
3325
3321
  }
3326
3322
  }
3327
3323
  if (config)
3328
- _timers.configure({ ...workerState2.config.fakeTimers, ...config });
3324
+ _timers.configure({ ...workerState.config.fakeTimers, ...config });
3329
3325
  else
3330
- _timers.configure(workerState2.config.fakeTimers);
3326
+ _timers.configure(workerState.config.fakeTimers);
3331
3327
  _timers.useFakeTimers();
3332
3328
  return utils;
3333
3329
  },
@@ -3415,7 +3411,12 @@ function createVitest() {
3415
3411
  _mocker.queueUnmock(path, getImporter());
3416
3412
  },
3417
3413
  doMock(path, factory) {
3418
- _mocker.queueMock(path, getImporter(), factory);
3414
+ const importer = getImporter();
3415
+ _mocker.queueMock(
3416
+ path,
3417
+ importer,
3418
+ factory ? () => factory(() => _mocker.importActual(path, importer)) : void 0
3419
+ );
3419
3420
  },
3420
3421
  doUnmock(path) {
3421
3422
  _mocker.queueUnmock(path, getImporter());
@@ -3433,15 +3434,15 @@ function createVitest() {
3433
3434
  return isMockFunction(fn2);
3434
3435
  },
3435
3436
  clearAllMocks() {
3436
- spies.forEach((spy) => spy.mockClear());
3437
+ mocks.forEach((spy) => spy.mockClear());
3437
3438
  return utils;
3438
3439
  },
3439
3440
  resetAllMocks() {
3440
- spies.forEach((spy) => spy.mockReset());
3441
+ mocks.forEach((spy) => spy.mockReset());
3441
3442
  return utils;
3442
3443
  },
3443
3444
  restoreAllMocks() {
3444
- spies.forEach((spy) => spy.mockRestore());
3445
+ mocks.forEach((spy) => spy.mockRestore());
3445
3446
  return utils;
3446
3447
  },
3447
3448
  stubGlobal(name, value) {
@@ -3482,24 +3483,20 @@ function createVitest() {
3482
3483
  return utils;
3483
3484
  },
3484
3485
  resetModules() {
3485
- const state = getWorkerState();
3486
- resetModules(state.moduleCache);
3486
+ resetModules(workerState.moduleCache);
3487
3487
  return utils;
3488
3488
  },
3489
3489
  async dynamicImportSettled() {
3490
3490
  return waitForImportsToResolve();
3491
3491
  },
3492
3492
  setConfig(config) {
3493
- const state = getWorkerState();
3494
3493
  if (!_config)
3495
- _config = { ...state.config };
3496
- Object.assign(state.config, config);
3494
+ _config = { ...workerState.config };
3495
+ Object.assign(workerState.config, config);
3497
3496
  },
3498
3497
  resetConfig() {
3499
- if (_config) {
3500
- const state = getWorkerState();
3501
- Object.assign(state.config, _config);
3502
- }
3498
+ if (_config)
3499
+ Object.assign(workerState.config, _config);
3503
3500
  }
3504
3501
  };
3505
3502
  return utils;
package/dist/vm.js CHANGED
@@ -8,9 +8,9 @@ import { resolve } from 'pathe';
8
8
  import { installSourcemapsSupport } from 'vite-node/source-map';
9
9
  import { d as distDir } from './vendor-paths.84fc7a99.js';
10
10
  import { l as loadEnvironment } from './vendor-loader.9c966f23.js';
11
- import { b as startVitestExecutor } from './vendor-execute.e6e4e89b.js';
11
+ import { b as startVitestExecutor } from './vendor-execute.157302d6.js';
12
12
  import { createCustomConsole } from './chunk-runtime-console.f3263f87.js';
13
- import { c as createSafeRpc } from './vendor-rpc.cbd8e972.js';
13
+ import { c as createSafeRpc } from './vendor-rpc.171f65fb.js';
14
14
  import 'acorn';
15
15
  import 'node:module';
16
16
  import 'node:fs';
@@ -24,19 +24,19 @@ import 'node:console';
24
24
  import 'local-pkg';
25
25
  import 'vite-node/utils';
26
26
  import '@vitest/utils/error';
27
- import './vendor-global.97e4527c.js';
28
27
  import '@vitest/utils';
29
28
  import './vendor-base.9c08bbd0.js';
30
29
  import 'vite-node/constants';
31
30
  import 'node:stream';
32
31
  import './vendor-date.6e993429.js';
32
+ import './vendor-global.c3664e75.js';
33
33
 
34
34
  const entryFile = pathToFileURL(resolve(distDir, "entry-vm.js")).href;
35
35
  async function run(ctx) {
36
36
  var _a;
37
37
  const moduleCache = new ModuleCacheMap();
38
38
  const mockMap = /* @__PURE__ */ new Map();
39
- const { config, port } = ctx;
39
+ const { config, port, providedContext } = ctx;
40
40
  let setCancel = (_reason) => {
41
41
  };
42
42
  const onCancel = new Promise((resolve2) => {
@@ -79,7 +79,8 @@ async function run(ctx) {
79
79
  environment: performance.now(),
80
80
  prepare: performance.now()
81
81
  },
82
- rpc
82
+ rpc,
83
+ providedContext
83
84
  };
84
85
  installSourcemapsSupport({
85
86
  getSourceMap: (source) => moduleCache.getSourceMap(source)
package/dist/worker.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { c as createBirpc } from './vendor-index.1ca68bd5.js';
3
3
  import { workerId } from 'tinypool';
4
- import { g as getWorkerState } from './vendor-global.97e4527c.js';
4
+ import { g as getWorkerState } from './vendor-global.c3664e75.js';
5
5
  import { l as loadEnvironment } from './vendor-loader.9c966f23.js';
6
- import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.e6e4e89b.js';
6
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.157302d6.js';
7
7
  import { s as setupInspect } from './vendor-inspector.209edf5a.js';
8
- import { r as rpcDone, c as createSafeRpc } from './vendor-rpc.cbd8e972.js';
8
+ import { r as rpcDone, c as createSafeRpc } from './vendor-rpc.171f65fb.js';
9
9
  import 'pathe';
10
10
  import 'acorn';
11
11
  import 'node:module';
@@ -34,7 +34,7 @@ async function init(ctx) {
34
34
  const isIsolatedThreads = ctx.config.pool === "threads" && (((_b = (_a = ctx.config.poolOptions) == null ? void 0 : _a.threads) == null ? void 0 : _b.isolate) ?? true);
35
35
  if (isInitialized && isIsolatedThreads)
36
36
  throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${getWorkerState().ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
37
- const { config, port, workerId: workerId$1 } = ctx;
37
+ const { config, port, workerId: workerId$1, providedContext } = ctx;
38
38
  process.env.VITEST_WORKER_ID = String(workerId$1);
39
39
  process.env.VITEST_POOL_ID = String(workerId);
40
40
  let setCancel = (_reason) => {
@@ -74,7 +74,8 @@ async function init(ctx) {
74
74
  environment: 0,
75
75
  prepare: performance.now()
76
76
  },
77
- rpc
77
+ rpc,
78
+ providedContext
78
79
  };
79
80
  Object.defineProperty(globalThis, "__vitest_worker__", {
80
81
  value: state,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.3",
4
+ "version": "1.0.0-beta.4",
5
5
  "description": "Next generation testing framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -144,12 +144,12 @@
144
144
  "tinypool": "^0.8.1",
145
145
  "vite": "^3.1.0 || ^4.0.0 || ^5.0.0-0",
146
146
  "why-is-node-running": "^2.2.2",
147
- "@vitest/expect": "1.0.0-beta.3",
148
- "@vitest/runner": "1.0.0-beta.3",
149
- "@vitest/snapshot": "1.0.0-beta.3",
150
- "@vitest/spy": "1.0.0-beta.3",
151
- "@vitest/utils": "1.0.0-beta.3",
152
- "vite-node": "1.0.0-beta.3"
147
+ "@vitest/spy": "1.0.0-beta.4",
148
+ "@vitest/expect": "1.0.0-beta.4",
149
+ "@vitest/runner": "1.0.0-beta.4",
150
+ "@vitest/snapshot": "1.0.0-beta.4",
151
+ "@vitest/utils": "1.0.0-beta.4",
152
+ "vite-node": "1.0.0-beta.4"
153
153
  },
154
154
  "devDependencies": {
155
155
  "@ampproject/remapping": "^2.2.1",
@@ -175,7 +175,7 @@
175
175
  "get-tsconfig": "^4.6.2",
176
176
  "happy-dom": "^9.20.3",
177
177
  "jsdom": "^22.1.0",
178
- "log-update": "^5.0.1",
178
+ "log-update": "^6.0.0",
179
179
  "micromatch": "^4.0.5",
180
180
  "mlly": "^1.4.0",
181
181
  "p-limit": "^4.0.0",
@@ -1,9 +0,0 @@
1
- function getWorkerState() {
2
- return globalThis.__vitest_worker__;
3
- }
4
- function getCurrentEnvironment() {
5
- const state = getWorkerState();
6
- return state == null ? void 0 : state.environment.name;
7
- }
8
-
9
- export { getCurrentEnvironment as a, getWorkerState as g };