vitest 0.22.1 → 0.23.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 (46) hide show
  1. package/LICENSE.md +29 -29
  2. package/dist/browser.d.ts +5 -4
  3. package/dist/browser.mjs +11 -9
  4. package/dist/{chunk-api-setup.377c28aa.mjs → chunk-api-setup.5fc06d1d.mjs} +90 -87
  5. package/dist/{chunk-constants.71e8a211.mjs → chunk-constants.6196597b.mjs} +0 -0
  6. package/dist/{chunk-integrations-coverage.d205bd87.mjs → chunk-env-node.ceb43f1c.mjs} +31 -179
  7. package/dist/{chunk-install-pkg.3aa3eae6.mjs → chunk-install-pkg.e081fc1b.mjs} +3 -3
  8. package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
  9. package/dist/{chunk-integrations-globals.60af7da3.mjs → chunk-integrations-globals.ef598c23.mjs} +6 -7
  10. package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
  11. package/dist/{chunk-mock-date.304e29b1.mjs → chunk-mock-date.0d86eaa5.mjs} +26 -5
  12. package/dist/{chunk-node-git.9a7e3153.mjs → chunk-node-git.6f289b0a.mjs} +18 -12
  13. package/dist/{chunk-runtime-chain.be610650.mjs → chunk-runtime-chain.2af36ddf.mjs} +507 -173
  14. package/dist/{chunk-runtime-error.1104e45a.mjs → chunk-runtime-error.ed9b4f70.mjs} +206 -75
  15. package/dist/{chunk-runtime-hooks.5d7073db.mjs → chunk-runtime-hooks.75ce0575.mjs} +18 -12
  16. package/dist/{chunk-runtime-mocker.49d21aa6.mjs → chunk-runtime-mocker.fc76f21d.mjs} +17 -10
  17. package/dist/{chunk-runtime-rpc.57586b73.mjs → chunk-runtime-rpc.3fe371e9.mjs} +1 -2
  18. package/dist/{chunk-utils-source-map.bbf3ad19.mjs → chunk-utils-source-map.70ee97e1.mjs} +11 -5
  19. package/dist/{chunk-vite-node-client.cddda63d.mjs → chunk-vite-node-client.74ebe3d5.mjs} +55 -13
  20. package/dist/{chunk-vite-node-debug.536c4c5b.mjs → chunk-vite-node-debug.2d8a1dc3.mjs} +1 -1
  21. package/dist/{chunk-vite-node-externalize.c843f497.mjs → chunk-vite-node-externalize.41bf722e.mjs} +483 -197
  22. package/dist/{chunk-vite-node-utils.b432150c.mjs → chunk-vite-node-utils.68573626.mjs} +24 -40
  23. package/dist/cli-wrapper.mjs +21 -17
  24. package/dist/cli.mjs +23 -15
  25. package/dist/config.cjs +2 -2
  26. package/dist/config.d.ts +4 -3
  27. package/dist/config.mjs +2 -2
  28. package/dist/entry.mjs +19 -14
  29. package/dist/environments.d.ts +23 -0
  30. package/dist/environments.mjs +3 -0
  31. package/dist/{global-fe52f84b.d.ts → global-ea084c9f.d.ts} +135 -19
  32. package/dist/{index-ea17aa0c.d.ts → index-5f09f4d0.d.ts} +3 -2
  33. package/dist/index.d.ts +6 -5
  34. package/dist/index.mjs +6 -7
  35. package/dist/loader.mjs +3 -4
  36. package/dist/node.d.ts +5 -4
  37. package/dist/node.mjs +14 -12
  38. package/dist/suite.mjs +5 -6
  39. package/dist/vendor-index.0557b03a.mjs +147 -0
  40. package/dist/{vendor-index.9d9196cc.mjs → vendor-index.13e3bda3.mjs} +0 -0
  41. package/dist/{vendor-index.fbec8a81.mjs → vendor-index.4aeeb598.mjs} +2 -2
  42. package/dist/{vendor-index.2ae8040a.mjs → vendor-index.62ce5c33.mjs} +0 -0
  43. package/dist/{vendor-index.29636037.mjs → vendor-index.731a22f2.mjs} +0 -0
  44. package/dist/worker.mjs +17 -15
  45. package/package.json +17 -10
  46. package/dist/chunk-utils-global.fa20c2f6.mjs +0 -5
@@ -1,13 +1,12 @@
1
1
  import util$1 from 'util';
2
- import { i as isObject, g as getCallLastIndex, s as slash, b as getNames, c as assertTypes, d as getFullName, n as noop } from './chunk-mock-date.304e29b1.mjs';
2
+ import { i as isObject, b as getCallLastIndex, s as slash, g as getWorkerState, c as getNames, d as assertTypes, e as getFullName, f as isRunningInTest, n as noop, h as isRunningInBenchmark } from './chunk-mock-date.0d86eaa5.mjs';
3
3
  import * as chai$2 from 'chai';
4
4
  import { expect, AssertionError, util } from 'chai';
5
5
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
6
- import { r as rpc } from './chunk-runtime-rpc.57586b73.mjs';
6
+ import { r as rpc } from './chunk-runtime-rpc.3fe371e9.mjs';
7
7
  import fs, { promises } from 'fs';
8
- import { j as join, d as dirname, p as picocolors } from './chunk-constants.71e8a211.mjs';
9
- import { a as plugins_1, f as format_1, g as getOriginalPos, b as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils } from './chunk-utils-source-map.bbf3ad19.mjs';
10
- import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
8
+ import { j as join, d as dirname, p as picocolors } from './chunk-constants.6196597b.mjs';
9
+ import { a as plugins_1, f as format_1, g as getOriginalPos, b as posToNumber, n as numberToPos, l as lineSplitRE, p as parseStacktrace, u as unifiedDiff, s as stringify, m as matcherUtils } from './chunk-utils-source-map.70ee97e1.mjs';
11
10
  import { isMockFunction } from './spy.mjs';
12
11
  import { s as safeSetTimeout, a as safeClearTimeout } from './chunk-utils-timers.b48455ed.mjs';
13
12
 
@@ -209,7 +208,11 @@ function keys(obj, hasKey2) {
209
208
  if (hasKey2(obj, key))
210
209
  keys2.push(key);
211
210
  }
212
- return keys2.concat(Object.getOwnPropertySymbols(obj).filter((symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable));
211
+ return keys2.concat(
212
+ Object.getOwnPropertySymbols(obj).filter(
213
+ (symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable
214
+ )
215
+ );
213
216
  }
214
217
  function hasDefinedKey(obj, key) {
215
218
  return hasKey(obj, key) && obj[key] !== void 0;
@@ -499,13 +502,15 @@ const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith
499
502
  const escapeRegex = true;
500
503
  const printFunctionName = false;
501
504
  function serialize(val, indent = 2, formatOverrides = {}) {
502
- return normalizeNewlines(format_1(val, {
503
- escapeRegex,
504
- indent,
505
- plugins: getSerializers(),
506
- printFunctionName,
507
- ...formatOverrides
508
- }));
505
+ return normalizeNewlines(
506
+ format_1(val, {
507
+ escapeRegex,
508
+ indent,
509
+ plugins: getSerializers(),
510
+ printFunctionName,
511
+ ...formatOverrides
512
+ })
513
+ );
509
514
  }
510
515
  function escapeBacktickString(str) {
511
516
  return str.replace(/`|\\|\${/g, "\\$&");
@@ -524,7 +529,9 @@ function normalizeNewlines(string) {
524
529
  }
525
530
  async function saveSnapshotFile(snapshotData, snapshotPath) {
526
531
  var _a, _b;
527
- const snapshots = Object.keys(snapshotData).sort(naturalCompare$1.exports).map((key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`);
532
+ const snapshots = Object.keys(snapshotData).sort(naturalCompare$1.exports).map(
533
+ (key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`
534
+ );
528
535
  const content = `${writeSnapshotVersion()}
529
536
 
530
537
  ${snapshots.join("\n\n")}
@@ -533,7 +540,11 @@ ${snapshots.join("\n\n")}
533
540
  if (skipWriting)
534
541
  return;
535
542
  ensureDirectoryExists(snapshotPath);
536
- await ((_b = fs) == null ? void 0 : _b.promises.writeFile(snapshotPath, content, "utf-8"));
543
+ await ((_b = fs) == null ? void 0 : _b.promises.writeFile(
544
+ snapshotPath,
545
+ content,
546
+ "utf-8"
547
+ ));
537
548
  }
538
549
  function prepareExpected(expected) {
539
550
  function findStartIndent() {
@@ -589,7 +600,7 @@ function deepMergeSnapshot(target, source) {
589
600
  }
590
601
 
591
602
  async function saveInlineSnapshots(snapshots) {
592
- const MagicString = (await import('./chunk-magic-string.efe26975.mjs')).default;
603
+ const MagicString = (await import('./chunk-magic-string.56b2b543.mjs')).default;
593
604
  const files = new Set(snapshots.map((i) => i.file));
594
605
  await Promise.all(Array.from(files).map(async (file) => {
595
606
  const map = await rpc().getSourceMap(file);
@@ -685,7 +696,10 @@ class SnapshotState {
685
696
  constructor(testFilePath, snapshotPath, options) {
686
697
  this.testFilePath = testFilePath;
687
698
  this.snapshotPath = snapshotPath;
688
- const { data, dirty } = getSnapshotData(this.snapshotPath, options.updateSnapshot);
699
+ const { data, dirty } = getSnapshotData(
700
+ this.snapshotPath,
701
+ options.updateSnapshot
702
+ );
689
703
  this._initialData = data;
690
704
  this._snapshotData = data;
691
705
  this._dirty = dirty;
@@ -724,8 +738,10 @@ class SnapshotState {
724
738
  stacks.forEach((i) => i.file = slash(i.file));
725
739
  const stack = this._inferInlineSnapshotStack(stacks);
726
740
  if (!stack) {
727
- throw new Error(`Vitest: Couldn't infer stack frame for inline snapshot.
728
- ${JSON.stringify(stacks)}`);
741
+ throw new Error(
742
+ `Vitest: Couldn't infer stack frame for inline snapshot.
743
+ ${JSON.stringify(stacks)}`
744
+ );
729
745
  }
730
746
  stack.column--;
731
747
  this._inlineSnapshots.push({
@@ -884,7 +900,14 @@ class SnapshotClient {
884
900
  this.saveCurrent();
885
901
  const filePath = this.test.file.filepath;
886
902
  if (!this.getSnapshotState(test)) {
887
- this.snapshotStateMap.set(filePath, new SnapshotState(filePath, await rpc().resolveSnapshotPath(filePath), getWorkerState().config.snapshotOptions));
903
+ this.snapshotStateMap.set(
904
+ filePath,
905
+ new SnapshotState(
906
+ filePath,
907
+ await rpc().resolveSnapshotPath(filePath),
908
+ getWorkerState().config.snapshotOptions
909
+ )
910
+ );
888
911
  }
889
912
  this.snapshotState = this.getSnapshotState(test);
890
913
  }
@@ -981,79 +1004,95 @@ const getErrorString = (expected, promise) => {
981
1004
  } catch (e) {
982
1005
  return getErrorMessage(e);
983
1006
  }
984
- throw new Error("snapshot function didn't threw");
1007
+ throw new Error("snapshot function didn't throw");
985
1008
  };
986
1009
  const SnapshotPlugin = (chai, utils) => {
987
1010
  for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
988
- utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
1011
+ utils.addMethod(
1012
+ chai.Assertion.prototype,
1013
+ key,
1014
+ function(properties, message) {
1015
+ const expected = utils.flag(this, "object");
1016
+ const test = utils.flag(this, "vitest-test");
1017
+ if (typeof properties === "string" && typeof message === "undefined") {
1018
+ message = properties;
1019
+ properties = void 0;
1020
+ }
1021
+ const errorMessage = utils.flag(this, "message");
1022
+ getSnapshotClient().assert({
1023
+ received: expected,
1024
+ test,
1025
+ message,
1026
+ isInline: false,
1027
+ properties,
1028
+ errorMessage
1029
+ });
1030
+ }
1031
+ );
1032
+ }
1033
+ utils.addMethod(
1034
+ chai.Assertion.prototype,
1035
+ "toMatchInlineSnapshot",
1036
+ function __VITEST_INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
989
1037
  const expected = utils.flag(this, "object");
1038
+ const error = utils.flag(this, "error");
990
1039
  const test = utils.flag(this, "vitest-test");
991
- if (typeof properties === "string" && typeof message === "undefined") {
992
- message = properties;
1040
+ if (typeof properties === "string") {
1041
+ message = inlineSnapshot;
1042
+ inlineSnapshot = properties;
993
1043
  properties = void 0;
994
1044
  }
1045
+ if (inlineSnapshot)
1046
+ inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
995
1047
  const errorMessage = utils.flag(this, "message");
996
1048
  getSnapshotClient().assert({
997
1049
  received: expected,
998
1050
  test,
999
1051
  message,
1000
- isInline: false,
1052
+ isInline: true,
1001
1053
  properties,
1054
+ inlineSnapshot,
1055
+ error,
1002
1056
  errorMessage
1003
1057
  });
1004
- });
1005
- }
1006
- utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function __VITEST_INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
1007
- const expected = utils.flag(this, "object");
1008
- const error = utils.flag(this, "error");
1009
- const test = utils.flag(this, "vitest-test");
1010
- if (typeof properties === "string") {
1011
- message = inlineSnapshot;
1012
- inlineSnapshot = properties;
1013
- properties = void 0;
1014
1058
  }
1015
- if (inlineSnapshot)
1016
- inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
1017
- const errorMessage = utils.flag(this, "message");
1018
- getSnapshotClient().assert({
1019
- received: expected,
1020
- test,
1021
- message,
1022
- isInline: true,
1023
- properties,
1024
- inlineSnapshot,
1025
- error,
1026
- errorMessage
1027
- });
1028
- });
1029
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
1030
- const expected = utils.flag(this, "object");
1031
- const test = utils.flag(this, "vitest-test");
1032
- const promise = utils.flag(this, "promise");
1033
- const errorMessage = utils.flag(this, "message");
1034
- getSnapshotClient().assert({
1035
- received: getErrorString(expected, promise),
1036
- test,
1037
- message,
1038
- errorMessage
1039
- });
1040
- });
1041
- utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __VITEST_INLINE_SNAPSHOT__(inlineSnapshot, message) {
1042
- const expected = utils.flag(this, "object");
1043
- const error = utils.flag(this, "error");
1044
- const test = utils.flag(this, "vitest-test");
1045
- const promise = utils.flag(this, "promise");
1046
- const errorMessage = utils.flag(this, "message");
1047
- getSnapshotClient().assert({
1048
- received: getErrorString(expected, promise),
1049
- test,
1050
- message,
1051
- inlineSnapshot,
1052
- isInline: true,
1053
- error,
1054
- errorMessage
1055
- });
1056
- });
1059
+ );
1060
+ utils.addMethod(
1061
+ chai.Assertion.prototype,
1062
+ "toThrowErrorMatchingSnapshot",
1063
+ function(message) {
1064
+ const expected = utils.flag(this, "object");
1065
+ const test = utils.flag(this, "vitest-test");
1066
+ const promise = utils.flag(this, "promise");
1067
+ const errorMessage = utils.flag(this, "message");
1068
+ getSnapshotClient().assert({
1069
+ received: getErrorString(expected, promise),
1070
+ test,
1071
+ message,
1072
+ errorMessage
1073
+ });
1074
+ }
1075
+ );
1076
+ utils.addMethod(
1077
+ chai.Assertion.prototype,
1078
+ "toThrowErrorMatchingInlineSnapshot",
1079
+ function __VITEST_INLINE_SNAPSHOT__(inlineSnapshot, message) {
1080
+ const expected = utils.flag(this, "object");
1081
+ const error = utils.flag(this, "error");
1082
+ const test = utils.flag(this, "vitest-test");
1083
+ const promise = utils.flag(this, "promise");
1084
+ const errorMessage = utils.flag(this, "message");
1085
+ getSnapshotClient().assert({
1086
+ received: getErrorString(expected, promise),
1087
+ test,
1088
+ message,
1089
+ inlineSnapshot,
1090
+ isInline: true,
1091
+ error,
1092
+ errorMessage
1093
+ });
1094
+ }
1095
+ );
1057
1096
  };
1058
1097
 
1059
1098
  var chai$1 = /*#__PURE__*/Object.freeze({
@@ -1064,10 +1103,20 @@ var chai$1 = /*#__PURE__*/Object.freeze({
1064
1103
 
1065
1104
  const GLOBAL_EXPECT = Symbol.for("expect-global");
1066
1105
  const MATCHERS_OBJECT = Symbol.for("matchers-object");
1106
+ const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
1067
1107
 
1068
1108
  if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
1109
+ const globalState = /* @__PURE__ */ new WeakMap();
1110
+ const matchers = /* @__PURE__ */ Object.create(null);
1069
1111
  Object.defineProperty(globalThis, MATCHERS_OBJECT, {
1070
- value: /* @__PURE__ */ new WeakMap()
1112
+ get: () => globalState
1113
+ });
1114
+ Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
1115
+ configurable: true,
1116
+ get: () => ({
1117
+ state: globalState.get(globalThis[GLOBAL_EXPECT]),
1118
+ matchers
1119
+ })
1071
1120
  });
1072
1121
  }
1073
1122
  const getState = (expect) => globalThis[MATCHERS_OBJECT].get(expect);
@@ -1081,6 +1130,7 @@ const JestChaiExpect = (chai, utils) => {
1081
1130
  function def(name, fn) {
1082
1131
  const addMethod = (n) => {
1083
1132
  utils.addMethod(chai.Assertion.prototype, n, fn);
1133
+ utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, n, fn);
1084
1134
  };
1085
1135
  if (Array.isArray(name))
1086
1136
  name.forEach((n) => addMethod(n));
@@ -1118,43 +1168,85 @@ const JestChaiExpect = (chai, utils) => {
1118
1168
  });
1119
1169
  def("toEqual", function(expected) {
1120
1170
  const actual = utils.flag(this, "object");
1121
- const equal = equals(actual, expected, [iterableEquality]);
1122
- return this.assert(equal, "expected #{this} to deeply equal #{exp}", "expected #{this} to not deeply equal #{exp}", expected, actual);
1171
+ const equal = equals(
1172
+ actual,
1173
+ expected,
1174
+ [iterableEquality]
1175
+ );
1176
+ return this.assert(
1177
+ equal,
1178
+ "expected #{this} to deeply equal #{exp}",
1179
+ "expected #{this} to not deeply equal #{exp}",
1180
+ expected,
1181
+ actual
1182
+ );
1123
1183
  });
1124
1184
  def("toStrictEqual", function(expected) {
1125
1185
  const obj = utils.flag(this, "object");
1126
- const equal = equals(obj, expected, [
1127
- iterableEquality,
1128
- typeEquality,
1129
- sparseArrayEquality,
1130
- arrayBufferEquality
1131
- ], true);
1132
- return this.assert(equal, "expected #{this} to strictly equal #{exp}", "expected #{this} to not strictly equal #{exp}", expected, obj);
1186
+ const equal = equals(
1187
+ obj,
1188
+ expected,
1189
+ [
1190
+ iterableEquality,
1191
+ typeEquality,
1192
+ sparseArrayEquality,
1193
+ arrayBufferEquality
1194
+ ],
1195
+ true
1196
+ );
1197
+ return this.assert(
1198
+ equal,
1199
+ "expected #{this} to strictly equal #{exp}",
1200
+ "expected #{this} to not strictly equal #{exp}",
1201
+ expected,
1202
+ obj
1203
+ );
1133
1204
  });
1134
1205
  def("toBe", function(expected) {
1135
1206
  const actual = this._obj;
1136
1207
  const pass = Object.is(actual, expected);
1137
1208
  let deepEqualityName = "";
1138
1209
  if (!pass) {
1139
- const toStrictEqualPass = equals(actual, expected, [
1140
- iterableEquality,
1141
- typeEquality,
1142
- sparseArrayEquality,
1143
- arrayBufferEquality
1144
- ], true);
1210
+ const toStrictEqualPass = equals(
1211
+ actual,
1212
+ expected,
1213
+ [
1214
+ iterableEquality,
1215
+ typeEquality,
1216
+ sparseArrayEquality,
1217
+ arrayBufferEquality
1218
+ ],
1219
+ true
1220
+ );
1145
1221
  if (toStrictEqualPass) {
1146
1222
  deepEqualityName = "toStrictEqual";
1147
1223
  } else {
1148
- const toEqualPass = equals(actual, expected, [iterableEquality]);
1224
+ const toEqualPass = equals(
1225
+ actual,
1226
+ expected,
1227
+ [iterableEquality]
1228
+ );
1149
1229
  if (toEqualPass)
1150
1230
  deepEqualityName = "toEqual";
1151
1231
  }
1152
1232
  }
1153
- return this.assert(pass, generateToBeMessage(deepEqualityName), "expected #{this} not to be #{exp} // Object.is equality", expected, actual);
1233
+ return this.assert(
1234
+ pass,
1235
+ generateToBeMessage(deepEqualityName),
1236
+ "expected #{this} not to be #{exp} // Object.is equality",
1237
+ expected,
1238
+ actual
1239
+ );
1154
1240
  });
1155
1241
  def("toMatchObject", function(expected) {
1156
1242
  const actual = this._obj;
1157
- return this.assert(equals(actual, expected, [iterableEquality, subsetEquality]), "expected #{this} to match object #{exp}", "expected #{this} to not match object #{exp}", expected, actual);
1243
+ return this.assert(
1244
+ equals(actual, expected, [iterableEquality, subsetEquality]),
1245
+ "expected #{this} to match object #{exp}",
1246
+ "expected #{this} to not match object #{exp}",
1247
+ expected,
1248
+ actual
1249
+ );
1158
1250
  });
1159
1251
  def("toMatch", function(expected) {
1160
1252
  if (typeof expected === "string")
@@ -1170,39 +1262,78 @@ const JestChaiExpect = (chai, utils) => {
1170
1262
  const index = Array.from(obj).findIndex((item) => {
1171
1263
  return equals(item, expected);
1172
1264
  });
1173
- this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
1265
+ this.assert(
1266
+ index !== -1,
1267
+ "expected #{this} to deep equally contain #{exp}",
1268
+ "expected #{this} to not deep equally contain #{exp}",
1269
+ expected
1270
+ );
1174
1271
  });
1175
1272
  def("toBeTruthy", function() {
1176
1273
  const obj = utils.flag(this, "object");
1177
- this.assert(Boolean(obj), "expected #{this} to be truthy", "expected #{this} to not be truthy", obj);
1274
+ this.assert(
1275
+ Boolean(obj),
1276
+ "expected #{this} to be truthy",
1277
+ "expected #{this} to not be truthy",
1278
+ obj
1279
+ );
1178
1280
  });
1179
1281
  def("toBeFalsy", function() {
1180
1282
  const obj = utils.flag(this, "object");
1181
- this.assert(!obj, "expected #{this} to be falsy", "expected #{this} to not be falsy", obj);
1283
+ this.assert(
1284
+ !obj,
1285
+ "expected #{this} to be falsy",
1286
+ "expected #{this} to not be falsy",
1287
+ obj
1288
+ );
1182
1289
  });
1183
1290
  def("toBeGreaterThan", function(expected) {
1184
1291
  const actual = this._obj;
1185
1292
  assertTypes(actual, "actual", ["number", "bigint"]);
1186
1293
  assertTypes(expected, "expected", ["number", "bigint"]);
1187
- return this.assert(actual > expected, `expected ${actual} to be greater than ${expected}`, `expected ${actual} to be not greater than ${expected}`, actual, expected);
1294
+ return this.assert(
1295
+ actual > expected,
1296
+ `expected ${actual} to be greater than ${expected}`,
1297
+ `expected ${actual} to be not greater than ${expected}`,
1298
+ actual,
1299
+ expected
1300
+ );
1188
1301
  });
1189
1302
  def("toBeGreaterThanOrEqual", function(expected) {
1190
1303
  const actual = this._obj;
1191
1304
  assertTypes(actual, "actual", ["number", "bigint"]);
1192
1305
  assertTypes(expected, "expected", ["number", "bigint"]);
1193
- return this.assert(actual >= expected, `expected ${actual} to be greater than or equal to ${expected}`, `expected ${actual} to be not greater than or equal to ${expected}`, actual, expected);
1306
+ return this.assert(
1307
+ actual >= expected,
1308
+ `expected ${actual} to be greater than or equal to ${expected}`,
1309
+ `expected ${actual} to be not greater than or equal to ${expected}`,
1310
+ actual,
1311
+ expected
1312
+ );
1194
1313
  });
1195
1314
  def("toBeLessThan", function(expected) {
1196
1315
  const actual = this._obj;
1197
1316
  assertTypes(actual, "actual", ["number", "bigint"]);
1198
1317
  assertTypes(expected, "expected", ["number", "bigint"]);
1199
- return this.assert(actual < expected, `expected ${actual} to be less than ${expected}`, `expected ${actual} to be not less than ${expected}`, actual, expected);
1318
+ return this.assert(
1319
+ actual < expected,
1320
+ `expected ${actual} to be less than ${expected}`,
1321
+ `expected ${actual} to be not less than ${expected}`,
1322
+ actual,
1323
+ expected
1324
+ );
1200
1325
  });
1201
1326
  def("toBeLessThanOrEqual", function(expected) {
1202
1327
  const actual = this._obj;
1203
1328
  assertTypes(actual, "actual", ["number", "bigint"]);
1204
1329
  assertTypes(expected, "expected", ["number", "bigint"]);
1205
- return this.assert(actual <= expected, `expected ${actual} to be less than or equal to ${expected}`, `expected ${actual} to be not less than or equal to ${expected}`, actual, expected);
1330
+ return this.assert(
1331
+ actual <= expected,
1332
+ `expected ${actual} to be less than or equal to ${expected}`,
1333
+ `expected ${actual} to be not less than or equal to ${expected}`,
1334
+ actual,
1335
+ expected
1336
+ );
1206
1337
  });
1207
1338
  def("toBeNaN", function() {
1208
1339
  return this.be.NaN;
@@ -1223,7 +1354,13 @@ const JestChaiExpect = (chai, utils) => {
1223
1354
  def("toBeTypeOf", function(expected) {
1224
1355
  const actual = typeof this._obj;
1225
1356
  const equal = expected === actual;
1226
- return this.assert(equal, "expected #{this} to be type of #{exp}", "expected #{this} not to be type of #{exp}", expected, actual);
1357
+ return this.assert(
1358
+ equal,
1359
+ "expected #{this} to be type of #{exp}",
1360
+ "expected #{this} not to be type of #{exp}",
1361
+ expected,
1362
+ actual
1363
+ );
1227
1364
  });
1228
1365
  def("toBeInstanceOf", function(obj) {
1229
1366
  return this.instanceOf(obj);
@@ -1236,14 +1373,21 @@ const JestChaiExpect = (chai, utils) => {
1236
1373
  args[0] = args[0].map((key) => key.replace(/([.[\]])/g, "\\$1")).join(".");
1237
1374
  const actual = this._obj;
1238
1375
  const [propertyName, expected] = args;
1239
- let pass = false;
1240
- if (Object.prototype.hasOwnProperty.call(actual, propertyName)) {
1241
- pass = true;
1242
- } else {
1243
- const { value, exists } = utils.getPathInfo(actual, propertyName);
1244
- pass = exists && (args.length === 1 || equals(expected, value));
1245
- }
1246
- return this.assert(pass, "expected #{this} to have property #{exp}", "expected #{this} to not have property #{exp}", expected, actual);
1376
+ const getValue = () => {
1377
+ const hasOwn = Object.prototype.hasOwnProperty.call(actual, propertyName);
1378
+ if (hasOwn)
1379
+ return { value: actual[propertyName], exists: true };
1380
+ return utils.getPathInfo(actual, propertyName);
1381
+ };
1382
+ const { value, exists } = getValue();
1383
+ const pass = exists && (args.length === 1 || equals(expected, value));
1384
+ const valueString = args.length === 1 ? "" : ` with value ${utils.objDisplay(expected)}`;
1385
+ return this.assert(
1386
+ pass,
1387
+ `expected #{this} to have property "${propertyName}"${valueString}`,
1388
+ `expected #{this} to not have property "${propertyName}"${valueString}`,
1389
+ actual
1390
+ );
1247
1391
  });
1248
1392
  def("toBeCloseTo", function(received, precision = 2) {
1249
1393
  const expected = this._obj;
@@ -1259,7 +1403,13 @@ const JestChaiExpect = (chai, utils) => {
1259
1403
  receivedDiff = Math.abs(expected - received);
1260
1404
  pass = receivedDiff < expectedDiff;
1261
1405
  }
1262
- return this.assert(pass, `expected #{this} to be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`, `expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`, received, expected);
1406
+ return this.assert(
1407
+ pass,
1408
+ `expected #{this} to be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
1409
+ `expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
1410
+ received,
1411
+ expected
1412
+ );
1263
1413
  });
1264
1414
  const assertIsMock = (assertion) => {
1265
1415
  if (!isMockFunction(assertion._obj))
@@ -1305,26 +1455,41 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1305
1455
  const spy = getSpy(this);
1306
1456
  const spyName = spy.getMockName();
1307
1457
  const callCount = spy.mock.calls.length;
1308
- return this.assert(callCount === number, `expected "${spyName}" to be called #{exp} times`, `expected "${spyName}" to not be called #{exp} times`, number, callCount);
1458
+ return this.assert(
1459
+ callCount === number,
1460
+ `expected "${spyName}" to be called #{exp} times`,
1461
+ `expected "${spyName}" to not be called #{exp} times`,
1462
+ number,
1463
+ callCount
1464
+ );
1309
1465
  });
1310
1466
  def("toHaveBeenCalledOnce", function() {
1311
1467
  const spy = getSpy(this);
1312
1468
  const spyName = spy.getMockName();
1313
1469
  const callCount = spy.mock.calls.length;
1314
- return this.assert(callCount === 1, `expected "${spyName}" to be called once`, `expected "${spyName}" to not be called once`, 1, callCount);
1470
+ return this.assert(
1471
+ callCount === 1,
1472
+ `expected "${spyName}" to be called once`,
1473
+ `expected "${spyName}" to not be called once`,
1474
+ 1,
1475
+ callCount
1476
+ );
1315
1477
  });
1316
1478
  def(["toHaveBeenCalled", "toBeCalled"], function() {
1317
1479
  const spy = getSpy(this);
1318
1480
  const spyName = spy.getMockName();
1319
1481
  const called = spy.mock.calls.length > 0;
1320
1482
  const isNot = utils.flag(this, "negate");
1321
- let msg = utils.getMessage(this, [
1322
- called,
1323
- `expected "${spyName}" to be called at least once`,
1324
- `expected "${spyName}" to not be called at all`,
1325
- true,
1326
- called
1327
- ]);
1483
+ let msg = utils.getMessage(
1484
+ this,
1485
+ [
1486
+ called,
1487
+ `expected "${spyName}" to be called at least once`,
1488
+ `expected "${spyName}" to not be called at all`,
1489
+ true,
1490
+ called
1491
+ ]
1492
+ );
1328
1493
  if (called && isNot)
1329
1494
  msg += formatCalls(spy, msg);
1330
1495
  if (called && isNot || !called && !isNot) {
@@ -1338,12 +1503,15 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1338
1503
  const spyName = spy.getMockName();
1339
1504
  const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
1340
1505
  const isNot = utils.flag(this, "negate");
1341
- let msg = utils.getMessage(this, [
1342
- pass,
1343
- `expected "${spyName}" to be called with arguments: #{exp}`,
1344
- `expected "${spyName}" to not be called with arguments: #{exp}`,
1345
- args
1346
- ]);
1506
+ let msg = utils.getMessage(
1507
+ this,
1508
+ [
1509
+ pass,
1510
+ `expected "${spyName}" to be called with arguments: #{exp}`,
1511
+ `expected "${spyName}" to not be called with arguments: #{exp}`,
1512
+ args
1513
+ ]
1514
+ );
1347
1515
  if (pass && isNot || !pass && !isNot) {
1348
1516
  msg += formatCalls(spy, msg, args);
1349
1517
  const err = new Error(msg);
@@ -1355,13 +1523,25 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1355
1523
  const spy = getSpy(this);
1356
1524
  const spyName = spy.getMockName();
1357
1525
  const nthCall = spy.mock.calls[times - 1];
1358
- this.assert(equals(nthCall, args, [iterableEquality]), `expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`, `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`, args, nthCall);
1526
+ this.assert(
1527
+ equals(nthCall, args, [iterableEquality]),
1528
+ `expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`,
1529
+ `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`,
1530
+ args,
1531
+ nthCall
1532
+ );
1359
1533
  });
1360
1534
  def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
1361
1535
  const spy = getSpy(this);
1362
1536
  const spyName = spy.getMockName();
1363
1537
  const lastCall = spy.mock.calls[spy.calls.length - 1];
1364
- this.assert(equals(lastCall, args, [iterableEquality]), `expected last "${spyName}" call to have been called with #{exp}`, `expected last "${spyName}" call to not have been called with #{exp}`, args, lastCall);
1538
+ this.assert(
1539
+ equals(lastCall, args, [iterableEquality]),
1540
+ `expected last "${spyName}" call to have been called with #{exp}`,
1541
+ `expected last "${spyName}" call to not have been called with #{exp}`,
1542
+ args,
1543
+ lastCall
1544
+ );
1365
1545
  });
1366
1546
  def(["toThrow", "toThrowError"], function(expected) {
1367
1547
  if (typeof expected === "string" || typeof expected === "undefined" || expected instanceof RegExp)
@@ -1391,14 +1571,32 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1391
1571
  }
1392
1572
  if (typeof expected === "function") {
1393
1573
  const name = expected.name || expected.prototype.constructor.name;
1394
- return this.assert(thrown && thrown instanceof expected, `expected error to be instance of ${name}`, `expected error not to be instance of ${name}`, expected, thrown);
1574
+ return this.assert(
1575
+ thrown && thrown instanceof expected,
1576
+ `expected error to be instance of ${name}`,
1577
+ `expected error not to be instance of ${name}`,
1578
+ expected,
1579
+ thrown
1580
+ );
1395
1581
  }
1396
1582
  if (expected instanceof Error) {
1397
- return this.assert(thrown && expected.message === thrown.message, `expected error to have message: ${expected.message}`, `expected error not to have message: ${expected.message}`, expected.message, thrown && thrown.message);
1583
+ return this.assert(
1584
+ thrown && expected.message === thrown.message,
1585
+ `expected error to have message: ${expected.message}`,
1586
+ `expected error not to have message: ${expected.message}`,
1587
+ expected.message,
1588
+ thrown && thrown.message
1589
+ );
1398
1590
  }
1399
1591
  if (typeof expected.asymmetricMatch === "function") {
1400
1592
  const matcher = expected;
1401
- return this.assert(thrown && matcher.asymmetricMatch(thrown), "expected error to match asymmetric matcher", "expected error not to match asymmetric matcher", matcher.toString(), thrown);
1593
+ return this.assert(
1594
+ thrown && matcher.asymmetricMatch(thrown),
1595
+ "expected error to match asymmetric matcher",
1596
+ "expected error not to match asymmetric matcher",
1597
+ matcher.toString(),
1598
+ thrown
1599
+ );
1402
1600
  }
1403
1601
  throw new Error(`"toThrow" expects string, RegExp, function, Error instance or asymmetric matcher, got "${typeof expected}"`);
1404
1602
  });
@@ -1406,26 +1604,49 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1406
1604
  const spy = getSpy(this);
1407
1605
  const spyName = spy.getMockName();
1408
1606
  const calledAndNotThrew = spy.mock.calls.length > 0 && !spy.mock.results.some(({ type }) => type === "throw");
1409
- this.assert(calledAndNotThrew, `expected "${spyName}" to be successfully called at least once`, `expected "${spyName}" to not be successfully called`, calledAndNotThrew, !calledAndNotThrew);
1607
+ this.assert(
1608
+ calledAndNotThrew,
1609
+ `expected "${spyName}" to be successfully called at least once`,
1610
+ `expected "${spyName}" to not be successfully called`,
1611
+ calledAndNotThrew,
1612
+ !calledAndNotThrew
1613
+ );
1410
1614
  });
1411
1615
  def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
1412
1616
  const spy = getSpy(this);
1413
1617
  const spyName = spy.getMockName();
1414
1618
  const successfulReturns = spy.mock.results.reduce((success, { type }) => type === "throw" ? success : ++success, 0);
1415
- this.assert(successfulReturns === times, `expected "${spyName}" to be successfully called ${times} times`, `expected "${spyName}" to not be successfully called ${times} times`, `expected number of returns: ${times}`, `received number of returns: ${successfulReturns}`);
1619
+ this.assert(
1620
+ successfulReturns === times,
1621
+ `expected "${spyName}" to be successfully called ${times} times`,
1622
+ `expected "${spyName}" to not be successfully called ${times} times`,
1623
+ `expected number of returns: ${times}`,
1624
+ `received number of returns: ${successfulReturns}`
1625
+ );
1416
1626
  });
1417
1627
  def(["toHaveReturnedWith", "toReturnWith"], function(value) {
1418
1628
  const spy = getSpy(this);
1419
1629
  const spyName = spy.getMockName();
1420
1630
  const pass = spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result));
1421
- this.assert(pass, `expected "${spyName}" to be successfully called with #{exp}`, `expected "${spyName}" to not be successfully called with #{exp}`, value);
1631
+ this.assert(
1632
+ pass,
1633
+ `expected "${spyName}" to be successfully called with #{exp}`,
1634
+ `expected "${spyName}" to not be successfully called with #{exp}`,
1635
+ value
1636
+ );
1422
1637
  });
1423
1638
  def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
1424
1639
  const spy = getSpy(this);
1425
1640
  const spyName = spy.getMockName();
1426
1641
  const { value: lastResult } = spy.mock.results[spy.returns.length - 1];
1427
1642
  const pass = equals(lastResult, value);
1428
- this.assert(pass, `expected last "${spyName}" call to return #{exp}`, `expected last "${spyName}" call to not return #{exp}`, value, lastResult);
1643
+ this.assert(
1644
+ pass,
1645
+ `expected last "${spyName}" call to return #{exp}`,
1646
+ `expected last "${spyName}" call to not return #{exp}`,
1647
+ value,
1648
+ lastResult
1649
+ );
1429
1650
  });
1430
1651
  def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
1431
1652
  const spy = getSpy(this);
@@ -1436,7 +1657,13 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1436
1657
  if (!isNot && callType === "throw")
1437
1658
  chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
1438
1659
  const nthCallReturn = equals(callResult, value);
1439
- this.assert(nthCallReturn, `expected ${ordinalCall} "${spyName}" call to return #{exp}`, `expected ${ordinalCall} "${spyName}" call to not return #{exp}`, value, callResult);
1660
+ this.assert(
1661
+ nthCallReturn,
1662
+ `expected ${ordinalCall} "${spyName}" call to return #{exp}`,
1663
+ `expected ${ordinalCall} "${spyName}" call to not return #{exp}`,
1664
+ value,
1665
+ callResult
1666
+ );
1440
1667
  });
1441
1668
  def("toSatisfy", function(matcher, message) {
1442
1669
  return this.be.satisfy(matcher, message);
@@ -1453,12 +1680,15 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1453
1680
  if (typeof result !== "function")
1454
1681
  return result instanceof chai.Assertion ? proxy : result;
1455
1682
  return async (...args) => {
1456
- return obj.then((value) => {
1457
- utils.flag(this, "object", value);
1458
- return result.call(this, ...args);
1459
- }, (err) => {
1460
- throw new Error(`promise rejected "${toString(err)}" instead of resolving`);
1461
- });
1683
+ return obj.then(
1684
+ (value) => {
1685
+ utils.flag(this, "object", value);
1686
+ return result.call(this, ...args);
1687
+ },
1688
+ (err) => {
1689
+ throw new Error(`promise rejected "${toString(err)}" instead of resolving`);
1690
+ }
1691
+ );
1462
1692
  };
1463
1693
  }
1464
1694
  });
@@ -1477,18 +1707,25 @@ Number of calls: ${picocolors.exports.bold(spy.mock.calls.length)}
1477
1707
  if (typeof result !== "function")
1478
1708
  return result instanceof chai.Assertion ? proxy : result;
1479
1709
  return async (...args) => {
1480
- return wrapper.then((value) => {
1481
- throw new Error(`promise resolved "${toString(value)}" instead of rejecting`);
1482
- }, (err) => {
1483
- utils.flag(this, "object", err);
1484
- return result.call(this, ...args);
1485
- });
1710
+ return wrapper.then(
1711
+ (value) => {
1712
+ throw new Error(`promise resolved "${toString(value)}" instead of rejecting`);
1713
+ },
1714
+ (err) => {
1715
+ utils.flag(this, "object", err);
1716
+ return result.call(this, ...args);
1717
+ }
1718
+ );
1486
1719
  };
1487
1720
  }
1488
1721
  });
1489
1722
  return proxy;
1490
1723
  });
1491
- utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
1724
+ utils.addMethod(
1725
+ chai.expect,
1726
+ "addSnapshotSerializer",
1727
+ addSerializer
1728
+ );
1492
1729
  };
1493
1730
  function toString(value) {
1494
1731
  try {
@@ -1561,7 +1798,9 @@ class ObjectContaining extends AsymmetricMatcher {
1561
1798
  }
1562
1799
  asymmetricMatch(other) {
1563
1800
  if (typeof this.sample !== "object") {
1564
- throw new TypeError(`You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`);
1801
+ throw new TypeError(
1802
+ `You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`
1803
+ );
1565
1804
  }
1566
1805
  let result = true;
1567
1806
  for (const property in this.sample) {
@@ -1585,9 +1824,13 @@ class ArrayContaining extends AsymmetricMatcher {
1585
1824
  }
1586
1825
  asymmetricMatch(other) {
1587
1826
  if (!Array.isArray(this.sample)) {
1588
- throw new TypeError(`You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`);
1827
+ throw new TypeError(
1828
+ `You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`
1829
+ );
1589
1830
  }
1590
- const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every((item) => other.some((another) => equals(item, another)));
1831
+ const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every(
1832
+ (item) => other.some((another) => equals(item, another))
1833
+ );
1591
1834
  return this.inverse ? !result : result;
1592
1835
  }
1593
1836
  toString() {
@@ -1600,7 +1843,9 @@ class ArrayContaining extends AsymmetricMatcher {
1600
1843
  class Any extends AsymmetricMatcher {
1601
1844
  constructor(sample) {
1602
1845
  if (typeof sample === "undefined") {
1603
- throw new TypeError("any() expects to be passed a constructor function. Please pass one or use anything() to match any object.");
1846
+ throw new TypeError(
1847
+ "any() expects to be passed a constructor function. Please pass one or use anything() to match any object."
1848
+ );
1604
1849
  }
1605
1850
  super(sample);
1606
1851
  }
@@ -1666,12 +1911,36 @@ class StringMatching extends AsymmetricMatcher {
1666
1911
  }
1667
1912
  }
1668
1913
  const JestAsymmetricMatchers = (chai, utils) => {
1669
- utils.addMethod(chai.expect, "anything", () => new Anything());
1670
- utils.addMethod(chai.expect, "any", (expected) => new Any(expected));
1671
- utils.addMethod(chai.expect, "stringContaining", (expected) => new StringContaining(expected));
1672
- utils.addMethod(chai.expect, "objectContaining", (expected) => new ObjectContaining(expected));
1673
- utils.addMethod(chai.expect, "arrayContaining", (expected) => new ArrayContaining(expected));
1674
- utils.addMethod(chai.expect, "stringMatching", (expected) => new StringMatching(expected));
1914
+ utils.addMethod(
1915
+ chai.expect,
1916
+ "anything",
1917
+ () => new Anything()
1918
+ );
1919
+ utils.addMethod(
1920
+ chai.expect,
1921
+ "any",
1922
+ (expected) => new Any(expected)
1923
+ );
1924
+ utils.addMethod(
1925
+ chai.expect,
1926
+ "stringContaining",
1927
+ (expected) => new StringContaining(expected)
1928
+ );
1929
+ utils.addMethod(
1930
+ chai.expect,
1931
+ "objectContaining",
1932
+ (expected) => new ObjectContaining(expected)
1933
+ );
1934
+ utils.addMethod(
1935
+ chai.expect,
1936
+ "arrayContaining",
1937
+ (expected) => new ArrayContaining(expected)
1938
+ );
1939
+ utils.addMethod(
1940
+ chai.expect,
1941
+ "stringMatching",
1942
+ (expected) => new StringMatching(expected)
1943
+ );
1675
1944
  chai.expect.not = {
1676
1945
  stringContaining: (expected) => new StringContaining(expected, true),
1677
1946
  objectContaining: (expected) => new ObjectContaining(expected, true),
@@ -1728,13 +1997,18 @@ function JestExtendPlugin(expect, matchers) {
1728
1997
  throw new JestExtendError(message(), actual, expected);
1729
1998
  }
1730
1999
  const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
2000
+ utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, expectAssertionWrapper);
1731
2001
  utils.addMethod(c.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
1732
2002
  class CustomMatcher extends AsymmetricMatcher {
1733
2003
  constructor(inverse = false, ...sample) {
1734
2004
  super(sample, inverse);
1735
2005
  }
1736
2006
  asymmetricMatch(other) {
1737
- const { pass } = expectAssertion.call(this.getMatcherContext(expect), other, ...this.sample);
2007
+ const { pass } = expectAssertion.call(
2008
+ this.getMatcherContext(expect),
2009
+ other,
2010
+ ...this.sample
2011
+ );
1738
2012
  return this.inverse ? !pass : pass;
1739
2013
  }
1740
2014
  toString() {
@@ -1774,6 +2048,7 @@ chai$2.use(Subset);
1774
2048
  chai$2.use(SnapshotPlugin);
1775
2049
  chai$2.use(JestAsymmetricMatchers);
1776
2050
 
2051
+ const workerState$1 = getWorkerState();
1777
2052
  function createExpect(test) {
1778
2053
  var _a;
1779
2054
  const expect = (value, message) => {
@@ -1794,6 +2069,7 @@ function createExpect(test) {
1794
2069
  isExpectingAssertionsError: null,
1795
2070
  expectedAssertionsNumber: null,
1796
2071
  expectedAssertionsNumberErrorGen: null,
2072
+ environment: workerState$1.config.environment,
1797
2073
  testPath: (_a = test == null ? void 0 : test.suite.file) == null ? void 0 : _a.filepath,
1798
2074
  currentTestName: test ? getFullName(test) : void 0
1799
2075
  }, expect);
@@ -1888,6 +2164,7 @@ If this is a long-running test, pass a timeout value as the last argument or con
1888
2164
 
1889
2165
  const fnMap = /* @__PURE__ */ new WeakMap();
1890
2166
  const hooksMap = /* @__PURE__ */ new WeakMap();
2167
+ const benchmarkMap = /* @__PURE__ */ new WeakMap();
1891
2168
  function setFn(key, fn) {
1892
2169
  fnMap.set(key, fn);
1893
2170
  }
@@ -1900,11 +2177,29 @@ function setHooks(key, hooks) {
1900
2177
  function getHooks(key) {
1901
2178
  return hooksMap.get(key);
1902
2179
  }
2180
+ async function getBenchmarkFactory(key) {
2181
+ let benchmark = benchmarkMap.get(key);
2182
+ if (!benchmark) {
2183
+ if (!globalThis.EventTarget)
2184
+ await import('./vendor-index.0557b03a.mjs').then(function (n) { return n.i; });
2185
+ const Bench = (await import('tinybench')).default;
2186
+ benchmark = new Bench({});
2187
+ benchmarkMap.set(key, benchmark);
2188
+ }
2189
+ return benchmark;
2190
+ }
1903
2191
 
1904
2192
  const suite = createSuite();
1905
- const test = createTest(function(name, fn, timeout) {
1906
- getCurrentSuite().test.fn.call(this, name, fn, timeout);
1907
- });
2193
+ const test = createTest(
2194
+ function(name, fn, options) {
2195
+ getCurrentSuite().test.fn.call(this, name, fn, options);
2196
+ }
2197
+ );
2198
+ const bench = createBenchmark(
2199
+ function(name, fn, options) {
2200
+ getCurrentSuite().benchmark.fn.call(this, name, fn, options);
2201
+ }
2202
+ );
1908
2203
  function formatTitle(template, items, idx) {
1909
2204
  if (template.includes("%#")) {
1910
2205
  template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
@@ -1944,15 +2239,20 @@ function createSuiteCollector(name, factory = () => {
1944
2239
  const factoryQueue = [];
1945
2240
  let suite2;
1946
2241
  initSuite();
1947
- const test2 = createTest(function(name2, fn = noop, timeout) {
2242
+ const test2 = createTest(function(name2, fn = noop, options) {
2243
+ if (!isRunningInTest())
2244
+ throw new Error("`test()` and `it()` is only available in test mode.");
1948
2245
  const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
2246
+ if (typeof options === "number")
2247
+ options = { timeout: options };
1949
2248
  const test3 = {
1950
2249
  id: "",
1951
2250
  type: "test",
1952
2251
  name: name2,
1953
2252
  mode: mode2,
1954
2253
  suite: void 0,
1955
- fails: this.fails
2254
+ fails: this.fails,
2255
+ retry: options == null ? void 0 : options.retry
1956
2256
  };
1957
2257
  if (this.concurrent || concurrent)
1958
2258
  test3.concurrent = true;
@@ -1963,15 +2263,34 @@ function createSuiteCollector(name, factory = () => {
1963
2263
  value: context,
1964
2264
  enumerable: false
1965
2265
  });
1966
- setFn(test3, withTimeout(() => fn(context), timeout));
2266
+ setFn(test3, withTimeout(
2267
+ () => fn(context),
2268
+ options == null ? void 0 : options.timeout
2269
+ ));
1967
2270
  tasks.push(test3);
1968
2271
  });
2272
+ const benchmark = createBenchmark(function(name2, fn = noop, options) {
2273
+ const mode2 = this.skip ? "skip" : "run";
2274
+ if (!isRunningInBenchmark())
2275
+ throw new Error("`bench()` is only available in benchmark mode. Run with `vitest bench` instead.");
2276
+ const benchmark2 = {
2277
+ type: "benchmark",
2278
+ id: "",
2279
+ name: name2,
2280
+ mode: mode2,
2281
+ options,
2282
+ suite: void 0
2283
+ };
2284
+ setFn(benchmark2, fn);
2285
+ tasks.push(benchmark2);
2286
+ });
1969
2287
  const collector = {
1970
2288
  type: "collector",
1971
2289
  name,
1972
2290
  mode,
1973
2291
  test: test2,
1974
2292
  tasks,
2293
+ benchmark,
1975
2294
  collect,
1976
2295
  clear,
1977
2296
  on: addHook
@@ -2030,22 +2349,37 @@ function createSuite() {
2030
2349
  };
2031
2350
  suiteFn.skipIf = (condition) => condition ? suite.skip : suite;
2032
2351
  suiteFn.runIf = (condition) => condition ? suite : suite.skip;
2033
- return createChainable(["concurrent", "shuffle", "skip", "only", "todo"], suiteFn);
2352
+ return createChainable(
2353
+ ["concurrent", "shuffle", "skip", "only", "todo"],
2354
+ suiteFn
2355
+ );
2034
2356
  }
2035
2357
  function createTest(fn) {
2036
2358
  const testFn = fn;
2037
2359
  testFn.each = function(cases) {
2038
2360
  const test2 = this.withContext();
2039
- return (name, fn2, timeout) => {
2361
+ return (name, fn2, options) => {
2040
2362
  cases.forEach((i, idx) => {
2041
2363
  const items = Array.isArray(i) ? i : [i];
2042
- test2(formatTitle(name, items, idx), () => fn2(...items), timeout);
2364
+ test2(formatTitle(name, items, idx), () => fn2(...items), options);
2043
2365
  });
2044
2366
  };
2045
2367
  };
2046
2368
  testFn.skipIf = (condition) => condition ? test.skip : test;
2047
2369
  testFn.runIf = (condition) => condition ? test : test.skip;
2048
- return createChainable(["concurrent", "skip", "only", "todo", "fails"], testFn);
2370
+ return createChainable(
2371
+ ["concurrent", "skip", "only", "todo", "fails"],
2372
+ testFn
2373
+ );
2374
+ }
2375
+ function createBenchmark(fn) {
2376
+ const benchmark = createChainable(
2377
+ ["skip"],
2378
+ fn
2379
+ );
2380
+ benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
2381
+ benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
2382
+ return benchmark;
2049
2383
  }
2050
2384
 
2051
- export { GLOBAL_EXPECT as G, getDefaultHookTimeout as a, globalExpect as b, createExpect as c, describe as d, clearCollectorContext as e, defaultSuite as f, getCurrentSuite as g, setHooks as h, it as i, getHooks as j, collectorContext as k, setState as l, getFn as m, getState as n, createSuiteHooks as o, chai$1 as p, suite as s, test as t, withTimeout as w };
2385
+ export { GLOBAL_EXPECT as G, getDefaultHookTimeout as a, bench as b, createExpect as c, describe as d, globalExpect as e, clearCollectorContext as f, getCurrentSuite as g, defaultSuite as h, it as i, setHooks as j, getHooks as k, collectorContext as l, getBenchmarkFactory as m, getFn as n, setState as o, getState as p, createSuiteHooks as q, chai$1 as r, suite as s, test as t, withTimeout as w };