vitest 0.31.4 → 0.32.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.
@@ -2,12 +2,12 @@ import { pathToFileURL } from 'node:url';
2
2
  import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client';
3
3
  import { isNodeBuiltin, isInternalRequest, isPrimitive } from 'vite-node/utils';
4
4
  import { isAbsolute, dirname, join, basename, extname, resolve, normalize, relative } from 'pathe';
5
- import { processError } from '@vitest/runner/utils';
5
+ import { processError } from '@vitest/utils/error';
6
6
  import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.6795f91f.js';
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.5037f2c0.js';
10
+ import { e as getAllMockableProperties } from './vendor-index.87ab04c3.js';
11
11
  import { spyOn } from '@vitest/spy';
12
12
  import { r as rpc } from './vendor-rpc.4d3d7a54.js';
13
13
 
@@ -71,7 +71,19 @@ const _VitestMocker = class {
71
71
  };
72
72
  }
73
73
  async resolvePath(rawId, importer) {
74
- const [id, fsPath] = await this.executor.resolveUrl(rawId, importer);
74
+ let id;
75
+ let fsPath;
76
+ try {
77
+ [id, fsPath] = await this.executor.originalResolveUrl(rawId, importer);
78
+ } catch (error) {
79
+ if (error.code === "ERR_MODULE_NOT_FOUND") {
80
+ const { id: unresolvedId } = error[Symbol.for("vitest.error.not_found.data")];
81
+ id = unresolvedId;
82
+ fsPath = unresolvedId;
83
+ } else {
84
+ throw error;
85
+ }
86
+ }
75
87
  const external = !isAbsolute(fsPath) || this.isAModuleDirectory(fsPath) ? rawId : null;
76
88
  return {
77
89
  id,
@@ -80,6 +92,8 @@ const _VitestMocker = class {
80
92
  };
81
93
  }
82
94
  async resolveMocks() {
95
+ if (!_VitestMocker.pendingIds.length)
96
+ return;
83
97
  await Promise.all(_VitestMocker.pendingIds.map(async (mock) => {
84
98
  const { fsPath, external } = await this.resolvePath(mock.id, mock.importer);
85
99
  if (mock.type === "unmock")
@@ -214,7 +228,7 @@ ${c.green(`vi.mock("${mockpath}", async () => {
214
228
  const mock = spyOn(newContainer, property).mockImplementation(() => void 0);
215
229
  mock.mockRestore = () => {
216
230
  mock.mockReset();
217
- mock.mockImplementation(void 0);
231
+ mock.mockImplementation(() => void 0);
218
232
  return mock;
219
233
  };
220
234
  Object.defineProperty(newContainer[property], "length", { value: 0 });
@@ -268,8 +282,6 @@ ${c.green(`vi.mock("${mockpath}", async () => {
268
282
  return this.executor.dependencyRequest(mock, mock, [importee]);
269
283
  }
270
284
  async requestWithMock(url, callstack) {
271
- if (_VitestMocker.pendingIds.length)
272
- await this.resolveMocks();
273
285
  const id = this.normalizePath(url);
274
286
  const mock = this.getDependencyMock(id);
275
287
  const mockPath = this.getMockPath(id);
@@ -365,15 +377,31 @@ class VitestExecutor extends ViteNodeRunner {
365
377
  });
366
378
  }
367
379
  shouldResolveId(id, _importee) {
368
- if (isInternalRequest(id))
380
+ if (isInternalRequest(id) || id.startsWith("data:"))
369
381
  return false;
370
382
  const environment = getCurrentEnvironment();
371
383
  return environment === "node" ? !isNodeBuiltin(id) : !id.startsWith("node:");
372
384
  }
385
+ async originalResolveUrl(id, importer) {
386
+ return super.resolveUrl(id, importer);
387
+ }
373
388
  async resolveUrl(id, importer) {
389
+ if (VitestMocker.pendingIds.length)
390
+ await this.mocker.resolveMocks();
374
391
  if (importer && importer.startsWith("mock:"))
375
392
  importer = importer.slice(5);
376
- return super.resolveUrl(id, importer);
393
+ try {
394
+ return await super.resolveUrl(id, importer);
395
+ } catch (error) {
396
+ if (error.code === "ERR_MODULE_NOT_FOUND") {
397
+ const { id: id2 } = error[Symbol.for("vitest.error.not_found.data")];
398
+ const path = this.mocker.normalizePath(id2);
399
+ const mock = this.mocker.getDependencyMock(path);
400
+ if (mock !== void 0)
401
+ return [id2, id2];
402
+ }
403
+ throw error;
404
+ }
377
405
  }
378
406
  async dependencyRequest(id, fsPath, callstack) {
379
407
  const mocked = await this.mocker.requestWithMock(fsPath, callstack);
@@ -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.23b98fa1.js';
2
+ import { e as bench, c as createExpect, d as globalExpect, s as setupChaiConfig, v as vi, f as vitest } from './vendor-vi.74cf3ef7.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';
@@ -82,8 +82,8 @@ function stdout() {
82
82
  return console._stdout || process.stdout;
83
83
  }
84
84
  function getEnvironmentTransformMode(config, environment) {
85
- var _a, _b;
86
- if (!((_b = (_a = config.deps) == null ? void 0 : _a.experimentalOptimizer) == null ? void 0 : _b.enabled))
85
+ var _a, _b, _c, _d, _e, _f;
86
+ if (!((_c = (_b = (_a = config.deps) == null ? void 0 : _a.experimentalOptimizer) == null ? void 0 : _b.ssr) == null ? void 0 : _c.enabled) && !((_f = (_e = (_d = config.deps) == null ? void 0 : _d.experimentalOptimizer) == null ? void 0 : _e.web) == null ? void 0 : _f.enabled))
87
87
  return void 0;
88
88
  return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
89
89
  }
@@ -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.6a234998.js')).registerApiGlobally();
13
+ (await import('./chunk-integrations-globals.a56dee90.js')).registerApiGlobally();
14
14
  }
15
15
  function setupDefines(defines) {
16
16
  for (const key in defines)
@@ -4,8 +4,9 @@ import { getSafeTimers, noop, assertTypes, createSimpleStackTrace, parseSingleSt
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';
7
- import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, getState, setState } from '@vitest/expect';
7
+ import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, getState, setState } from '@vitest/expect';
8
8
  import { SnapshotClient, stripSnapshotIndentation, addSerializer } from '@vitest/snapshot';
9
+ import '@vitest/utils/error';
9
10
  import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.6795f91f.js';
10
11
  import { g as getFullName } from './vendor-tasks.f9d75aed.js';
11
12
  import require$$0 from 'util';
@@ -151,6 +152,25 @@ var chaiSubset = {exports: {}};
151
152
 
152
153
  var Subset = chaiSubset.exports;
153
154
 
155
+ const MATCHERS_OBJECT = Symbol.for("matchers-object");
156
+ const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
157
+ const GLOBAL_EXPECT = Symbol.for("expect-global");
158
+
159
+ if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
160
+ const globalState = /* @__PURE__ */ new WeakMap();
161
+ const matchers = /* @__PURE__ */ Object.create(null);
162
+ Object.defineProperty(globalThis, MATCHERS_OBJECT, {
163
+ get: () => globalState
164
+ });
165
+ Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
166
+ configurable: true,
167
+ get: () => ({
168
+ state: globalState.get(globalThis[GLOBAL_EXPECT]),
169
+ matchers
170
+ })
171
+ });
172
+ }
173
+
154
174
  function recordAsyncExpect(test, promise) {
155
175
  if (test && promise instanceof Promise) {
156
176
  promise = promise.finally(() => {
@@ -336,7 +356,7 @@ function createExpect(test) {
336
356
  var _a;
337
357
  const expect = (value, message) => {
338
358
  const { assertionCalls } = getState(expect);
339
- setState({ assertionCalls: assertionCalls + 1 }, expect);
359
+ setState({ assertionCalls: assertionCalls + 1, soft: false }, expect);
340
360
  const assert2 = chai$1.expect(value, message);
341
361
  const _test = test || getCurrentTest();
342
362
  if (_test)
@@ -347,7 +367,7 @@ function createExpect(test) {
347
367
  Object.assign(expect, chai$1.expect);
348
368
  expect.getState = () => getState(expect);
349
369
  expect.setState = (state) => setState(state, expect);
350
- const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
370
+ const globalState = getState(globalThis[GLOBAL_EXPECT$1]) || {};
351
371
  setState({
352
372
  // this should also add "snapshotState" that is added conditionally
353
373
  ...globalState,
@@ -361,6 +381,16 @@ function createExpect(test) {
361
381
  currentTestName: test ? getFullName(test) : globalState.currentTestName
362
382
  }, expect);
363
383
  expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
384
+ expect.soft = (...args) => {
385
+ const assert2 = expect(...args);
386
+ expect.setState({
387
+ soft: true
388
+ });
389
+ return assert2;
390
+ };
391
+ expect.unreachable = (message) => {
392
+ chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
393
+ };
364
394
  function assertions(expected) {
365
395
  const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
366
396
  if (Error.captureStackTrace)
@@ -384,7 +414,7 @@ function createExpect(test) {
384
414
  return expect;
385
415
  }
386
416
  const globalExpect = createExpect();
387
- Object.defineProperty(globalThis, GLOBAL_EXPECT, {
417
+ Object.defineProperty(globalThis, GLOBAL_EXPECT$1, {
388
418
  value: globalExpect,
389
419
  writable: true,
390
420
  configurable: true
package/dist/worker.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { performance } from 'node:perf_hooks';
2
- import { c as createBirpc } from './vendor-index.5037f2c0.js';
2
+ import { c as createBirpc } from './vendor-index.87ab04c3.js';
3
3
  import { workerId } from 'tinypool';
4
4
  import { g as getWorkerState } from './vendor-global.6795f91f.js';
5
- import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.132a3e09.js';
5
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.001ae440.js';
6
6
  import { s as setupInspect } from './vendor-inspector.47fc8cbb.js';
7
7
  import { a as rpcDone } from './vendor-rpc.4d3d7a54.js';
8
8
  import '@vitest/utils';
@@ -10,7 +10,7 @@ import 'node:url';
10
10
  import 'vite-node/client';
11
11
  import 'vite-node/utils';
12
12
  import 'pathe';
13
- import '@vitest/runner/utils';
13
+ import '@vitest/utils/error';
14
14
  import './vendor-paths.84fc7a99.js';
15
15
  import 'node:fs';
16
16
  import '@vitest/spy';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.31.4",
4
+ "version": "0.32.1",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -148,17 +148,17 @@
148
148
  "tinypool": "^0.5.0",
149
149
  "vite": "^3.0.0 || ^4.0.0",
150
150
  "why-is-node-running": "^2.2.2",
151
- "@vitest/runner": "0.31.4",
152
- "@vitest/expect": "0.31.4",
153
- "@vitest/snapshot": "0.31.4",
154
- "@vitest/spy": "0.31.4",
155
- "vite-node": "0.31.4",
156
- "@vitest/utils": "0.31.4"
151
+ "@vitest/expect": "0.32.1",
152
+ "@vitest/snapshot": "0.32.1",
153
+ "@vitest/runner": "0.32.1",
154
+ "vite-node": "0.32.1",
155
+ "@vitest/spy": "0.32.1",
156
+ "@vitest/utils": "0.32.1"
157
157
  },
158
158
  "devDependencies": {
159
159
  "@ampproject/remapping": "^2.2.1",
160
160
  "@antfu/install-pkg": "^0.1.1",
161
- "@edge-runtime/vm": "2.1.2",
161
+ "@edge-runtime/vm": "3.0.1",
162
162
  "@jridgewell/trace-mapping": "^0.3.18",
163
163
  "@sinonjs/fake-timers": "^10.0.2",
164
164
  "@types/diff": "^5.0.3",
@@ -180,7 +180,7 @@
180
180
  "flatted": "^3.2.7",
181
181
  "get-tsconfig": "^4.5.0",
182
182
  "happy-dom": "^9.10.7",
183
- "jsdom": "^21.1.2",
183
+ "jsdom": "^22.1.0",
184
184
  "log-update": "^5.0.1",
185
185
  "micromatch": "^4.0.5",
186
186
  "mlly": "^1.2.0",