vitest 0.34.3 → 0.34.5

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 (35) hide show
  1. package/dist/browser.d.ts +28 -2
  2. package/dist/browser.js +11 -2
  3. package/dist/child.js +13 -8
  4. package/dist/{chunk-api-setup.3b016b1c.js → chunk-api-setup.d65b007d.js} +3 -3
  5. package/dist/{chunk-install-pkg.a036014e.js → chunk-install-pkg.e623b1bf.js} +3 -3
  6. package/dist/{chunk-integrations-globals.7f4b17bf.js → chunk-integrations-globals.5afac659.js} +2 -2
  7. package/dist/{chunk-node-git.c410fed8.js → chunk-node-git.36288174.js} +1 -1
  8. package/dist/cli-wrapper.js +1 -1
  9. package/dist/cli.js +4 -4
  10. package/dist/config.d.ts +1 -1
  11. package/dist/coverage.d.ts +1 -1
  12. package/dist/entry-vm.js +3 -3
  13. package/dist/entry.js +6 -3
  14. package/dist/environments.d.ts +1 -1
  15. package/dist/environments.js +3 -2
  16. package/dist/execute.d.ts +1 -1
  17. package/dist/execute.js +1 -1
  18. package/dist/index.d.ts +25 -2
  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-2ff87305.d.ts → reporters-5f784f42.d.ts} +23 -18
  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/{vendor-environments.8eb4d407.js → vendor-environments.b9b2f624.js} +26 -5
  27. package/dist/{vendor-execute.a63e187f.js → vendor-execute.07d1a420.js} +10 -3
  28. package/dist/{vendor-index.9378c9a4.js → vendor-index.3e351f42.js} +2 -0
  29. package/dist/{vendor-index.7178e7a2.js → vendor-index.7646b3af.js} +1 -1
  30. package/dist/{vendor-index.1f85e5f1.js → vendor-index.85fc950a.js} +2 -2
  31. package/dist/{vendor-node.5ce5f335.js → vendor-node.81dd929c.js} +123 -96
  32. package/dist/{vendor-vi.597d9e06.js → vendor-vi.6873a1c1.js} +149 -22
  33. package/dist/vm.js +11 -6
  34. package/dist/worker.js +13 -8
  35. package/package.json +8 -8
@@ -3168,6 +3168,9 @@ class FakeTimers {
3168
3168
  configure(config) {
3169
3169
  this._userConfig = config;
3170
3170
  }
3171
+ isFakeTimers() {
3172
+ return this._fakingTime;
3173
+ }
3171
3174
  _checkFakeTimers() {
3172
3175
  if (!this._fakingTime) {
3173
3176
  throw new Error(
@@ -3178,6 +3181,124 @@ class FakeTimers {
3178
3181
  }
3179
3182
  }
3180
3183
 
3184
+ function copyStackTrace(target, source) {
3185
+ if (source.stack !== void 0)
3186
+ target.stack = source.stack.replace(source.message, target.message);
3187
+ return target;
3188
+ }
3189
+ function waitFor(callback, options = {}) {
3190
+ const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
3191
+ const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
3192
+ const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
3193
+ return new Promise((resolve, reject) => {
3194
+ let lastError;
3195
+ let promiseStatus = "idle";
3196
+ let timeoutId;
3197
+ let intervalId;
3198
+ const onResolve = (result) => {
3199
+ if (timeoutId)
3200
+ clearTimeout(timeoutId);
3201
+ if (intervalId)
3202
+ clearInterval(intervalId);
3203
+ resolve(result);
3204
+ };
3205
+ const handleTimeout = () => {
3206
+ let error = lastError;
3207
+ if (!error)
3208
+ error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
3209
+ reject(error);
3210
+ };
3211
+ const checkCallback = () => {
3212
+ if (vi.isFakeTimers())
3213
+ vi.advanceTimersByTime(interval);
3214
+ if (promiseStatus === "pending")
3215
+ return;
3216
+ try {
3217
+ const result = callback();
3218
+ if (result !== null && typeof result === "object" && typeof result.then === "function") {
3219
+ const thenable = result;
3220
+ promiseStatus = "pending";
3221
+ thenable.then(
3222
+ (resolvedValue) => {
3223
+ promiseStatus = "resolved";
3224
+ onResolve(resolvedValue);
3225
+ },
3226
+ (rejectedValue) => {
3227
+ promiseStatus = "rejected";
3228
+ lastError = rejectedValue;
3229
+ }
3230
+ );
3231
+ } else {
3232
+ onResolve(result);
3233
+ return true;
3234
+ }
3235
+ } catch (error) {
3236
+ lastError = error;
3237
+ }
3238
+ };
3239
+ if (checkCallback() === true)
3240
+ return;
3241
+ timeoutId = setTimeout(handleTimeout, timeout);
3242
+ intervalId = setInterval(checkCallback, interval);
3243
+ });
3244
+ }
3245
+ function waitUntil(callback, options = {}) {
3246
+ const { setTimeout, setInterval, clearTimeout, clearInterval } = getSafeTimers();
3247
+ const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
3248
+ const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
3249
+ return new Promise((resolve, reject) => {
3250
+ let promiseStatus = "idle";
3251
+ let timeoutId;
3252
+ let intervalId;
3253
+ const onReject = (error) => {
3254
+ if (!error)
3255
+ error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
3256
+ reject(error);
3257
+ };
3258
+ const onResolve = (result) => {
3259
+ if (!result)
3260
+ return;
3261
+ if (timeoutId)
3262
+ clearTimeout(timeoutId);
3263
+ if (intervalId)
3264
+ clearInterval(intervalId);
3265
+ resolve(result);
3266
+ return true;
3267
+ };
3268
+ const checkCallback = () => {
3269
+ if (vi.isFakeTimers())
3270
+ vi.advanceTimersByTime(interval);
3271
+ if (promiseStatus === "pending")
3272
+ return;
3273
+ try {
3274
+ const result = callback();
3275
+ if (result !== null && typeof result === "object" && typeof result.then === "function") {
3276
+ const thenable = result;
3277
+ promiseStatus = "pending";
3278
+ thenable.then(
3279
+ (resolvedValue) => {
3280
+ promiseStatus = "resolved";
3281
+ onResolve(resolvedValue);
3282
+ },
3283
+ (rejectedValue) => {
3284
+ promiseStatus = "rejected";
3285
+ onReject(rejectedValue);
3286
+ }
3287
+ );
3288
+ } else {
3289
+ return onResolve(result);
3290
+ }
3291
+ } catch (error) {
3292
+ onReject(error);
3293
+ }
3294
+ };
3295
+ if (checkCallback() === true)
3296
+ return;
3297
+ timeoutId = setTimeout(onReject, timeout);
3298
+ intervalId = setInterval(checkCallback, interval);
3299
+ });
3300
+ }
3301
+
3181
3302
  function createVitest() {
3182
3303
  const _mocker = typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy({}, {
3183
3304
  get(_, name) {
@@ -3205,7 +3326,7 @@ function createVitest() {
3205
3326
  const stack = parseSingleStack(importerStack);
3206
3327
  return (stack == null ? void 0 : stack.file) || "";
3207
3328
  };
3208
- return {
3329
+ const utils = {
3209
3330
  useFakeTimers(config) {
3210
3331
  if (config) {
3211
3332
  _timers.configure(config);
@@ -3214,48 +3335,51 @@ function createVitest() {
3214
3335
  _timers.configure(workerState2.config.fakeTimers);
3215
3336
  }
3216
3337
  _timers.useFakeTimers();
3217
- return this;
3338
+ return utils;
3339
+ },
3340
+ isFakeTimers() {
3341
+ return _timers.isFakeTimers();
3218
3342
  },
3219
3343
  useRealTimers() {
3220
3344
  _timers.useRealTimers();
3221
3345
  _mockedDate = null;
3222
- return this;
3346
+ return utils;
3223
3347
  },
3224
3348
  runOnlyPendingTimers() {
3225
3349
  _timers.runOnlyPendingTimers();
3226
- return this;
3350
+ return utils;
3227
3351
  },
3228
3352
  async runOnlyPendingTimersAsync() {
3229
3353
  await _timers.runOnlyPendingTimersAsync();
3230
- return this;
3354
+ return utils;
3231
3355
  },
3232
3356
  runAllTimers() {
3233
3357
  _timers.runAllTimers();
3234
- return this;
3358
+ return utils;
3235
3359
  },
3236
3360
  async runAllTimersAsync() {
3237
3361
  await _timers.runAllTimersAsync();
3238
- return this;
3362
+ return utils;
3239
3363
  },
3240
3364
  runAllTicks() {
3241
3365
  _timers.runAllTicks();
3242
- return this;
3366
+ return utils;
3243
3367
  },
3244
3368
  advanceTimersByTime(ms) {
3245
3369
  _timers.advanceTimersByTime(ms);
3246
- return this;
3370
+ return utils;
3247
3371
  },
3248
3372
  async advanceTimersByTimeAsync(ms) {
3249
3373
  await _timers.advanceTimersByTimeAsync(ms);
3250
- return this;
3374
+ return utils;
3251
3375
  },
3252
3376
  advanceTimersToNextTimer() {
3253
3377
  _timers.advanceTimersToNextTimer();
3254
- return this;
3378
+ return utils;
3255
3379
  },
3256
3380
  async advanceTimersToNextTimerAsync() {
3257
3381
  await _timers.advanceTimersToNextTimerAsync();
3258
- return this;
3382
+ return utils;
3259
3383
  },
3260
3384
  getTimerCount() {
3261
3385
  return _timers.getTimerCount();
@@ -3264,7 +3388,7 @@ function createVitest() {
3264
3388
  const date = time instanceof Date ? time : new Date(time);
3265
3389
  _mockedDate = date;
3266
3390
  _timers.setSystemTime(date);
3267
- return this;
3391
+ return utils;
3268
3392
  },
3269
3393
  getMockedSystemTime() {
3270
3394
  return _mockedDate;
@@ -3274,11 +3398,13 @@ function createVitest() {
3274
3398
  },
3275
3399
  clearAllTimers() {
3276
3400
  _timers.clearAllTimers();
3277
- return this;
3401
+ return utils;
3278
3402
  },
3279
3403
  // mocks
3280
3404
  spyOn,
3281
3405
  fn,
3406
+ waitFor,
3407
+ waitUntil,
3282
3408
  hoisted(factory) {
3283
3409
  assertTypes(factory, '"vi.hoisted" factory', ["function"]);
3284
3410
  return factory();
@@ -3314,15 +3440,15 @@ function createVitest() {
3314
3440
  },
3315
3441
  clearAllMocks() {
3316
3442
  spies.forEach((spy) => spy.mockClear());
3317
- return this;
3443
+ return utils;
3318
3444
  },
3319
3445
  resetAllMocks() {
3320
3446
  spies.forEach((spy) => spy.mockReset());
3321
- return this;
3447
+ return utils;
3322
3448
  },
3323
3449
  restoreAllMocks() {
3324
3450
  spies.forEach((spy) => spy.mockRestore());
3325
- return this;
3451
+ return utils;
3326
3452
  },
3327
3453
  stubGlobal(name, value) {
3328
3454
  if (!_stubsGlobal.has(name))
@@ -3333,13 +3459,13 @@ function createVitest() {
3333
3459
  configurable: true,
3334
3460
  enumerable: true
3335
3461
  });
3336
- return this;
3462
+ return utils;
3337
3463
  },
3338
3464
  stubEnv(name, value) {
3339
3465
  if (!_stubsEnv.has(name))
3340
3466
  _stubsEnv.set(name, process.env[name]);
3341
3467
  process.env[name] = value;
3342
- return this;
3468
+ return utils;
3343
3469
  },
3344
3470
  unstubAllGlobals() {
3345
3471
  _stubsGlobal.forEach((original, name) => {
@@ -3349,7 +3475,7 @@ function createVitest() {
3349
3475
  Object.defineProperty(globalThis, name, original);
3350
3476
  });
3351
3477
  _stubsGlobal.clear();
3352
- return this;
3478
+ return utils;
3353
3479
  },
3354
3480
  unstubAllEnvs() {
3355
3481
  _stubsEnv.forEach((original, name) => {
@@ -3359,12 +3485,12 @@ function createVitest() {
3359
3485
  process.env[name] = original;
3360
3486
  });
3361
3487
  _stubsEnv.clear();
3362
- return this;
3488
+ return utils;
3363
3489
  },
3364
3490
  resetModules() {
3365
3491
  const state = getWorkerState();
3366
3492
  resetModules(state.moduleCache);
3367
- return this;
3493
+ return utils;
3368
3494
  },
3369
3495
  async dynamicImportSettled() {
3370
3496
  return waitForImportsToResolve();
@@ -3382,6 +3508,7 @@ function createVitest() {
3382
3508
  }
3383
3509
  }
3384
3510
  };
3511
+ return utils;
3385
3512
  }
3386
3513
  const vitest = createVitest();
3387
3514
  const vi = vitest;
package/dist/vm.js CHANGED
@@ -7,8 +7,8 @@ import { c as createBirpc } from './vendor-index.b271ebe4.js';
7
7
  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
- import { l as loadEnvironment } from './vendor-environments.8eb4d407.js';
11
- import { b as startVitestExecutor } from './vendor-execute.a63e187f.js';
10
+ import { l as loadEnvironment } from './vendor-environments.b9b2f624.js';
11
+ import { b as startVitestExecutor } from './vendor-execute.07d1a420.js';
12
12
  import { createCustomConsole } from './chunk-runtime-console.ea222ffb.js';
13
13
  import { c as createSafeRpc } from './vendor-rpc.cbd8e972.js';
14
14
  import './vendor-index.0b5b3600.js';
@@ -42,7 +42,7 @@ async function run(ctx) {
42
42
  const onCancel = new Promise((resolve2) => {
43
43
  setCancel = resolve2;
44
44
  });
45
- const rpc = createBirpc(
45
+ const rpc = createSafeRpc(createBirpc(
46
46
  {
47
47
  onCancel: setCancel
48
48
  },
@@ -55,8 +55,13 @@ async function run(ctx) {
55
55
  port.addListener("message", fn);
56
56
  }
57
57
  }
58
- );
59
- const environment = await loadEnvironment(ctx.environment.name, ctx.config.root);
58
+ ));
59
+ const environment = await loadEnvironment(ctx.environment.name, {
60
+ root: ctx.config.root,
61
+ fetchModule(id) {
62
+ return rpc.fetch(id, "ssr");
63
+ }
64
+ });
60
65
  if (!environment.setupVM) {
61
66
  const envName = ctx.environment.name;
62
67
  const packageId = envName[0] === "." ? envName : `vitest-environment-${envName}`;
@@ -75,7 +80,7 @@ async function run(ctx) {
75
80
  environment: performance.now(),
76
81
  prepare: performance.now()
77
82
  },
78
- rpc: createSafeRpc(rpc)
83
+ rpc
79
84
  };
80
85
  installSourcemapsSupport({
81
86
  getSourceMap: (source) => moduleCache.getSourceMap(source)
package/dist/worker.js CHANGED
@@ -2,25 +2,25 @@ import { performance } from 'node:perf_hooks';
2
2
  import { c as createBirpc } from './vendor-index.b271ebe4.js';
3
3
  import { workerId } from 'tinypool';
4
4
  import { g as getWorkerState } from './vendor-global.97e4527c.js';
5
- import { l as loadEnvironment } from './vendor-environments.8eb4d407.js';
6
- import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.a63e187f.js';
5
+ import { l as loadEnvironment } from './vendor-environments.b9b2f624.js';
6
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.07d1a420.js';
7
7
  import { s as setupInspect } from './vendor-inspector.47fc8cbb.js';
8
8
  import { r as rpcDone, c as createSafeRpc } from './vendor-rpc.cbd8e972.js';
9
- import 'node:url';
10
9
  import 'pathe';
11
10
  import './vendor-index.0b5b3600.js';
12
11
  import 'acorn';
13
12
  import 'node:module';
14
13
  import 'node:fs';
14
+ import 'node:url';
15
15
  import 'node:assert';
16
16
  import 'node:process';
17
17
  import 'node:path';
18
18
  import 'node:v8';
19
19
  import 'node:util';
20
+ import 'vite-node/client';
20
21
  import 'node:console';
21
22
  import 'local-pkg';
22
23
  import 'node:vm';
23
- import 'vite-node/client';
24
24
  import 'vite-node/utils';
25
25
  import '@vitest/utils/error';
26
26
  import './vendor-paths.84fc7a99.js';
@@ -39,7 +39,7 @@ async function init(ctx) {
39
39
  const onCancel = new Promise((resolve) => {
40
40
  setCancel = resolve;
41
41
  });
42
- const rpc = createBirpc(
42
+ const rpc = createSafeRpc(createBirpc(
43
43
  {
44
44
  onCancel: setCancel
45
45
  },
@@ -52,8 +52,13 @@ async function init(ctx) {
52
52
  port.addListener("message", fn);
53
53
  }
54
54
  }
55
- );
56
- const environment = await loadEnvironment(ctx.environment.name, ctx.config.root);
55
+ ));
56
+ const environment = await loadEnvironment(ctx.environment.name, {
57
+ root: ctx.config.root,
58
+ fetchModule(id) {
59
+ return rpc.fetch(id, "ssr");
60
+ }
61
+ });
57
62
  if (ctx.environment.transformMode)
58
63
  environment.transformMode = ctx.environment.transformMode;
59
64
  const state = {
@@ -67,7 +72,7 @@ async function init(ctx) {
67
72
  environment: 0,
68
73
  prepare: performance.now()
69
74
  },
70
- rpc: createSafeRpc(rpc)
75
+ rpc
71
76
  };
72
77
  globalThis.__vitest_worker__ = state;
73
78
  if (ctx.invalidates) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.34.3",
4
+ "version": "0.34.5",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -153,14 +153,14 @@
153
153
  "strip-literal": "^1.0.1",
154
154
  "tinybench": "^2.5.0",
155
155
  "tinypool": "^0.7.0",
156
- "vite": "^3.0.0 || ^4.0.0",
156
+ "vite": "^3.1.0 || ^4.0.0 || ^5.0.0-0",
157
157
  "why-is-node-running": "^2.2.2",
158
- "@vitest/runner": "0.34.3",
159
- "@vitest/utils": "0.34.3",
160
- "vite-node": "0.34.3",
161
- "@vitest/expect": "0.34.3",
162
- "@vitest/snapshot": "0.34.3",
163
- "@vitest/spy": "0.34.3"
158
+ "@vitest/runner": "0.34.5",
159
+ "@vitest/snapshot": "0.34.5",
160
+ "vite-node": "0.34.5",
161
+ "@vitest/spy": "0.34.5",
162
+ "@vitest/utils": "0.34.5",
163
+ "@vitest/expect": "0.34.5"
164
164
  },
165
165
  "devDependencies": {
166
166
  "@ampproject/remapping": "^2.2.1",