@noma.to/qwik-testing-library 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/lib/mock.qwik.cjs +3 -3
  2. package/lib/lib/mock.qwik.mjs +1 -1
  3. package/lib/lib/qwik-testing-library.qwik.cjs +2 -2
  4. package/lib/lib/qwik-testing-library.qwik.mjs +3 -3
  5. package/lib/lib/qwikloader.qwik.cjs +1 -1
  6. package/lib/lib/qwikloader.qwik.mjs +1 -1
  7. package/lib/node_modules/.pnpm/{@vitest_expect@2.1.8 → @vitest_expect@3.0.5}/node_modules/@vitest/expect/dist/index.qwik.cjs +175 -35
  8. package/lib/node_modules/.pnpm/{@vitest_expect@2.1.8 → @vitest_expect@3.0.5}/node_modules/@vitest/expect/dist/index.qwik.mjs +180 -40
  9. package/lib/node_modules/.pnpm/{@vitest_pretty-format@2.1.8 → @vitest_pretty-format@3.0.5}/node_modules/@vitest/pretty-format/dist/index.qwik.cjs +301 -10
  10. package/lib/node_modules/.pnpm/{@vitest_pretty-format@2.1.8 → @vitest_pretty-format@3.0.5}/node_modules/@vitest/pretty-format/dist/index.qwik.mjs +306 -15
  11. package/lib/node_modules/.pnpm/{@vitest_runner@2.1.8 → @vitest_runner@3.0.5}/node_modules/@vitest/runner/dist/chunk-tasks.qwik.cjs +1 -1
  12. package/lib/node_modules/.pnpm/{@vitest_runner@2.1.8 → @vitest_runner@3.0.5}/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs +1 -1
  13. package/lib/node_modules/.pnpm/{@vitest_runner@2.1.8 → @vitest_runner@3.0.5}/node_modules/@vitest/runner/dist/index.qwik.cjs +130 -44
  14. package/lib/node_modules/.pnpm/{@vitest_runner@2.1.8 → @vitest_runner@3.0.5}/node_modules/@vitest/runner/dist/index.qwik.mjs +130 -44
  15. package/lib/node_modules/.pnpm/{@vitest_snapshot@2.1.8 → @vitest_snapshot@3.0.5}/node_modules/@vitest/snapshot/dist/index.qwik.cjs +119 -84
  16. package/lib/node_modules/.pnpm/{@vitest_snapshot@2.1.8 → @vitest_snapshot@3.0.5}/node_modules/@vitest/snapshot/dist/index.qwik.mjs +119 -84
  17. package/lib/node_modules/.pnpm/{@vitest_spy@2.1.8 → @vitest_spy@3.0.5}/node_modules/@vitest/spy/dist/index.qwik.cjs +20 -3
  18. package/lib/node_modules/.pnpm/{@vitest_spy@2.1.8 → @vitest_spy@3.0.5}/node_modules/@vitest/spy/dist/index.qwik.mjs +20 -3
  19. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.cjs +3 -3
  20. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.mjs +3 -3
  21. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/diff.qwik.cjs +37 -21
  22. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/diff.qwik.mjs +37 -21
  23. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/error.qwik.cjs +2 -2
  24. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/error.qwik.mjs +2 -2
  25. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/helpers.qwik.cjs +1 -1
  26. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/helpers.qwik.mjs +1 -1
  27. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/index.qwik.cjs +6 -4
  28. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/index.qwik.mjs +6 -4
  29. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/source-map.qwik.cjs +1 -1
  30. package/lib/node_modules/.pnpm/{@vitest_utils@2.1.8 → @vitest_utils@3.0.5}/node_modules/@vitest/utils/dist/source-map.qwik.mjs +1 -1
  31. package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/index.qwik.mjs +6 -6
  32. package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/map.qwik.cjs +1 -3
  33. package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/map.qwik.mjs +1 -3
  34. package/lib/node_modules/.pnpm/{pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.cjs → pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.cjs} +2 -2
  35. package/lib/node_modules/.pnpm/{pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.mjs → pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.mjs} +2 -2
  36. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +4 -0
  37. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +5 -0
  38. package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0 → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0}/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.cjs +1 -1
  39. package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0 → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0}/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.mjs +1 -1
  40. package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.DgezovHB.qwik.cjs → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.cjs} +439 -211
  41. package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.DgezovHB.qwik.mjs → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.mjs} +415 -187
  42. package/package.json +8 -8
  43. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +0 -7
  44. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +0 -8
  45. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/arguments.qwik.cjs +0 -0
  46. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/arguments.qwik.mjs +0 -0
  47. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/array.qwik.cjs +0 -0
  48. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/array.qwik.mjs +0 -0
  49. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/bigint.qwik.cjs +0 -0
  50. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/bigint.qwik.mjs +0 -0
  51. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/class.qwik.cjs +0 -0
  52. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/class.qwik.mjs +0 -0
  53. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/date.qwik.cjs +0 -0
  54. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/date.qwik.mjs +0 -0
  55. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/error.qwik.cjs +0 -0
  56. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/error.qwik.mjs +0 -0
  57. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/function.qwik.cjs +0 -0
  58. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/function.qwik.mjs +0 -0
  59. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/helpers.qwik.cjs +0 -0
  60. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/helpers.qwik.mjs +0 -0
  61. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/html.qwik.cjs +0 -0
  62. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/html.qwik.mjs +0 -0
  63. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/index.qwik.cjs +0 -0
  64. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/number.qwik.cjs +0 -0
  65. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/number.qwik.mjs +0 -0
  66. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/object.qwik.cjs +0 -0
  67. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/object.qwik.mjs +0 -0
  68. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/promise.qwik.cjs +0 -0
  69. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/promise.qwik.mjs +0 -0
  70. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/regexp.qwik.cjs +0 -0
  71. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/regexp.qwik.mjs +0 -0
  72. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/set.qwik.cjs +0 -0
  73. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/set.qwik.mjs +0 -0
  74. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/string.qwik.cjs +0 -0
  75. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/string.qwik.mjs +0 -0
  76. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/symbol.qwik.cjs +0 -0
  77. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/symbol.qwik.mjs +0 -0
  78. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/typedarray.qwik.cjs +0 -0
  79. /package/lib/node_modules/.pnpm/{loupe@3.1.2 → loupe@3.1.3}/node_modules/loupe/lib/typedarray.qwik.mjs +0 -0
  80. /package/lib/node_modules/.pnpm/{tinyrainbow@1.2.0 → tinyrainbow@2.0.0}/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.cjs +0 -0
  81. /package/lib/node_modules/.pnpm/{tinyrainbow@1.2.0 → tinyrainbow@2.0.0}/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.mjs +0 -0
  82. /package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0 → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0}/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.cjs +0 -0
  83. /package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0 → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0}/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.mjs +0 -0
  84. /package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0 → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0}/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.cjs +0 -0
  85. /package/lib/node_modules/.pnpm/{vitest@2.1.8_@types_node@22.10.3_@vitest_ui@2.1.8_jsdom@26.0.0 → vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0}/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.mjs +0 -0
@@ -1,21 +1,21 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { GLOBAL_EXPECT, JestExtend, JestChaiExpect, JestAsymmetricMatchers, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, equals, iterableEquality, subsetEquality } from "../../../../../@vitest_expect@2.1.8/node_modules/@vitest/expect/dist/index.qwik.mjs";
5
- import "../../../../../@vitest_runner@2.1.8/node_modules/@vitest/runner/dist/index.qwik.mjs";
6
- import { e as getNames } from "../../../../../@vitest_runner@2.1.8/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs";
7
- import { getSafeTimers } from "../../../../../@vitest_utils@2.1.8/node_modules/@vitest/utils/dist/index.qwik.mjs";
4
+ import { GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers, JestExtend, JestChaiExpect, JestAsymmetricMatchers, equals, iterableEquality, subsetEquality } from "../../../../../@vitest_expect@3.0.5/node_modules/@vitest/expect/dist/index.qwik.mjs";
5
+ import "../../../../../@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/index.qwik.mjs";
6
+ import { f as getNames } from "../../../../../@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs";
7
+ import { getSafeTimers } from "../../../../../@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.mjs";
8
8
  import { use, expect, assert, util as utils_exports, Assertion } from "../../../../../chai@5.1.2/node_modules/chai/chai.qwik.mjs";
9
- import { a as getCurrentEnvironment, g as getWorkerState, i as isChildProcess, r as resetModules, w as waitForImportsToResolve } from "./utils.C8RiOc4B.qwik.mjs";
10
- import { g as getDefaultExportFromCjs, c as commonjsGlobal } from "./_commonjsHelpers.BFTU3MAI.qwik.mjs";
11
- import { stripSnapshotIndentation, addSerializer, SnapshotClient } from "../../../../../@vitest_snapshot@2.1.8/node_modules/@vitest/snapshot/dist/index.qwik.mjs";
12
- import { parseSingleStack } from "../../../../../@vitest_utils@2.1.8/node_modules/@vitest/utils/dist/source-map.qwik.mjs";
9
+ import { g as getWorkerState, w as waitForImportsToResolve, r as resetModules, i as isChildProcess, a as getCurrentEnvironment } from "./utils.C8RiOc4B.qwik.mjs";
10
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from "./_commonjsHelpers.BFTU3MAI.qwik.mjs";
11
+ import { stripSnapshotIndentation, addSerializer, SnapshotClient } from "../../../../../@vitest_snapshot@3.0.5/node_modules/@vitest/snapshot/dist/index.qwik.mjs";
12
+ import { parseSingleStack } from "../../../../../@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.mjs";
13
13
  import { R as RealDate, r as resetDate, m as mockDate } from "./date.W2xKR2qe.qwik.mjs";
14
- import { spyOn, fn, isMockFunction, mocks } from "../../../../../@vitest_spy@2.1.8/node_modules/@vitest/spy/dist/index.qwik.mjs";
15
- import { assertTypes, createSimpleStackTrace } from "../../../../../@vitest_utils@2.1.8/node_modules/@vitest/utils/dist/helpers.qwik.mjs";
14
+ import { fn, spyOn, mocks, isMockFunction } from "../../../../../@vitest_spy@3.0.5/node_modules/@vitest/spy/dist/index.qwik.mjs";
15
+ import { assertTypes, createSimpleStackTrace } from "../../../../../@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.mjs";
16
16
  const unsupported = [
17
17
  // .poll is meant to retry matchers until they succeed, and
18
- // snapshots will always succeed as long as the poll method doesn't thow an error
18
+ // snapshots will always succeed as long as the poll method doesn't throw an error
19
19
  // in this case using the `vi.waitFor` method is more appropriate
20
20
  "matchSnapshot",
21
21
  "toMatchSnapshot",
@@ -68,19 +68,9 @@ function createExpectPoll(expect2) {
68
68
  const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
69
69
  const promise = () => new Promise((resolve, reject) => {
70
70
  let intervalId;
71
+ let timeoutId;
71
72
  let lastError;
72
73
  const { setTimeout, clearTimeout } = getSafeTimers();
73
- const timeoutId = setTimeout(() => {
74
- clearTimeout(intervalId);
75
- reject(
76
- copyStackTrace$1(
77
- new Error(`Matcher did not succeed in ${timeout}ms`, {
78
- cause: lastError
79
- }),
80
- STACK_TRACE_ERROR
81
- )
82
- );
83
- }, timeout);
84
74
  const check = async () => {
85
75
  try {
86
76
  utils_exports.flag(assertion, "_name", key);
@@ -91,9 +81,26 @@ function createExpectPoll(expect2) {
91
81
  clearTimeout(timeoutId);
92
82
  } catch (err) {
93
83
  lastError = err;
94
- intervalId = setTimeout(check, interval);
84
+ if (!utils_exports.flag(assertion, "_isLastPollAttempt")) {
85
+ intervalId = setTimeout(check, interval);
86
+ }
95
87
  }
96
88
  };
89
+ timeoutId = setTimeout(() => {
90
+ clearTimeout(intervalId);
91
+ utils_exports.flag(assertion, "_isLastPollAttempt", true);
92
+ const rejectWithCause = (cause) => {
93
+ reject(
94
+ copyStackTrace$1(
95
+ new Error(`Matcher did not succeed in ${timeout}ms`, {
96
+ cause
97
+ }),
98
+ STACK_TRACE_ERROR
99
+ )
100
+ );
101
+ };
102
+ check().then(() => rejectWithCause(lastError)).catch((e) => rejectWithCause(e));
103
+ }, timeout);
97
104
  check();
98
105
  });
99
106
  let awaited = false;
@@ -262,9 +269,9 @@ function recordAsyncExpect(_test, promise, assertion, error) {
262
269
  }
263
270
  });
264
271
  return {
265
- then(onFullfilled, onRejected) {
272
+ then(onFulfilled, onRejected) {
266
273
  resolved = true;
267
- return promise.then(onFullfilled, onRejected);
274
+ return promise.then(onFulfilled, onRejected);
268
275
  },
269
276
  catch(onRejected) {
270
277
  return promise.catch(onRejected);
@@ -305,15 +312,20 @@ function getError(expected, promise) {
305
312
  throw new Error("snapshot function didn't throw");
306
313
  }
307
314
  function getTestNames(test) {
308
- if (!test) {
309
- return {};
310
- }
311
315
  return {
312
316
  filepath: test.file.filepath,
313
- name: getNames(test).slice(1).join(" > ")
317
+ name: getNames(test).slice(1).join(" > "),
318
+ testId: test.id
314
319
  };
315
320
  }
316
321
  const SnapshotPlugin = (chai2, utils) => {
322
+ function getTest(assertionName, obj) {
323
+ const test = utils.flag(obj, "vitest-test");
324
+ if (!test) {
325
+ throw new Error(`'${assertionName}' cannot be used without test context`);
326
+ }
327
+ return test;
328
+ }
317
329
  for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
318
330
  utils.addMethod(
319
331
  chai2.Assertion.prototype,
@@ -325,7 +337,7 @@ const SnapshotPlugin = (chai2, utils) => {
325
337
  throw new Error(`${key} cannot be used with "not"`);
326
338
  }
327
339
  const expected = utils.flag(this, "object");
328
- const test = utils.flag(this, "vitest-test");
340
+ const test = getTest(key, this);
329
341
  if (typeof properties === "string" && typeof message === "undefined") {
330
342
  message = properties;
331
343
  properties = void 0;
@@ -353,7 +365,7 @@ const SnapshotPlugin = (chai2, utils) => {
353
365
  }
354
366
  const error = new Error("resolves");
355
367
  const expected = utils.flag(this, "object");
356
- const test = utils.flag(this, "vitest-test");
368
+ const test = getTest("toMatchFileSnapshot", this);
357
369
  const errorMessage = utils.flag(this, "message");
358
370
  const promise = getSnapshotClient().assertRaw({
359
371
  received: expected,
@@ -382,8 +394,8 @@ const SnapshotPlugin = (chai2, utils) => {
382
394
  if (isNot) {
383
395
  throw new Error('toMatchInlineSnapshot cannot be used with "not"');
384
396
  }
385
- const test = utils.flag(this, "vitest-test");
386
- const isInsideEach = test && (test.each || test.suite?.each);
397
+ const test = getTest("toMatchInlineSnapshot", this);
398
+ const isInsideEach = test.each || test.suite?.each;
387
399
  if (isInsideEach) {
388
400
  throw new Error(
389
401
  "InlineSnapshot cannot be used inside of test.each or describe.each"
@@ -424,7 +436,7 @@ const SnapshotPlugin = (chai2, utils) => {
424
436
  );
425
437
  }
426
438
  const expected = utils.flag(this, "object");
427
- const test = utils.flag(this, "vitest-test");
439
+ const test = getTest("toThrowErrorMatchingSnapshot", this);
428
440
  const promise = utils.flag(this, "promise");
429
441
  const errorMessage = utils.flag(this, "message");
430
442
  getSnapshotClient().assert({
@@ -445,8 +457,8 @@ const SnapshotPlugin = (chai2, utils) => {
445
457
  'toThrowErrorMatchingInlineSnapshot cannot be used with "not"'
446
458
  );
447
459
  }
448
- const test = utils.flag(this, "vitest-test");
449
- const isInsideEach = test && (test.each || test.suite?.each);
460
+ const test = getTest("toThrowErrorMatchingInlineSnapshot", this);
461
+ const isInsideEach = test.each || test.suite?.each;
450
462
  if (isInsideEach) {
451
463
  throw new Error(
452
464
  "InlineSnapshot cannot be used inside of test.each or describe.each"
@@ -543,6 +555,7 @@ function createExpect(test) {
543
555
  }
544
556
  utils_exports.addMethod(expect$1, "assertions", assertions);
545
557
  utils_exports.addMethod(expect$1, "hasAssertions", hasAssertions);
558
+ expect$1.extend(customMatchers);
546
559
  return expect$1;
547
560
  }
548
561
  const globalExpect = createExpect();
@@ -658,42 +671,14 @@ function requireCalledInOrder() {
658
671
  calledInOrder_1 = calledInOrder;
659
672
  return calledInOrder_1;
660
673
  }
661
- var functionName;
662
- var hasRequiredFunctionName;
663
- function requireFunctionName() {
664
- if (hasRequiredFunctionName) return functionName;
665
- hasRequiredFunctionName = 1;
666
- functionName = function functionName2(func) {
667
- if (!func) {
668
- return "";
669
- }
670
- try {
671
- return func.displayName || func.name || // Use function decomposition as a last resort to get function
672
- // name. Does not rely on function decomposition to work - if it
673
- // doesn't debugging will be slightly less informative
674
- // (i.e. toString will say 'spy' rather than 'myFunc').
675
- (String(func).match(/function ([^\s(]+)/) || [])[1];
676
- } catch (e) {
677
- return "";
678
- }
679
- };
680
- return functionName;
681
- }
682
674
  var className_1;
683
675
  var hasRequiredClassName;
684
676
  function requireClassName() {
685
677
  if (hasRequiredClassName) return className_1;
686
678
  hasRequiredClassName = 1;
687
- var functionName2 = requireFunctionName();
688
679
  function className(value) {
689
- return value.constructor && value.constructor.name || // The next branch is for IE11 support only:
690
- // Because the name property is not set on the prototype
691
- // of the Function object, we finally try to grab the
692
- // name from its definition. This will never be reached
693
- // in node, so we are not able to test this properly.
694
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
695
- typeof value.constructor === "function" && /* istanbul ignore next */
696
- functionName2(value.constructor) || null;
680
+ const name = value.constructor && value.constructor.name;
681
+ return name || null;
697
682
  }
698
683
  className_1 = className;
699
684
  return className_1;
@@ -749,6 +734,27 @@ function requireEvery() {
749
734
  };
750
735
  return every;
751
736
  }
737
+ var functionName;
738
+ var hasRequiredFunctionName;
739
+ function requireFunctionName() {
740
+ if (hasRequiredFunctionName) return functionName;
741
+ hasRequiredFunctionName = 1;
742
+ functionName = function functionName2(func) {
743
+ if (!func) {
744
+ return "";
745
+ }
746
+ try {
747
+ return func.displayName || func.name || // Use function decomposition as a last resort to get function
748
+ // name. Does not rely on function decomposition to work - if it
749
+ // doesn't debugging will be slightly less informative
750
+ // (i.e. toString will say 'spy' rather than 'myFunc').
751
+ (String(func).match(/function ([^\s(]+)/) || [])[1];
752
+ } catch (e) {
753
+ return "";
754
+ }
755
+ };
756
+ return functionName;
757
+ }
752
758
  var orderByFirstCall_1;
753
759
  var hasRequiredOrderByFirstCall;
754
760
  function requireOrderByFirstCall() {
@@ -1000,12 +1006,16 @@ function requireFakeTimersSrc() {
1000
1006
  if (hasRequiredFakeTimersSrc) return fakeTimersSrc;
1001
1007
  hasRequiredFakeTimersSrc = 1;
1002
1008
  const globalObject = requireLib().global;
1003
- let timersModule;
1009
+ let timersModule, timersPromisesModule;
1004
1010
  if (typeof __vitest_required__ !== "undefined") {
1005
1011
  try {
1006
1012
  timersModule = __vitest_required__.timers;
1007
1013
  } catch (e) {
1008
1014
  }
1015
+ try {
1016
+ timersPromisesModule = __vitest_required__.timersPromises;
1017
+ } catch (e) {
1018
+ }
1009
1019
  }
1010
1020
  function withGlobal(_global) {
1011
1021
  const maxTimeout = Math.pow(2, 31) - 1;
@@ -1016,26 +1026,57 @@ function requireFakeTimersSrc() {
1016
1026
  const NOOP_ARRAY = function() {
1017
1027
  return [];
1018
1028
  };
1019
- const timeoutResult = _global.setTimeout(NOOP, 0);
1020
- const addTimerReturnsObject = typeof timeoutResult === "object";
1021
- const hrtimePresent = _global.process && typeof _global.process.hrtime === "function";
1022
- const hrtimeBigintPresent = hrtimePresent && typeof _global.process.hrtime.bigint === "function";
1023
- const nextTickPresent = _global.process && typeof _global.process.nextTick === "function";
1029
+ const isPresent = {};
1030
+ let timeoutResult, addTimerReturnsObject = false;
1031
+ if (_global.setTimeout) {
1032
+ isPresent.setTimeout = true;
1033
+ timeoutResult = _global.setTimeout(NOOP, 0);
1034
+ addTimerReturnsObject = typeof timeoutResult === "object";
1035
+ }
1036
+ isPresent.clearTimeout = Boolean(_global.clearTimeout);
1037
+ isPresent.setInterval = Boolean(_global.setInterval);
1038
+ isPresent.clearInterval = Boolean(_global.clearInterval);
1039
+ isPresent.hrtime = _global.process && typeof _global.process.hrtime === "function";
1040
+ isPresent.hrtimeBigint = isPresent.hrtime && typeof _global.process.hrtime.bigint === "function";
1041
+ isPresent.nextTick = _global.process && typeof _global.process.nextTick === "function";
1024
1042
  const utilPromisify = _global.process && _global.__vitest_required__ && _global.__vitest_required__.util.promisify;
1025
- const performancePresent = _global.performance && typeof _global.performance.now === "function";
1043
+ isPresent.performance = _global.performance && typeof _global.performance.now === "function";
1026
1044
  const hasPerformancePrototype = _global.Performance && (typeof _global.Performance).match(/^(function|object)$/);
1027
1045
  const hasPerformanceConstructorPrototype = _global.performance && _global.performance.constructor && _global.performance.constructor.prototype;
1028
- const queueMicrotaskPresent = _global.hasOwnProperty("queueMicrotask");
1029
- const requestAnimationFramePresent = _global.requestAnimationFrame && typeof _global.requestAnimationFrame === "function";
1030
- const cancelAnimationFramePresent = _global.cancelAnimationFrame && typeof _global.cancelAnimationFrame === "function";
1031
- const requestIdleCallbackPresent = _global.requestIdleCallback && typeof _global.requestIdleCallback === "function";
1032
- const cancelIdleCallbackPresent = _global.cancelIdleCallback && typeof _global.cancelIdleCallback === "function";
1033
- const setImmediatePresent = _global.setImmediate && typeof _global.setImmediate === "function";
1034
- const intlPresent = _global.Intl && typeof _global.Intl === "object";
1035
- _global.clearTimeout(timeoutResult);
1046
+ isPresent.queueMicrotask = _global.hasOwnProperty("queueMicrotask");
1047
+ isPresent.requestAnimationFrame = _global.requestAnimationFrame && typeof _global.requestAnimationFrame === "function";
1048
+ isPresent.cancelAnimationFrame = _global.cancelAnimationFrame && typeof _global.cancelAnimationFrame === "function";
1049
+ isPresent.requestIdleCallback = _global.requestIdleCallback && typeof _global.requestIdleCallback === "function";
1050
+ isPresent.cancelIdleCallbackPresent = _global.cancelIdleCallback && typeof _global.cancelIdleCallback === "function";
1051
+ isPresent.setImmediate = _global.setImmediate && typeof _global.setImmediate === "function";
1052
+ isPresent.clearImmediate = _global.clearImmediate && typeof _global.clearImmediate === "function";
1053
+ isPresent.Intl = _global.Intl && typeof _global.Intl === "object";
1054
+ if (_global.clearTimeout) {
1055
+ _global.clearTimeout(timeoutResult);
1056
+ }
1036
1057
  const NativeDate = _global.Date;
1037
- const NativeIntl = _global.Intl;
1058
+ const NativeIntl = isPresent.Intl ? Object.defineProperties(
1059
+ /* @__PURE__ */ Object.create(null),
1060
+ Object.getOwnPropertyDescriptors(_global.Intl)
1061
+ ) : void 0;
1038
1062
  let uniqueTimerId = idCounterStart;
1063
+ if (NativeDate === void 0) {
1064
+ throw new Error(
1065
+ "The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
1066
+ );
1067
+ }
1068
+ isPresent.Date = true;
1069
+ class FakePerformanceEntry {
1070
+ constructor(name, entryType, startTime, duration) {
1071
+ this.name = name;
1072
+ this.entryType = entryType;
1073
+ this.startTime = startTime;
1074
+ this.duration = duration;
1075
+ }
1076
+ toJSON() {
1077
+ return JSON.stringify({ ...this });
1078
+ }
1079
+ }
1039
1080
  function isNumberFinite(num) {
1040
1081
  if (Number.isFinite) {
1041
1082
  return Number.isFinite(num);
@@ -1136,80 +1177,66 @@ ${job.error.stack.split("\n").slice(matchedLineIndex + 1).join("\n")}`;
1136
1177
  }
1137
1178
  return infiniteLoopError;
1138
1179
  }
1139
- function mirrorDateProperties(target, source) {
1140
- let prop;
1141
- for (prop in source) {
1142
- if (source.hasOwnProperty(prop)) {
1143
- target[prop] = source[prop];
1180
+ function createDate() {
1181
+ class ClockDate extends NativeDate {
1182
+ /**
1183
+ * @param {number} year
1184
+ * @param {number} month
1185
+ * @param {number} date
1186
+ * @param {number} hour
1187
+ * @param {number} minute
1188
+ * @param {number} second
1189
+ * @param {number} ms
1190
+ * @returns void
1191
+ */
1192
+ // eslint-disable-next-line no-unused-vars
1193
+ constructor(year, month, date, hour, minute, second, ms) {
1194
+ if (arguments.length === 0) {
1195
+ super(ClockDate.clock.now);
1196
+ } else {
1197
+ super(...arguments);
1198
+ }
1199
+ Object.defineProperty(this, "constructor", {
1200
+ value: NativeDate,
1201
+ enumerable: false
1202
+ });
1203
+ }
1204
+ static [Symbol.hasInstance](instance) {
1205
+ return instance instanceof NativeDate;
1144
1206
  }
1145
1207
  }
1146
- if (source.now) {
1147
- target.now = function now() {
1148
- return target.clock.now;
1208
+ ClockDate.isFake = true;
1209
+ if (NativeDate.now) {
1210
+ ClockDate.now = function now() {
1211
+ return ClockDate.clock.now;
1149
1212
  };
1150
- } else {
1151
- delete target.now;
1152
1213
  }
1153
- if (source.toSource) {
1154
- target.toSource = function toSource() {
1155
- return source.toSource();
1214
+ if (NativeDate.toSource) {
1215
+ ClockDate.toSource = function toSource() {
1216
+ return NativeDate.toSource();
1156
1217
  };
1157
- } else {
1158
- delete target.toSource;
1159
1218
  }
1160
- target.toString = function toString() {
1161
- return source.toString();
1219
+ ClockDate.toString = function toString() {
1220
+ return NativeDate.toString();
1162
1221
  };
1163
- target.prototype = source.prototype;
1164
- target.parse = source.parse;
1165
- target.UTC = source.UTC;
1166
- target.prototype.toUTCString = source.prototype.toUTCString;
1167
- target.isFake = true;
1168
- return target;
1169
- }
1170
- function createDate() {
1171
- function ClockDate(year, month, date, hour, minute, second, ms) {
1172
- if (!(this instanceof ClockDate)) {
1173
- return new NativeDate(ClockDate.clock.now).toString();
1174
- }
1175
- switch (arguments.length) {
1176
- case 0:
1177
- return new NativeDate(ClockDate.clock.now);
1178
- case 1:
1179
- return new NativeDate(year);
1180
- case 2:
1181
- return new NativeDate(year, month);
1182
- case 3:
1183
- return new NativeDate(year, month, date);
1184
- case 4:
1185
- return new NativeDate(year, month, date, hour);
1186
- case 5:
1187
- return new NativeDate(year, month, date, hour, minute);
1188
- case 6:
1189
- return new NativeDate(
1190
- year,
1191
- month,
1192
- date,
1193
- hour,
1194
- minute,
1195
- second
1196
- );
1197
- default:
1198
- return new NativeDate(
1199
- year,
1200
- month,
1201
- date,
1202
- hour,
1203
- minute,
1204
- second,
1205
- ms
1222
+ const ClockDateProxy = new Proxy(ClockDate, {
1223
+ // handler for [[Call]] invocations (i.e. not using `new`)
1224
+ apply() {
1225
+ if (this instanceof ClockDate) {
1226
+ throw new TypeError(
1227
+ "A Proxy should only capture `new` calls with the `construct` handler. This is not supposed to be possible, so check the logic."
1206
1228
  );
1229
+ }
1230
+ return new NativeDate(ClockDate.clock.now).toString();
1207
1231
  }
1208
- }
1209
- return mirrorDateProperties(ClockDate, NativeDate);
1232
+ });
1233
+ return ClockDateProxy;
1210
1234
  }
1211
1235
  function createIntl() {
1212
- const ClockIntl = { ...NativeIntl };
1236
+ const ClockIntl = {};
1237
+ Object.getOwnPropertyNames(NativeIntl).forEach(
1238
+ (property) => ClockIntl[property] = NativeIntl[property]
1239
+ );
1213
1240
  ClockIntl.DateTimeFormat = function(...args) {
1214
1241
  const realFormatter = new NativeIntl.DateTimeFormat(...args);
1215
1242
  const formatter = {};
@@ -1495,11 +1522,21 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1495
1522
  timersModule[entry.methodName] = entry.original;
1496
1523
  }
1497
1524
  }
1525
+ if (clock.timersPromisesModuleMethods !== void 0) {
1526
+ for (let j = 0; j < clock.timersPromisesModuleMethods.length; j++) {
1527
+ const entry = clock.timersPromisesModuleMethods[j];
1528
+ timersPromisesModule[entry.methodName] = entry.original;
1529
+ }
1530
+ }
1498
1531
  }
1499
1532
  if (config.shouldAdvanceTime === true) {
1500
1533
  _global.clearInterval(clock.attachedInterval);
1501
1534
  }
1502
1535
  clock.methods = [];
1536
+ for (const [listener, signal] of clock.abortListenerMap.entries()) {
1537
+ signal.removeEventListener("abort", listener);
1538
+ clock.abortListenerMap.delete(listener);
1539
+ }
1503
1540
  if (!clock.timers) {
1504
1541
  return [];
1505
1542
  }
@@ -1514,8 +1551,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1514
1551
  );
1515
1552
  clock[`_${method}`] = target[method];
1516
1553
  if (method === "Date") {
1517
- const date = mirrorDateProperties(clock[method], target[method]);
1518
- target[method] = date;
1554
+ target[method] = clock[method];
1519
1555
  } else if (method === "Intl") {
1520
1556
  target[method] = clock[method];
1521
1557
  } else if (method === "performance") {
@@ -1558,36 +1594,38 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1558
1594
  clearInterval: _global.clearInterval,
1559
1595
  Date: _global.Date
1560
1596
  };
1561
- if (setImmediatePresent) {
1597
+ if (isPresent.setImmediate) {
1562
1598
  timers.setImmediate = _global.setImmediate;
1599
+ }
1600
+ if (isPresent.clearImmediate) {
1563
1601
  timers.clearImmediate = _global.clearImmediate;
1564
1602
  }
1565
- if (hrtimePresent) {
1603
+ if (isPresent.hrtime) {
1566
1604
  timers.hrtime = _global.process.hrtime;
1567
1605
  }
1568
- if (nextTickPresent) {
1606
+ if (isPresent.nextTick) {
1569
1607
  timers.nextTick = _global.process.nextTick;
1570
1608
  }
1571
- if (performancePresent) {
1609
+ if (isPresent.performance) {
1572
1610
  timers.performance = _global.performance;
1573
1611
  }
1574
- if (requestAnimationFramePresent) {
1612
+ if (isPresent.requestAnimationFrame) {
1575
1613
  timers.requestAnimationFrame = _global.requestAnimationFrame;
1576
1614
  }
1577
- if (queueMicrotaskPresent) {
1578
- timers.queueMicrotask = true;
1615
+ if (isPresent.queueMicrotask) {
1616
+ timers.queueMicrotask = _global.queueMicrotask;
1579
1617
  }
1580
- if (cancelAnimationFramePresent) {
1618
+ if (isPresent.cancelAnimationFrame) {
1581
1619
  timers.cancelAnimationFrame = _global.cancelAnimationFrame;
1582
1620
  }
1583
- if (requestIdleCallbackPresent) {
1621
+ if (isPresent.requestIdleCallback) {
1584
1622
  timers.requestIdleCallback = _global.requestIdleCallback;
1585
1623
  }
1586
- if (cancelIdleCallbackPresent) {
1624
+ if (isPresent.cancelIdleCallback) {
1587
1625
  timers.cancelIdleCallback = _global.cancelIdleCallback;
1588
1626
  }
1589
- if (intlPresent) {
1590
- timers.Intl = _global.Intl;
1627
+ if (isPresent.Intl) {
1628
+ timers.Intl = NativeIntl;
1591
1629
  }
1592
1630
  const originalSetTimeout = _global.setImmediate || _global.setTimeout;
1593
1631
  function createClock(start, loopLimit) {
@@ -1595,11 +1633,6 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1595
1633
  loopLimit = loopLimit || 1e3;
1596
1634
  let nanos = 0;
1597
1635
  const adjustedSystemTime = [0, 0];
1598
- if (NativeDate === void 0) {
1599
- throw new Error(
1600
- "The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
1601
- );
1602
- }
1603
1636
  const clock = {
1604
1637
  now: start,
1605
1638
  Date: createDate(),
@@ -1635,13 +1668,13 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1635
1668
  const millis = hrt[0] * 1e3 + hrt[1] / 1e6;
1636
1669
  return millis;
1637
1670
  }
1638
- if (hrtimeBigintPresent) {
1671
+ if (isPresent.hrtimeBigint) {
1639
1672
  hrtime.bigint = function() {
1640
1673
  const parts = hrtime();
1641
1674
  return BigInt(parts[0]) * BigInt(1e9) + BigInt(parts[1]);
1642
1675
  };
1643
1676
  }
1644
- if (intlPresent) {
1677
+ if (isPresent.Intl) {
1645
1678
  clock.Intl = createIntl();
1646
1679
  clock.Intl.clock = clock;
1647
1680
  }
@@ -1704,7 +1737,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1704
1737
  clock.clearInterval = function clearInterval(timerId) {
1705
1738
  return clearTimer(clock, timerId, "Interval");
1706
1739
  };
1707
- if (setImmediatePresent) {
1740
+ if (isPresent.setImmediate) {
1708
1741
  clock.setImmediate = function setImmediate(func) {
1709
1742
  return addTimer(clock, {
1710
1743
  func,
@@ -1937,6 +1970,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1937
1970
  function doRun() {
1938
1971
  originalSetTimeout(function() {
1939
1972
  try {
1973
+ runJobs(clock);
1940
1974
  let numTimers;
1941
1975
  if (i < clock.loopLimit) {
1942
1976
  if (!clock.timers) {
@@ -1984,6 +2018,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
1984
2018
  try {
1985
2019
  const timer = lastTimer(clock);
1986
2020
  if (!timer) {
2021
+ runJobs(clock);
1987
2022
  resolve(clock.now);
1988
2023
  }
1989
2024
  resolve(clock.tickAsync(timer.callAt - clock.now));
@@ -2026,11 +2061,11 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
2026
2061
  }
2027
2062
  clock.tick(ms);
2028
2063
  };
2029
- if (performancePresent) {
2064
+ if (isPresent.performance) {
2030
2065
  clock.performance = /* @__PURE__ */ Object.create(null);
2031
2066
  clock.performance.now = fakePerformanceNow;
2032
2067
  }
2033
- if (hrtimePresent) {
2068
+ if (isPresent.hrtime) {
2034
2069
  clock.hrtime = hrtime;
2035
2070
  }
2036
2071
  return clock;
@@ -2057,17 +2092,24 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
2057
2092
  "config.target is no longer supported. Use `withGlobal(target)` instead."
2058
2093
  );
2059
2094
  }
2095
+ function handleMissingTimer(timer) {
2096
+ if (config.ignoreMissingTimers) {
2097
+ return;
2098
+ }
2099
+ throw new ReferenceError(
2100
+ `non-existent timers and/or objects cannot be faked: '${timer}'`
2101
+ );
2102
+ }
2060
2103
  let i, l;
2061
2104
  const clock = createClock(config.now, config.loopLimit);
2062
2105
  clock.shouldClearNativeTimers = config.shouldClearNativeTimers;
2063
2106
  clock.uninstall = function() {
2064
2107
  return uninstall(clock, config);
2065
2108
  };
2109
+ clock.abortListenerMap = /* @__PURE__ */ new Map();
2066
2110
  clock.methods = config.toFake || [];
2067
2111
  if (clock.methods.length === 0) {
2068
- clock.methods = Object.keys(timers).filter(function(key) {
2069
- return key !== "nextTick" && key !== "queueMicrotask";
2070
- });
2112
+ clock.methods = Object.keys(timers);
2071
2113
  }
2072
2114
  if (config.shouldAdvanceTime === true) {
2073
2115
  const intervalTick = doIntervalTick.bind(
@@ -2096,17 +2138,25 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
2096
2138
  clock.performance[name] = name.indexOf("getEntries") === 0 ? NOOP_ARRAY : NOOP;
2097
2139
  }
2098
2140
  });
2141
+ clock.performance.mark = (name) => new FakePerformanceEntry(name, "mark", 0, 0);
2142
+ clock.performance.measure = (name) => new FakePerformanceEntry(name, "measure", 0, 100);
2143
+ clock.performance.timeOrigin = getEpoch(config.now);
2099
2144
  } else if ((config.toFake || []).includes("performance")) {
2100
- throw new ReferenceError(
2101
- "non-existent performance object cannot be faked"
2102
- );
2145
+ return handleMissingTimer("performance");
2103
2146
  }
2104
2147
  }
2105
2148
  if (_global === globalObject && timersModule) {
2106
2149
  clock.timersModuleMethods = [];
2107
2150
  }
2151
+ if (_global === globalObject && timersPromisesModule) {
2152
+ clock.timersPromisesModuleMethods = [];
2153
+ }
2108
2154
  for (i = 0, l = clock.methods.length; i < l; i++) {
2109
2155
  const nameOfMethodToReplace = clock.methods[i];
2156
+ if (!isPresent[nameOfMethodToReplace]) {
2157
+ handleMissingTimer(nameOfMethodToReplace);
2158
+ continue;
2159
+ }
2110
2160
  if (nameOfMethodToReplace === "hrtime") {
2111
2161
  if (_global.process && typeof _global.process.hrtime === "function") {
2112
2162
  hijackMethod(_global.process, nameOfMethodToReplace, clock);
@@ -2126,6 +2176,194 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
2126
2176
  });
2127
2177
  timersModule[nameOfMethodToReplace] = _global[nameOfMethodToReplace];
2128
2178
  }
2179
+ if (clock.timersPromisesModuleMethods !== void 0) {
2180
+ if (nameOfMethodToReplace === "setTimeout") {
2181
+ clock.timersPromisesModuleMethods.push({
2182
+ methodName: "setTimeout",
2183
+ original: timersPromisesModule.setTimeout
2184
+ });
2185
+ timersPromisesModule.setTimeout = (delay, value, options = {}) => new Promise((resolve, reject) => {
2186
+ const abort = () => {
2187
+ options.signal.removeEventListener(
2188
+ "abort",
2189
+ abort
2190
+ );
2191
+ clock.abortListenerMap.delete(abort);
2192
+ clock.clearTimeout(handle);
2193
+ reject(options.signal.reason);
2194
+ };
2195
+ const handle = clock.setTimeout(() => {
2196
+ if (options.signal) {
2197
+ options.signal.removeEventListener(
2198
+ "abort",
2199
+ abort
2200
+ );
2201
+ clock.abortListenerMap.delete(abort);
2202
+ }
2203
+ resolve(value);
2204
+ }, delay);
2205
+ if (options.signal) {
2206
+ if (options.signal.aborted) {
2207
+ abort();
2208
+ } else {
2209
+ options.signal.addEventListener(
2210
+ "abort",
2211
+ abort
2212
+ );
2213
+ clock.abortListenerMap.set(
2214
+ abort,
2215
+ options.signal
2216
+ );
2217
+ }
2218
+ }
2219
+ });
2220
+ } else if (nameOfMethodToReplace === "setImmediate") {
2221
+ clock.timersPromisesModuleMethods.push({
2222
+ methodName: "setImmediate",
2223
+ original: timersPromisesModule.setImmediate
2224
+ });
2225
+ timersPromisesModule.setImmediate = (value, options = {}) => new Promise((resolve, reject) => {
2226
+ const abort = () => {
2227
+ options.signal.removeEventListener(
2228
+ "abort",
2229
+ abort
2230
+ );
2231
+ clock.abortListenerMap.delete(abort);
2232
+ clock.clearImmediate(handle);
2233
+ reject(options.signal.reason);
2234
+ };
2235
+ const handle = clock.setImmediate(() => {
2236
+ if (options.signal) {
2237
+ options.signal.removeEventListener(
2238
+ "abort",
2239
+ abort
2240
+ );
2241
+ clock.abortListenerMap.delete(abort);
2242
+ }
2243
+ resolve(value);
2244
+ });
2245
+ if (options.signal) {
2246
+ if (options.signal.aborted) {
2247
+ abort();
2248
+ } else {
2249
+ options.signal.addEventListener(
2250
+ "abort",
2251
+ abort
2252
+ );
2253
+ clock.abortListenerMap.set(
2254
+ abort,
2255
+ options.signal
2256
+ );
2257
+ }
2258
+ }
2259
+ });
2260
+ } else if (nameOfMethodToReplace === "setInterval") {
2261
+ clock.timersPromisesModuleMethods.push({
2262
+ methodName: "setInterval",
2263
+ original: timersPromisesModule.setInterval
2264
+ });
2265
+ timersPromisesModule.setInterval = (delay, value, options = {}) => ({
2266
+ [Symbol.asyncIterator]: () => {
2267
+ const createResolvable = () => {
2268
+ let resolve, reject;
2269
+ const promise = new Promise((res, rej) => {
2270
+ resolve = res;
2271
+ reject = rej;
2272
+ });
2273
+ promise.resolve = resolve;
2274
+ promise.reject = reject;
2275
+ return promise;
2276
+ };
2277
+ let done = false;
2278
+ let hasThrown = false;
2279
+ let returnCall;
2280
+ let nextAvailable = 0;
2281
+ const nextQueue = [];
2282
+ const handle = clock.setInterval(() => {
2283
+ if (nextQueue.length > 0) {
2284
+ nextQueue.shift().resolve();
2285
+ } else {
2286
+ nextAvailable++;
2287
+ }
2288
+ }, delay);
2289
+ const abort = () => {
2290
+ options.signal.removeEventListener(
2291
+ "abort",
2292
+ abort
2293
+ );
2294
+ clock.abortListenerMap.delete(abort);
2295
+ clock.clearInterval(handle);
2296
+ done = true;
2297
+ for (const resolvable of nextQueue) {
2298
+ resolvable.resolve();
2299
+ }
2300
+ };
2301
+ if (options.signal) {
2302
+ if (options.signal.aborted) {
2303
+ done = true;
2304
+ } else {
2305
+ options.signal.addEventListener(
2306
+ "abort",
2307
+ abort
2308
+ );
2309
+ clock.abortListenerMap.set(
2310
+ abort,
2311
+ options.signal
2312
+ );
2313
+ }
2314
+ }
2315
+ return {
2316
+ next: async () => {
2317
+ if (options.signal?.aborted && !hasThrown) {
2318
+ hasThrown = true;
2319
+ throw options.signal.reason;
2320
+ }
2321
+ if (done) {
2322
+ return { done: true, value: void 0 };
2323
+ }
2324
+ if (nextAvailable > 0) {
2325
+ nextAvailable--;
2326
+ return { done: false, value };
2327
+ }
2328
+ const resolvable = createResolvable();
2329
+ nextQueue.push(resolvable);
2330
+ await resolvable;
2331
+ if (returnCall && nextQueue.length === 0) {
2332
+ returnCall.resolve();
2333
+ }
2334
+ if (options.signal?.aborted && !hasThrown) {
2335
+ hasThrown = true;
2336
+ throw options.signal.reason;
2337
+ }
2338
+ if (done) {
2339
+ return { done: true, value: void 0 };
2340
+ }
2341
+ return { done: false, value };
2342
+ },
2343
+ return: async () => {
2344
+ if (done) {
2345
+ return { done: true, value: void 0 };
2346
+ }
2347
+ if (nextQueue.length > 0) {
2348
+ returnCall = createResolvable();
2349
+ await returnCall;
2350
+ }
2351
+ clock.clearInterval(handle);
2352
+ done = true;
2353
+ if (options.signal) {
2354
+ options.signal.removeEventListener(
2355
+ "abort",
2356
+ abort
2357
+ );
2358
+ clock.abortListenerMap.delete(abort);
2359
+ }
2360
+ return { done: true, value: void 0 };
2361
+ }
2362
+ };
2363
+ }
2364
+ });
2365
+ }
2366
+ }
2129
2367
  }
2130
2368
  return clock;
2131
2369
  }
@@ -2257,21 +2495,11 @@ class FakeTimers {
2257
2495
  "process.nextTick cannot be mocked inside child_process"
2258
2496
  );
2259
2497
  }
2260
- const existingFakedMethods = (this._userConfig?.toFake || toFake).filter(
2261
- (method) => {
2262
- switch (method) {
2263
- case "setImmediate":
2264
- case "clearImmediate":
2265
- return method in this._global && this._global[method];
2266
- default:
2267
- return true;
2268
- }
2269
- }
2270
- );
2271
2498
  this._clock = this._fakeTimers.install({
2272
2499
  now: Date.now(),
2273
2500
  ...this._userConfig,
2274
- toFake: existingFakedMethods
2501
+ toFake: this._userConfig?.toFake || toFake,
2502
+ ignoreMissingTimers: true
2275
2503
  });
2276
2504
  this._fakingTime = true;
2277
2505
  }