vitest 0.0.109 → 0.0.113

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.
package/dist/entry.js CHANGED
@@ -1,18 +1,19 @@
1
1
  import fs, { promises } from 'fs';
2
- import { c as clearContext, e as defaultSuite, f as setHooks, h as getHooks, j as context, k as getFn, b as vi } from './vi-9754296d.js';
2
+ import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, b as getState, e as vi } from './vi-51946984.js';
3
3
  import { Console } from 'console';
4
4
  import { Writable } from 'stream';
5
5
  import { importModule } from 'local-pkg';
6
6
  import chai$1, { expect, util } from 'chai';
7
7
  import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
8
- import { l as index, g as getNames, c as c$1, t as toArray, b as basename, o as interpretOnlyMode, p as partitionSuiteChildren, q as hasTests, j as hasFailed } from './utils-d97bd6d9.js';
8
+ import { c as index, r as relative } from './index-1488b423.js';
9
9
  import { r as rpc, s as send } from './rpc-7de86f29.js';
10
- import { u as unifiedDiff } from './diff-46ee5d7d.js';
10
+ import { s as slash, f as getNames, c as c$1, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, j as hasTests, h as hasFailed } from './index-041e627e.js';
11
+ import { l as getOriginalPos, m as posToNumber, n as parseStack, u as unifiedDiff } from './diff-9c43ab50.js';
11
12
  import { performance } from 'perf_hooks';
12
- import { n as nanoid } from './jest-mock-8498c46d.js';
13
+ import { n as nanoid } from './jest-mock-a57b745c.js';
13
14
  import { format as format$1 } from 'util';
14
- import 'tty';
15
15
  import 'path';
16
+ import 'tty';
16
17
  import 'tinyspy';
17
18
 
18
19
  var node = {
@@ -382,6 +383,44 @@ var chaiSubset = {exports: {}};
382
383
 
383
384
  var Subset = chaiSubset.exports;
384
385
 
386
+ async function saveInlineSnapshots(snapshots) {
387
+ const MagicString = (await import('./magic-string.es-94000aea.js')).default;
388
+ const files = new Set(snapshots.map((i) => i.file));
389
+ await Promise.all(Array.from(files).map(async (file) => {
390
+ const map = await rpc("getSourceMap", file, true);
391
+ const snaps = snapshots.filter((i) => i.file === file);
392
+ const code = await promises.readFile(file, "utf8");
393
+ const s = new MagicString(code);
394
+ for (const snap of snaps) {
395
+ const pos = await getOriginalPos(map, snap);
396
+ const index = posToNumber(code, pos);
397
+ replaceInlineSnap(code, s, index, snap.snapshot);
398
+ }
399
+ await promises.writeFile(file, s.toString(), "utf-8");
400
+ }));
401
+ }
402
+ const startRegex = /toMatchInlineSnapshot\s*\(\s*(['"`\)])/m;
403
+ function replaceInlineSnap(code, s, index, newSnap) {
404
+ const startMatch = startRegex.exec(code.slice(index));
405
+ if (!startMatch)
406
+ return false;
407
+ newSnap = newSnap.replace(/\\/g, "\\\\");
408
+ const snapString = newSnap.includes("\n") ? `\`${newSnap.replace(/`/g, "\\`").trimEnd()}\`` : `'${newSnap.replace(/'/g, "\\'")}'`;
409
+ const quote = startMatch[1];
410
+ const startIndex = index + startMatch.index + startMatch[0].length;
411
+ if (quote === ")") {
412
+ s.appendRight(startIndex - 1, snapString);
413
+ return true;
414
+ }
415
+ const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
416
+ const endMatch = quoteEndRE.exec(code.slice(startIndex));
417
+ if (!endMatch)
418
+ return false;
419
+ const endIndex = startIndex + endMatch.index + endMatch[0].length;
420
+ s.overwrite(startIndex - 1, endIndex, snapString);
421
+ return true;
422
+ }
423
+
385
424
  var naturalCompare$2 = {exports: {}};
386
425
 
387
426
  /*
@@ -1422,13 +1461,13 @@ var _collections$1 = collections;
1422
1461
  // SENTINEL constants are from https://github.com/facebook/immutable-js
1423
1462
  const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
1424
1463
  const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
1425
- const IS_KEYED_SENTINEL$1 = '@@__IMMUTABLE_KEYED__@@';
1464
+ const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
1426
1465
  const IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
1427
- const IS_ORDERED_SENTINEL$1 = '@@__IMMUTABLE_ORDERED__@@';
1466
+ const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
1428
1467
  const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@'; // immutable v4
1429
1468
 
1430
1469
  const IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
1431
- const IS_SET_SENTINEL$1 = '@@__IMMUTABLE_SET__@@';
1470
+ const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
1432
1471
  const IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
1433
1472
 
1434
1473
  const getImmutableName = name => 'Immutable.' + name;
@@ -1517,7 +1556,7 @@ const printImmutableSeq = (val, config, indentation, depth, refs, printer) => {
1517
1556
  return printAsLeaf(name);
1518
1557
  }
1519
1558
 
1520
- if (val[IS_KEYED_SENTINEL$1]) {
1559
+ if (val[IS_KEYED_SENTINEL]) {
1521
1560
  return (
1522
1561
  name +
1523
1562
  SPACE +
@@ -1590,7 +1629,7 @@ const serialize$3 = (val, config, indentation, depth, refs, printer) => {
1590
1629
  depth,
1591
1630
  refs,
1592
1631
  printer,
1593
- val[IS_ORDERED_SENTINEL$1] ? 'OrderedMap' : 'Map'
1632
+ val[IS_ORDERED_SENTINEL] ? 'OrderedMap' : 'Map'
1594
1633
  );
1595
1634
  }
1596
1635
 
@@ -1606,7 +1645,7 @@ const serialize$3 = (val, config, indentation, depth, refs, printer) => {
1606
1645
  );
1607
1646
  }
1608
1647
 
1609
- if (val[IS_SET_SENTINEL$1]) {
1648
+ if (val[IS_SET_SENTINEL]) {
1610
1649
  return printImmutableValues(
1611
1650
  val,
1612
1651
  config,
@@ -1614,7 +1653,7 @@ const serialize$3 = (val, config, indentation, depth, refs, printer) => {
1614
1653
  depth,
1615
1654
  refs,
1616
1655
  printer,
1617
- val[IS_ORDERED_SENTINEL$1] ? 'OrderedSet' : 'Set'
1656
+ val[IS_ORDERED_SENTINEL] ? 'OrderedSet' : 'Set'
1618
1657
  );
1619
1658
  }
1620
1659
 
@@ -2187,7 +2226,7 @@ function _interopRequireDefault(obj) {
2187
2226
  */
2188
2227
 
2189
2228
  /* eslint-disable local/ban-types-eventually */
2190
- const toString$1 = Object.prototype.toString;
2229
+ const toString = Object.prototype.toString;
2191
2230
  const toISOString = Date.prototype.toISOString;
2192
2231
  const errorToString = Error.prototype.toString;
2193
2232
  const regExpToString = RegExp.prototype.toString;
@@ -2299,7 +2338,7 @@ function printBasicValue(val, printFunctionName, escapeRegex, escapeString) {
2299
2338
  return printSymbol(val);
2300
2339
  }
2301
2340
 
2302
- const toStringed = toString$1.call(val);
2341
+ const toStringed = toString.call(val);
2303
2342
 
2304
2343
  if (toStringed === '[object WeakMap]') {
2305
2344
  return 'WeakMap {}';
@@ -2375,7 +2414,7 @@ function printComplexValue(
2375
2414
  return printer(val.toJSON(), config, indentation, depth, refs, true);
2376
2415
  }
2377
2416
 
2378
- const toStringed = toString$1.call(val);
2417
+ const toStringed = toString.call(val);
2379
2418
 
2380
2419
  if (toStringed === '[object Arguments]') {
2381
2420
  return hitMaxDepth
@@ -2830,13 +2869,13 @@ function ensureDirectoryExists(filePath) {
2830
2869
  function normalizeNewlines(string) {
2831
2870
  return string.replace(/\r\n|\r/g, "\n");
2832
2871
  }
2833
- function saveSnapshotFile(snapshotData, snapshotPath) {
2872
+ async function saveSnapshotFile(snapshotData, snapshotPath) {
2834
2873
  const snapshots = Object.keys(snapshotData).sort(naturalCompare$1).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
2835
2874
  ensureDirectoryExists(snapshotPath);
2836
- fs.writeFileSync(snapshotPath, `${writeSnapshotVersion()}
2875
+ await promises.writeFile(snapshotPath, `${writeSnapshotVersion()}
2837
2876
 
2838
2877
  ${snapshots.join("\n\n")}
2839
- `);
2878
+ `, "utf-8");
2840
2879
  }
2841
2880
 
2842
2881
  var __defProp$1 = Object.defineProperty;
@@ -2862,6 +2901,7 @@ class SnapshotState {
2862
2901
  this._initialData = data;
2863
2902
  this._snapshotData = data;
2864
2903
  this._dirty = dirty;
2904
+ this._inlineSnapshots = [];
2865
2905
  this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
2866
2906
  this._counters = /* @__PURE__ */ new Map();
2867
2907
  this._index = 0;
@@ -2883,7 +2923,20 @@ class SnapshotState {
2883
2923
  }
2884
2924
  _addSnapshot(key, receivedSerialized, options) {
2885
2925
  this._dirty = true;
2886
- this._snapshotData[key] = receivedSerialized;
2926
+ if (options.isInline) {
2927
+ const error = options.error || new Error("Unknown error");
2928
+ const stacks = parseStack(error.stack || "");
2929
+ stacks.forEach((i) => i.file = slash(i.file));
2930
+ const stack = stacks.find((i) => process.__vitest_worker__.ctx.files.includes(i.file));
2931
+ if (!stack) {
2932
+ throw new Error("Vitest: Couldn't infer stack frame for inline snapshot.");
2933
+ }
2934
+ this._inlineSnapshots.push(__spreadValues$1({
2935
+ snapshot: receivedSerialized
2936
+ }, stack));
2937
+ } else {
2938
+ this._snapshotData[key] = receivedSerialized;
2939
+ }
2887
2940
  }
2888
2941
  clear() {
2889
2942
  this._snapshotData = this._initialData;
@@ -2894,16 +2947,19 @@ class SnapshotState {
2894
2947
  this.unmatched = 0;
2895
2948
  this.updated = 0;
2896
2949
  }
2897
- save() {
2950
+ async save() {
2898
2951
  const hasExternalSnapshots = Object.keys(this._snapshotData).length;
2899
- const isEmpty = !hasExternalSnapshots;
2952
+ const hasInlineSnapshots = this._inlineSnapshots.length;
2953
+ const isEmpty = !hasExternalSnapshots && !hasInlineSnapshots;
2900
2954
  const status = {
2901
2955
  deleted: false,
2902
2956
  saved: false
2903
2957
  };
2904
2958
  if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
2905
2959
  if (hasExternalSnapshots)
2906
- saveSnapshotFile(this._snapshotData, this._snapshotPath);
2960
+ await saveSnapshotFile(this._snapshotData, this._snapshotPath);
2961
+ if (hasInlineSnapshots)
2962
+ await saveInlineSnapshots(this._inlineSnapshots);
2907
2963
  status.saved = true;
2908
2964
  } else if (!hasExternalSnapshots && fs.existsSync(this._snapshotPath)) {
2909
2965
  if (this._updateSnapshot === "all")
@@ -3019,7 +3075,7 @@ class SnapshotClient {
3019
3075
  clearTest() {
3020
3076
  this.test = void 0;
3021
3077
  }
3022
- assert(received, message, inlineSnapshot) {
3078
+ assert(received, message, isInline = false, inlineSnapshot) {
3023
3079
  if (!this.test)
3024
3080
  throw new Error("Snapshot cannot be used outside of test");
3025
3081
  const testName = [
@@ -3029,7 +3085,7 @@ class SnapshotClient {
3029
3085
  const { actual, expected, key, pass } = this.snapshotState.match({
3030
3086
  testName,
3031
3087
  received,
3032
- isInline: !!inlineSnapshot,
3088
+ isInline,
3033
3089
  inlineSnapshot: inlineSnapshot == null ? void 0 : inlineSnapshot.trim()
3034
3090
  });
3035
3091
  if (!pass) {
@@ -3044,13 +3100,13 @@ class SnapshotClient {
3044
3100
  async saveSnap() {
3045
3101
  if (!this.testFile || !this.snapshotState)
3046
3102
  return;
3047
- const result = packSnapshotState(this.testFile, this.snapshotState);
3103
+ const result = await packSnapshotState(this.testFile, this.snapshotState);
3048
3104
  await rpc("snapshotSaved", result);
3049
3105
  this.testFile = "";
3050
3106
  this.snapshotState = void 0;
3051
3107
  }
3052
3108
  }
3053
- function packSnapshotState(filepath, state) {
3109
+ async function packSnapshotState(filepath, state) {
3054
3110
  const snapshot = {
3055
3111
  filepath,
3056
3112
  added: 0,
@@ -3065,7 +3121,7 @@ function packSnapshotState(filepath, state) {
3065
3121
  const uncheckedKeys = state.getUncheckedKeys();
3066
3122
  if (uncheckedCount)
3067
3123
  state.removeUncheckedKeys();
3068
- const status = state.save();
3124
+ const status = await state.save();
3069
3125
  snapshot.fileDeleted = status.deleted;
3070
3126
  snapshot.added = state.added;
3071
3127
  snapshot.matched = state.matched;
@@ -3091,7 +3147,7 @@ const SnapshotPlugin = (chai, utils) => {
3091
3147
  }
3092
3148
  utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function(inlineSnapshot, message) {
3093
3149
  const expected = utils.flag(this, "object");
3094
- getSnapshotClient().assert(expected, message, inlineSnapshot);
3150
+ getSnapshotClient().assert(expected, message, true, inlineSnapshot);
3095
3151
  });
3096
3152
  };
3097
3153
 
@@ -3200,238 +3256,6 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
3200
3256
  diff: diff
3201
3257
  });
3202
3258
 
3203
- const isObject = (val) => toString.call(val) === "[object Object]";
3204
- function equals(a, b, customTesters, strictCheck) {
3205
- customTesters = customTesters || [];
3206
- return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
3207
- }
3208
- function isAsymmetric(obj) {
3209
- return !!obj && isA("Function", obj.asymmetricMatch);
3210
- }
3211
- function hasAsymmetric(obj, seen = /* @__PURE__ */ new Set()) {
3212
- if (seen.has(obj))
3213
- return false;
3214
- seen.add(obj);
3215
- if (isAsymmetric(obj))
3216
- return true;
3217
- if (Array.isArray(obj))
3218
- return obj.some((i) => hasAsymmetric(i, seen));
3219
- if (obj instanceof Set)
3220
- return Array.from(obj).some((i) => hasAsymmetric(i, seen));
3221
- if (isObject(obj))
3222
- return Object.values(obj).some((v) => hasAsymmetric(v, seen));
3223
- return false;
3224
- }
3225
- function asymmetricMatch(a, b) {
3226
- const asymmetricA = isAsymmetric(a);
3227
- const asymmetricB = isAsymmetric(b);
3228
- if (asymmetricA && asymmetricB)
3229
- return void 0;
3230
- if (asymmetricA)
3231
- return a.asymmetricMatch(b);
3232
- if (asymmetricB)
3233
- return b.asymmetricMatch(a);
3234
- }
3235
- function eq(a, b, aStack, bStack, customTesters, hasKey2) {
3236
- let result = true;
3237
- const asymmetricResult = asymmetricMatch(a, b);
3238
- if (asymmetricResult !== void 0)
3239
- return asymmetricResult;
3240
- for (let i = 0; i < customTesters.length; i++) {
3241
- const customTesterResult = customTesters[i](a, b);
3242
- if (customTesterResult !== void 0)
3243
- return customTesterResult;
3244
- }
3245
- if (a instanceof Error && b instanceof Error)
3246
- return a.message === b.message;
3247
- if (Object.is(a, b))
3248
- return true;
3249
- if (a === null || b === null)
3250
- return a === b;
3251
- const className = Object.prototype.toString.call(a);
3252
- if (className !== Object.prototype.toString.call(b))
3253
- return false;
3254
- switch (className) {
3255
- case "[object Boolean]":
3256
- case "[object String]":
3257
- case "[object Number]":
3258
- if (typeof a !== typeof b) {
3259
- return false;
3260
- } else if (typeof a !== "object" && typeof b !== "object") {
3261
- return Object.is(a, b);
3262
- } else {
3263
- return Object.is(a.valueOf(), b.valueOf());
3264
- }
3265
- case "[object Date]":
3266
- return +a === +b;
3267
- case "[object RegExp]":
3268
- return a.source === b.source && a.flags === b.flags;
3269
- }
3270
- if (typeof a !== "object" || typeof b !== "object")
3271
- return false;
3272
- if (isDomNode(a) && isDomNode(b))
3273
- return a.isEqualNode(b);
3274
- let length = aStack.length;
3275
- while (length--) {
3276
- if (aStack[length] === a)
3277
- return bStack[length] === b;
3278
- else if (bStack[length] === b)
3279
- return false;
3280
- }
3281
- aStack.push(a);
3282
- bStack.push(b);
3283
- if (className === "[object Array]" && a.length !== b.length)
3284
- return false;
3285
- const aKeys = keys(a, hasKey2);
3286
- let key;
3287
- let size = aKeys.length;
3288
- if (keys(b, hasKey2).length !== size)
3289
- return false;
3290
- while (size--) {
3291
- key = aKeys[size];
3292
- result = hasKey2(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, hasKey2);
3293
- if (!result)
3294
- return false;
3295
- }
3296
- aStack.pop();
3297
- bStack.pop();
3298
- return result;
3299
- }
3300
- function keys(obj, hasKey2) {
3301
- const keys2 = [];
3302
- for (const key in obj) {
3303
- if (hasKey2(obj, key))
3304
- keys2.push(key);
3305
- }
3306
- return keys2.concat(Object.getOwnPropertySymbols(obj).filter((symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable));
3307
- }
3308
- function hasDefinedKey(obj, key) {
3309
- return hasKey(obj, key) && obj[key] !== void 0;
3310
- }
3311
- function hasKey(obj, key) {
3312
- return Object.prototype.hasOwnProperty.call(obj, key);
3313
- }
3314
- function isA(typeName, value) {
3315
- return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
3316
- }
3317
- function isDomNode(obj) {
3318
- return obj !== null && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string" && typeof obj.isEqualNode === "function";
3319
- }
3320
- const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
3321
- const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
3322
- const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
3323
- function isImmutableUnorderedKeyed(maybeKeyed) {
3324
- return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL] && !maybeKeyed[IS_ORDERED_SENTINEL]);
3325
- }
3326
- function isImmutableUnorderedSet(maybeSet) {
3327
- return !!(maybeSet && maybeSet[IS_SET_SENTINEL] && !maybeSet[IS_ORDERED_SENTINEL]);
3328
- }
3329
- const IteratorSymbol = Symbol.iterator;
3330
- const hasIterator = (object) => !!(object != null && object[IteratorSymbol]);
3331
- const iterableEquality = (a, b, aStack = [], bStack = []) => {
3332
- if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b))
3333
- return void 0;
3334
- if (a.constructor !== b.constructor)
3335
- return false;
3336
- let length = aStack.length;
3337
- while (length--) {
3338
- if (aStack[length] === a)
3339
- return bStack[length] === b;
3340
- }
3341
- aStack.push(a);
3342
- bStack.push(b);
3343
- const iterableEqualityWithStack = (a2, b2) => iterableEquality(a2, b2, [...aStack], [...bStack]);
3344
- if (a.size !== void 0) {
3345
- if (a.size !== b.size) {
3346
- return false;
3347
- } else if (isA("Set", a) || isImmutableUnorderedSet(a)) {
3348
- let allFound = true;
3349
- for (const aValue of a) {
3350
- if (!b.has(aValue)) {
3351
- let has = false;
3352
- for (const bValue of b) {
3353
- const isEqual = equals(aValue, bValue, [iterableEqualityWithStack]);
3354
- if (isEqual === true)
3355
- has = true;
3356
- }
3357
- if (has === false) {
3358
- allFound = false;
3359
- break;
3360
- }
3361
- }
3362
- }
3363
- aStack.pop();
3364
- bStack.pop();
3365
- return allFound;
3366
- } else if (isA("Map", a) || isImmutableUnorderedKeyed(a)) {
3367
- let allFound = true;
3368
- for (const aEntry of a) {
3369
- if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), [iterableEqualityWithStack])) {
3370
- let has = false;
3371
- for (const bEntry of b) {
3372
- const matchedKey = equals(aEntry[0], bEntry[0], [
3373
- iterableEqualityWithStack
3374
- ]);
3375
- let matchedValue = false;
3376
- if (matchedKey === true) {
3377
- matchedValue = equals(aEntry[1], bEntry[1], [
3378
- iterableEqualityWithStack
3379
- ]);
3380
- }
3381
- if (matchedValue === true)
3382
- has = true;
3383
- }
3384
- if (has === false) {
3385
- allFound = false;
3386
- break;
3387
- }
3388
- }
3389
- }
3390
- aStack.pop();
3391
- bStack.pop();
3392
- return allFound;
3393
- }
3394
- }
3395
- const bIterator = b[IteratorSymbol]();
3396
- for (const aValue of a) {
3397
- const nextB = bIterator.next();
3398
- if (nextB.done || !equals(aValue, nextB.value, [iterableEqualityWithStack]))
3399
- return false;
3400
- }
3401
- if (!bIterator.next().done)
3402
- return false;
3403
- aStack.pop();
3404
- bStack.pop();
3405
- return true;
3406
- };
3407
- const hasPropertyInObject = (object, key) => {
3408
- const shouldTerminate = !object || typeof object !== "object" || object === Object.prototype;
3409
- if (shouldTerminate)
3410
- return false;
3411
- return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
3412
- };
3413
- const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
3414
- const subsetEquality = (object, subset) => {
3415
- const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
3416
- if (!isObjectWithKeys(subset2))
3417
- return void 0;
3418
- return Object.keys(subset2).every((key) => {
3419
- if (isObjectWithKeys(subset2[key])) {
3420
- if (seenReferences.has(subset2[key]))
3421
- return equals(object2[key], subset2[key], [iterableEquality]);
3422
- seenReferences.set(subset2[key], true);
3423
- }
3424
- const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
3425
- iterableEquality,
3426
- subsetEqualityWithContext(seenReferences)
3427
- ]);
3428
- seenReferences.delete(subset2[key]);
3429
- return result;
3430
- });
3431
- };
3432
- return subsetEqualityWithContext()(object, subset);
3433
- };
3434
-
3435
3259
  var __defProp = Object.defineProperty;
3436
3260
  var __defProps = Object.defineProperties;
3437
3261
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -3499,213 +3323,11 @@ const JestExtend = (chai2, utils) => {
3499
3323
  });
3500
3324
  };
3501
3325
 
3502
- const JestChaiExpect = (chai, utils) => {
3503
- function def(name, fn) {
3504
- const addMethod = (n) => {
3505
- utils.addMethod(chai.Assertion.prototype, n, fn);
3506
- };
3507
- if (Array.isArray(name))
3508
- name.forEach((n) => addMethod(n));
3509
- else
3510
- addMethod(name);
3511
- }
3512
- const chaiEqual = chai.Assertion.prototype.equal;
3513
- def("chaiEqual", function(...args) {
3514
- return chaiEqual.apply(this, args);
3515
- });
3516
- utils.overwriteMethod(chai.Assertion.prototype, "equal", (_super) => {
3517
- return function(...args) {
3518
- const expected = args[0];
3519
- const actual = utils.flag(this, "object");
3520
- if (hasAsymmetric(expected)) {
3521
- this.assert(equals(actual, expected, void 0, true), "not match with #{act}", "should not match with #{act}", actual, expected);
3522
- } else {
3523
- _super.apply(this, args);
3524
- }
3525
- };
3526
- });
3527
- utils.overwriteMethod(chai.Assertion.prototype, "eql", (_super) => {
3528
- return function(...args) {
3529
- const expected = args[0];
3530
- const actual = utils.flag(this, "object");
3531
- if (hasAsymmetric(expected)) {
3532
- this.assert(equals(actual, expected), "not match with #{exp}", "should not match with #{exp}", actual, expected);
3533
- } else {
3534
- _super.apply(this, args);
3535
- }
3536
- };
3537
- });
3538
- def("toEqual", function(expected) {
3539
- return this.eql(expected);
3540
- });
3541
- def("toStrictEqual", function(expected) {
3542
- return this.chaiEqual(expected);
3543
- });
3544
- def("toBe", function(expected) {
3545
- return this.equal(expected);
3546
- });
3547
- def("toMatchObject", function(expected) {
3548
- return this.containSubset(expected);
3549
- });
3550
- def("toMatch", function(expected) {
3551
- if (typeof expected === "string")
3552
- return this.include(expected);
3553
- else
3554
- return this.match(expected);
3555
- });
3556
- def("toContain", function(item) {
3557
- return this.contain(item);
3558
- });
3559
- def("toContainEqual", function(expected) {
3560
- const obj = utils.flag(this, "object");
3561
- const index = Array.from(obj).findIndex((item) => {
3562
- try {
3563
- chai.assert.deepEqual(item, expected);
3564
- } catch {
3565
- return false;
3566
- }
3567
- return true;
3568
- });
3569
- this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
3570
- });
3571
- def("toBeTruthy", function() {
3572
- const obj = utils.flag(this, "object");
3573
- this.assert(Boolean(obj), "expected #{this} to be truthy", "expected #{this} to not be truthy", obj);
3574
- });
3575
- def("toBeFalsy", function() {
3576
- const obj = utils.flag(this, "object");
3577
- this.assert(!obj, "expected #{this} to be falsy", "expected #{this} to not be falsy", obj);
3578
- });
3579
- def("toBeGreaterThan", function(expected) {
3580
- return this.to.greaterThan(expected);
3581
- });
3582
- def("toBeGreaterThanOrEqual", function(expected) {
3583
- return this.to.greaterThanOrEqual(expected);
3584
- });
3585
- def("toBeLessThan", function(expected) {
3586
- return this.to.lessThan(expected);
3587
- });
3588
- def("toBeLessThanOrEqual", function(expected) {
3589
- return this.to.lessThanOrEqual(expected);
3590
- });
3591
- def("toBeNaN", function() {
3592
- return this.be.NaN;
3593
- });
3594
- def("toBeUndefined", function() {
3595
- return this.be.undefined;
3596
- });
3597
- def("toBeNull", function() {
3598
- return this.be.null;
3599
- });
3600
- def("toBeDefined", function() {
3601
- return this.not.be.undefined;
3602
- });
3603
- def("toBeInstanceOf", function(obj) {
3604
- return this.instanceOf(obj);
3605
- });
3606
- def("toHaveLength", function(length) {
3607
- return this.have.length(length);
3608
- });
3609
- def("toHaveProperty", function(...args) {
3610
- return this.have.deep.nested.property(...args);
3611
- });
3612
- def("toBeCloseTo", function(number, numDigits = 2) {
3613
- utils.expectTypes(this, ["number"]);
3614
- return this.closeTo(number, numDigits);
3615
- });
3616
- function isSpy(putativeSpy) {
3617
- return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
3618
- }
3619
- const assertIsMock = (assertion) => {
3620
- if (!isSpy(assertion._obj))
3621
- throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
3622
- };
3623
- const getSpy = (assertion) => {
3624
- assertIsMock(assertion);
3625
- return assertion._obj;
3626
- };
3627
- def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
3628
- const spy = getSpy(this);
3629
- return this.assert(spy.callCount === number, "expected spy to be called #{exp} times", "expected spy to not be called #{exp} times", number, spy.callCount);
3630
- });
3631
- def("toHaveBeenCalledOnce", function() {
3632
- const spy = getSpy(this);
3633
- return this.assert(spy.callCount === 1, "expected spy to be called once", "expected spy to not be called once", 1, spy.callCount);
3634
- });
3635
- def(["toHaveBeenCalled", "toBeCalled"], function() {
3636
- const spy = getSpy(this);
3637
- return this.assert(spy.called, "expected spy to be called at least once", "expected spy to not be called at all", true, spy.called);
3638
- });
3639
- def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
3640
- const spy = getSpy(this);
3641
- const pass = spy.calls.some((callArg) => equals(callArg, args));
3642
- return this.assert(pass, "expected spy to be called with arguments: #{exp}", "expected spy to not be called with arguments: #{exp}", args, spy.calls);
3643
- });
3644
- const ordinalOf = (i) => {
3645
- const j = i % 10;
3646
- const k = i % 100;
3647
- if (j === 1 && k !== 11)
3648
- return `${i}st`;
3649
- if (j === 2 && k !== 12)
3650
- return `${i}nd`;
3651
- if (j === 3 && k !== 13)
3652
- return `${i}rd`;
3653
- return `${i}th`;
3654
- };
3655
- def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
3656
- const spy = getSpy(this);
3657
- const nthCall = spy.calls[times - 1];
3658
- this.assert(equals(nthCall, args), `expected ${ordinalOf(times)} spy call to have been called with #{exp}`, `expected ${ordinalOf(times)} spy call to not have been called with #{exp}`, args, nthCall);
3659
- });
3660
- def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
3661
- const spy = getSpy(this);
3662
- const lastCall = spy.calls[spy.calls.length - 1];
3663
- this.assert(equals(lastCall, args), "expected last spy call to have been called with #{exp}", "expected last spy call to not have been called with #{exp}", args, lastCall);
3664
- });
3665
- def(["toThrow", "toThrowError"], function(expected) {
3666
- const negate = utils.flag(this, "negate");
3667
- if (negate)
3668
- this.not.to.throw(expected);
3669
- else
3670
- this.to.throw(expected);
3671
- });
3672
- def(["toHaveReturned", "toReturn"], function() {
3673
- const spy = getSpy(this);
3674
- const calledAndNotThrew = spy.called && !spy.results.some(([type]) => type === "error");
3675
- this.assert(calledAndNotThrew, "expected spy to be successfully called at least once", "expected spy to not be successfully called", calledAndNotThrew, !calledAndNotThrew);
3676
- });
3677
- def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
3678
- const spy = getSpy(this);
3679
- const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
3680
- this.assert(successfullReturns === times, `expected spy to be successfully called ${times} times`, `expected spy to not be successfully called ${times} times`, `expected number of returns: ${times}`, `received number of returns: ${successfullReturns}`);
3681
- });
3682
- def(["toHaveReturnedWith", "toReturnWith"], function(value) {
3683
- const spy = getSpy(this);
3684
- const pass = spy.results.some(([type, result]) => type === "ok" && equals(value, result));
3685
- this.assert(pass, "expected spy to be successfully called with #{exp}", "expected spy to not be successfully called with #{exp}", value);
3686
- });
3687
- def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
3688
- const spy = getSpy(this);
3689
- const lastResult = spy.returns[spy.returns.length - 1];
3690
- const pass = equals(lastResult, value);
3691
- this.assert(pass, "expected last spy call to return #{exp}", "expected last spy call to not return #{exp}", value, lastResult);
3692
- });
3693
- def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
3694
- const spy = getSpy(this);
3695
- const isNot = utils.flag(this, "negate");
3696
- const [callType, callResult] = spy.results[nthCall - 1];
3697
- const ordinalCall = `${ordinalOf(nthCall)} call`;
3698
- if (!isNot && callType === "error")
3699
- chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
3700
- const nthCallReturn = equals(callResult, value);
3701
- this.assert(nthCallReturn, `expected ${ordinalCall} spy call to return #{exp}`, `expected ${ordinalCall} spy call to not return #{exp}`, value, callResult);
3702
- });
3703
- };
3704
-
3705
3326
  class AsymmetricMatcher {
3706
3327
  constructor(sample, inverse = false) {
3707
3328
  this.sample = sample;
3708
3329
  this.inverse = inverse;
3330
+ this.$$typeof = Symbol.for("jest.asymmetricMatcher");
3709
3331
  }
3710
3332
  getMatcherContext() {
3711
3333
  return {
@@ -3906,7 +3528,7 @@ async function setupGlobalEnv(config) {
3906
3528
  setupConsoleLogSpy();
3907
3529
  await setupChai();
3908
3530
  if (config.global)
3909
- (await import('./global-e0d00047.js')).registerApiGlobally();
3531
+ (await import('./global-75208c77.js')).registerApiGlobally();
3910
3532
  }
3911
3533
  function setupConsoleLogSpy() {
3912
3534
  const stdout = new Writable({
@@ -3991,7 +3613,7 @@ async function collectTests(paths, config) {
3991
3613
  for (const filepath of paths) {
3992
3614
  const file = {
3993
3615
  id: nanoid(),
3994
- name: basename(filepath),
3616
+ name: relative(config.root, filepath),
3995
3617
  type: "suite",
3996
3618
  mode: "run",
3997
3619
  computeMode: "serial",
@@ -4053,7 +3675,11 @@ async function runTest(test) {
4053
3675
  process.__vitest_worker__.current = test;
4054
3676
  try {
4055
3677
  await callSuiteHook(test.suite, "beforeEach", [test, test.suite]);
3678
+ setState({ assertionCalls: 0, expectedAssertionsNumber: null, expectedAssertionsNumberError: null });
4056
3679
  await getFn(test)();
3680
+ const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberError } = getState();
3681
+ if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
3682
+ throw expectedAssertionsNumberError;
4057
3683
  test.result.state = "pass";
4058
3684
  } catch (e) {
4059
3685
  test.result.state = "fail";