@accelint/design-system 1.1.5 → 1.1.6

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 (82) hide show
  1. package/dist/components/button/button.css.d.ts +25 -24
  2. package/dist/components/button/index.d.ts +9 -40
  3. package/dist/components/button/index.js +23 -17
  4. package/dist/components/button/index.js.map +1 -1
  5. package/dist/components/button/types.d.ts +3 -2
  6. package/dist/components/checkbox/checkbox.css.d.ts +23 -23
  7. package/dist/components/chip/chip.css.d.ts +18 -18
  8. package/dist/components/collection/index.d.ts +2 -2
  9. package/dist/components/collection/index.js.map +1 -1
  10. package/dist/components/combo-box/combo-box.css.d.ts +9 -9
  11. package/dist/components/date-field/date-field.css.d.ts +17 -17
  12. package/dist/components/date-input/date-input.css.d.ts +25 -25
  13. package/dist/components/date-input/index.js +4 -1
  14. package/dist/components/date-input/index.js.map +1 -1
  15. package/dist/components/dialog/dialog.css.d.ts +16 -15
  16. package/dist/components/dialog/index.d.ts +1 -0
  17. package/dist/components/dialog/types.d.ts +1 -0
  18. package/dist/components/drawer/drawer.css.d.ts +17 -17
  19. package/dist/components/drawer/index.d.ts +1 -1
  20. package/dist/components/drawer/types.d.ts +1 -1
  21. package/dist/components/group/group.css.d.ts +7 -7
  22. package/dist/components/icon/icon.css.d.ts +9 -9
  23. package/dist/components/index.d.ts +2 -2
  24. package/dist/components/input/input.css.d.ts +20 -20
  25. package/dist/components/menu/index.d.ts +2 -2
  26. package/dist/components/menu/index.js +1 -1
  27. package/dist/components/menu/index.js.map +1 -1
  28. package/dist/components/menu/menu.css.d.ts +42 -42
  29. package/dist/components/merge-provider/index.js +15 -7
  30. package/dist/components/merge-provider/index.js.map +1 -1
  31. package/dist/components/number-field/index.d.ts +1 -1
  32. package/dist/components/number-field/number-field.css.d.ts +12 -12
  33. package/dist/components/number-field/types.d.ts +1 -1
  34. package/dist/components/options/index.js +1 -1
  35. package/dist/components/options/index.js.map +1 -1
  36. package/dist/components/options/options.css.d.ts +44 -44
  37. package/dist/components/picker/index.js.map +1 -1
  38. package/dist/components/picker/picker.css.d.ts +18 -18
  39. package/dist/components/popover/popover.css.d.ts +12 -12
  40. package/dist/components/query-builder/query-builder.css.d.ts +53 -53
  41. package/dist/components/radio/radio.css.d.ts +22 -22
  42. package/dist/components/search-field/search-field.css.d.ts +9 -9
  43. package/dist/components/select/select.css.d.ts +12 -12
  44. package/dist/components/slider/slider.css.d.ts +27 -27
  45. package/dist/components/switch/switch.css.d.ts +16 -16
  46. package/dist/components/tabs/tabs.css.d.ts +25 -25
  47. package/dist/components/text-field/index.d.ts +3 -128
  48. package/dist/components/text-field/index.js +3 -3
  49. package/dist/components/text-field/index.js.map +1 -1
  50. package/dist/components/text-field/text-field.css.d.ts +8 -8
  51. package/dist/components/textarea/textarea.css.d.ts +22 -22
  52. package/dist/components/time-field/time-field.css.d.ts +17 -17
  53. package/dist/components/tooltip/tooltip.css.d.ts +11 -11
  54. package/dist/components/tree/index.js +5 -2
  55. package/dist/components/tree/index.js.map +1 -1
  56. package/dist/components/tree/tree.css.d.ts +45 -45
  57. package/dist/hooks/index.d.ts +11 -11
  58. package/dist/hooks/use-collection-render/index.d.ts +1 -1
  59. package/dist/hooks/use-collection-render/index.js +2 -3
  60. package/dist/hooks/use-collection-render/index.js.map +1 -1
  61. package/dist/hooks/use-context-props/index.js.map +1 -1
  62. package/dist/hooks/use-defaults/index.d.ts +32 -80
  63. package/dist/hooks/use-defaults/index.js +1 -4
  64. package/dist/hooks/use-defaults/index.js.map +1 -1
  65. package/dist/hooks/use-defaults/types.d.ts +1 -1
  66. package/dist/hooks/use-theme/index.d.ts +1 -1
  67. package/dist/hooks/use-theme/types.d.ts +1 -1
  68. package/dist/hooks/use-tree/index.js +3 -2
  69. package/dist/hooks/use-tree/index.js.map +1 -1
  70. package/dist/hooks/use-tree/utils.js +6 -9
  71. package/dist/hooks/use-tree/utils.js.map +1 -1
  72. package/dist/hooks/use-update-effect/index.js.map +1 -1
  73. package/dist/index.css +32 -32
  74. package/dist/index.d.ts +5 -5
  75. package/dist/ladle/actions.js.map +1 -1
  76. package/dist/styles/theme.css.d.ts +200 -200
  77. package/dist/test/setup.js +646 -1387
  78. package/dist/test/setup.js.map +1 -1
  79. package/dist/utils/css/index.d.ts +1 -1
  80. package/dist/utils/props/index.d.ts +1 -2
  81. package/dist/utils/props/index.js.map +1 -1
  82. package/package.json +27 -27
@@ -3,7 +3,8 @@ import redent from 'redent.js';
3
3
  import { parse } from '@adobe/css-tools.js';
4
4
  import { computeAccessibleDescription, computeAccessibleName } from 'dom-accessibility-api.js';
5
5
  import { roles, elementRoles, roleElements } from 'aria-query.js';
6
- import pico from 'picocolors.js';
6
+ import chalk from 'chalk.js';
7
+ import isEqualWith from 'lodash/isEqualWith.js';
7
8
  import escape from 'css.escape.js';
8
9
  import * as React from 'react';
9
10
  import * as DeprecatedReactTestUtils from 'react-dom/test-utils';
@@ -11,22 +12,22 @@ import 'react-dom';
11
12
  import 'react-dom/client';
12
13
  import * as prettyFormat from 'pretty-format.js';
13
14
  import lzString from 'lz-string.js';
14
- import { JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, equals, iterableEquality, subsetEquality } from '@vitest/expect.js';
15
+ import { chai, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers, equals, iterableEquality, subsetEquality } from '@vitest/expect.js';
15
16
  import { afterEach as afterEach$1, getCurrentTest } from '@vitest/runner.js';
17
+ import { getSafeTimers, delay } from '@vitest/utils/timers.js';
16
18
  import { getNames } from '@vitest/runner/utils.js';
17
- import * as chai$1 from 'chai.js';
18
- import { assertTypes, getSafeTimers, createSimpleStackTrace } from '@vitest/utils.js';
19
19
  import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot.js';
20
20
  import '@vitest/utils/error.js';
21
- import { parseSingleStack } from '@vitest/utils/source-map.js';
22
- import { fn, spyOn, mocks, isMockFunction } from '@vitest/spy.js';
21
+ import '@vitest/utils/helpers.js';
22
+ import '@vitest/spy.js';
23
+ import '@vitest/utils/offset.js';
24
+ import '@vitest/utils/source-map.js';
23
25
  import 'expect-type.js';
26
+ import 'pathe.js';
24
27
 
25
- // ../node_modules/.pnpm/@testing-library+jest-dom@6.9.1/node_modules/@testing-library/jest-dom/dist/matchers.mjs
28
+ // ../node_modules/.pnpm/@testing-library+jest-dom@6.6.3/node_modules/@testing-library/jest-dom/dist/matchers.mjs
26
29
  var matchers_exports = {};
27
30
  __export(matchers_exports, {
28
- toAppearAfter: () => toAppearAfter,
29
- toAppearBefore: () => toAppearBefore,
30
31
  toBeChecked: () => toBeChecked,
31
32
  toBeDisabled: () => toBeDisabled,
32
33
  toBeEmpty: () => toBeEmpty,
@@ -36,8 +37,6 @@ __export(matchers_exports, {
36
37
  toBeInTheDocument: () => toBeInTheDocument,
37
38
  toBeInvalid: () => toBeInvalid,
38
39
  toBePartiallyChecked: () => toBePartiallyChecked,
39
- toBePartiallyPressed: () => toBePartiallyPressed,
40
- toBePressed: () => toBePressed,
41
40
  toBeRequired: () => toBeRequired,
42
41
  toBeValid: () => toBeValid,
43
42
  toBeVisible: () => toBeVisible,
@@ -236,11 +235,11 @@ function toSentence(array2, { wordConnector = ", ", lastWordConnector = " and "
236
235
  array2.length > 1 ? lastWordConnector : ""
237
236
  );
238
237
  }
239
- function compareAsSet(val1, val2) {
240
- if (Array.isArray(val1) && Array.isArray(val2)) {
241
- return [...new Set(val1)].every((v) => new Set(val2).has(v));
238
+ function compareArraysAsSet(arr1, arr2) {
239
+ if (Array.isArray(arr1) && Array.isArray(arr2)) {
240
+ return [...new Set(arr1)].every((v) => new Set(arr2).has(v));
242
241
  }
243
- return val1 === val2;
242
+ return void 0;
244
243
  }
245
244
  function toBeInTheDOM(element, container) {
246
245
  deprecate(
@@ -784,7 +783,7 @@ function expectedDiff(diffFn, expected, computedStyles) {
784
783
  {}
785
784
  );
786
785
  const diffOutput = diffFn(printoutStyles(expected), printoutStyles(received));
787
- return diffOutput.replace(`${pico.red("+ Received")}
786
+ return diffOutput.replace(`${chalk.red("+ Received")}
788
787
  `, "");
789
788
  }
790
789
  function toHaveStyle(htmlElement, css) {
@@ -882,7 +881,7 @@ function toHaveFormValues(formElement, expectedValues) {
882
881
  const formValues = getAllFormValues(formElement);
883
882
  return {
884
883
  pass: Object.entries(expectedValues).every(
885
- ([name, expectedValue]) => compareAsSet(formValues[name], expectedValue)
884
+ ([name, expectedValue]) => isEqualWith(formValues[name], expectedValue, compareArraysAsSet)
886
885
  ),
887
886
  message: () => {
888
887
  const to = this.isNot ? "not to" : "to";
@@ -1128,7 +1127,7 @@ function toHaveValue(htmlElement, expectedValue) {
1128
1127
  receivedTypedValue = `${receivedValue} (${typeof receivedValue})`;
1129
1128
  }
1130
1129
  return {
1131
- pass: expectsValue ? compareAsSet(receivedValue, expectedValue) : Boolean(receivedValue),
1130
+ pass: expectsValue ? isEqualWith(receivedValue, expectedValue, compareArraysAsSet) : Boolean(receivedValue),
1132
1131
  message: () => {
1133
1132
  const to = this.isNot ? "not to" : "to";
1134
1133
  const matcher = this.utils.matcherHint(
@@ -1409,7 +1408,7 @@ function toHaveSelection(htmlElement, expectedSelection) {
1409
1408
  }
1410
1409
  const receivedSelection = getSelection(htmlElement);
1411
1410
  return {
1412
- pass: expectsSelection ? compareAsSet(receivedSelection, expectedSelection) : Boolean(receivedSelection),
1411
+ pass: expectsSelection ? isEqualWith(receivedSelection, expectedSelection, compareArraysAsSet) : Boolean(receivedSelection),
1413
1412
  message: () => {
1414
1413
  const to = this.isNot ? "not to" : "to";
1415
1414
  const matcher = this.utils.matcherHint(
@@ -1428,125 +1427,6 @@ function toHaveSelection(htmlElement, expectedSelection) {
1428
1427
  }
1429
1428
  };
1430
1429
  }
1431
- function toBePressed(element) {
1432
- checkHtmlElement(element, toBePressed, this);
1433
- const roles3 = (element.getAttribute("role") || "").split(" ").map((role) => role.trim());
1434
- const isButton = element.tagName.toLowerCase() === "button" || element.tagName.toLowerCase() === "input" && element.type === "button" || roles3.includes("button");
1435
- const pressedAttribute = element.getAttribute("aria-pressed");
1436
- const isValidAriaElement = pressedAttribute === "true" || pressedAttribute === "false";
1437
- if (!isButton || !isValidAriaElement) {
1438
- return {
1439
- pass: false,
1440
- message: () => `Only button or input with type="button" or element with role="button" and a valid aria-pressed attribute can be used with .toBePressed()`
1441
- };
1442
- }
1443
- const isPressed = pressedAttribute === "true";
1444
- return {
1445
- pass: isButton && isPressed,
1446
- message: () => {
1447
- const matcher = this.utils.matcherHint(
1448
- `${this.isNot ? ".not" : ""}.toBePressed`,
1449
- "element",
1450
- ""
1451
- );
1452
- return getMessage(
1453
- this,
1454
- matcher,
1455
- `Expected element to have`,
1456
- `aria-pressed="${this.isNot ? "false" : "true"}"`,
1457
- `Received`,
1458
- `aria-pressed="${pressedAttribute}"`
1459
- );
1460
- }
1461
- };
1462
- }
1463
- function toBePartiallyPressed(element) {
1464
- checkHtmlElement(element, toBePartiallyPressed, this);
1465
- const roles3 = (element.getAttribute("role") || "").split(" ").map((role) => role.trim());
1466
- const isButton = element.tagName.toLowerCase() === "button" || element.tagName.toLowerCase() === "input" && element.type === "button" || roles3.includes("button");
1467
- const pressedAttribute = element.getAttribute("aria-pressed");
1468
- const isValidAriaElement = pressedAttribute === "true" || pressedAttribute === "false" || pressedAttribute === "mixed";
1469
- if (!isButton || !isValidAriaElement) {
1470
- return {
1471
- pass: false,
1472
- message: () => `Only button or input with type="button" or element with role="button" and a valid aria-pressed attribute can be used with .toBePartiallyPressed()`
1473
- };
1474
- }
1475
- const isPartiallyPressed = pressedAttribute === "mixed";
1476
- return {
1477
- pass: isButton && isPartiallyPressed,
1478
- message: () => {
1479
- const to = this.isNot ? "not to" : "to";
1480
- const matcher = this.utils.matcherHint(
1481
- `${this.isNot ? ".not" : ""}.toBePartiallyPressed`,
1482
- "element",
1483
- ""
1484
- );
1485
- return getMessage(
1486
- this,
1487
- matcher,
1488
- `Expected element ${to} have`,
1489
- `aria-pressed="mixed"`,
1490
- `Received`,
1491
- `aria-pressed="${pressedAttribute}"`
1492
- );
1493
- }
1494
- };
1495
- }
1496
- var DOCUMENT_POSITION_DISCONNECTED = 1;
1497
- var DOCUMENT_POSITION_PRECEDING = 2;
1498
- var DOCUMENT_POSITION_FOLLOWING = 4;
1499
- var DOCUMENT_POSITION_CONTAINS = 8;
1500
- var DOCUMENT_POSITION_CONTAINED_BY = 16;
1501
- var DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;
1502
- var DOCUMENT_POSITIONS_STRINGS = {
1503
- [DOCUMENT_POSITION_DISCONNECTED]: "Node.DOCUMENT_POSITION_DISCONNECTED",
1504
- [DOCUMENT_POSITION_PRECEDING]: "Node.DOCUMENT_POSITION_PRECEDING",
1505
- [DOCUMENT_POSITION_FOLLOWING]: "Node.DOCUMENT_POSITION_FOLLOWING",
1506
- [DOCUMENT_POSITION_CONTAINS]: "Node.DOCUMENT_POSITION_CONTAINS",
1507
- [DOCUMENT_POSITION_CONTAINED_BY]: "Node.DOCUMENT_POSITION_CONTAINED_BY",
1508
- [DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC]: "Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC"
1509
- };
1510
- function makeDocumentPositionErrorString(documentPosition) {
1511
- if (documentPosition in DOCUMENT_POSITIONS_STRINGS) {
1512
- return `${DOCUMENT_POSITIONS_STRINGS[documentPosition]} (${documentPosition})`;
1513
- }
1514
- return `Unknown document position (${documentPosition})`;
1515
- }
1516
- function checkToAppear(methodName, targetDocumentPosition) {
1517
- return function(element, secondElement) {
1518
- checkHtmlElement(element, toAppearBefore, this);
1519
- checkHtmlElement(secondElement, toAppearBefore, this);
1520
- const documentPosition = element.compareDocumentPosition(secondElement);
1521
- const pass = documentPosition === targetDocumentPosition;
1522
- return {
1523
- pass,
1524
- message: () => {
1525
- return [
1526
- this.utils.matcherHint(
1527
- `${this.isNot ? ".not" : ""}.${methodName}`,
1528
- "element",
1529
- "secondElement"
1530
- ),
1531
- "",
1532
- `Received: ${makeDocumentPositionErrorString(documentPosition)}`
1533
- ].join("\n");
1534
- }
1535
- };
1536
- };
1537
- }
1538
- function toAppearBefore(element, secondElement) {
1539
- return checkToAppear("toAppearBefore", DOCUMENT_POSITION_FOLLOWING).apply(
1540
- this,
1541
- [element, secondElement]
1542
- );
1543
- }
1544
- function toAppearAfter(element, secondElement) {
1545
- return checkToAppear("toAppearAfter", DOCUMENT_POSITION_PRECEDING).apply(
1546
- this,
1547
- [element, secondElement]
1548
- );
1549
- }
1550
1430
  function escapeHTML(str) {
1551
1431
  return str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
1552
1432
  }
@@ -1640,14 +1520,14 @@ function createDOMElementFilter(filterNode) {
1640
1520
  }
1641
1521
  };
1642
1522
  }
1643
- var picocolors = null;
1523
+ var chalk2 = null;
1644
1524
  var readFileSync = null;
1645
1525
  var codeFrameColumns = null;
1646
1526
  try {
1647
1527
  const nodeRequire = module && module.require;
1648
1528
  readFileSync = nodeRequire.call(module, "fs").readFileSync;
1649
1529
  codeFrameColumns = nodeRequire.call(module, "@babel/code-frame").codeFrameColumns;
1650
- picocolors = nodeRequire.call(module, "picocolors");
1530
+ chalk2 = nodeRequire.call(module, "chalk");
1651
1531
  } catch {
1652
1532
  }
1653
1533
  function getCodeFrame(frame) {
@@ -1671,7 +1551,7 @@ function getCodeFrame(frame) {
1671
1551
  highlightCode: true,
1672
1552
  linesBelow: 0
1673
1553
  });
1674
- return picocolors.dim(frameLocation) + "\n" + codeFrame + "\n";
1554
+ return chalk2.dim(frameLocation) + "\n" + codeFrame + "\n";
1675
1555
  }
1676
1556
  function getUserCodeFrame() {
1677
1557
  if (!readFileSync || !codeFrameColumns) {
@@ -2899,8 +2779,8 @@ var queryAllByRole = function(container, role, _temp) {
2899
2779
  }
2900
2780
  }
2901
2781
  if (expanded !== void 0) {
2902
- var _allRoles$get0;
2903
- if (((_allRoles$get0 = roles.get(role)) == null ? void 0 : _allRoles$get0.props["aria-expanded"]) === void 0) {
2782
+ var _allRoles$get10;
2783
+ if (((_allRoles$get10 = roles.get(role)) == null ? void 0 : _allRoles$get10.props["aria-expanded"]) === void 0) {
2904
2784
  throw new Error('"aria-expanded" is not supported on role "' + role + '".');
2905
2785
  }
2906
2786
  }
@@ -3999,7 +3879,7 @@ typeof document !== "undefined" && document.body ? getQueriesForElement(document
3999
3879
  return helpers;
4000
3880
  }, initialValue);
4001
3881
 
4002
- // ../node_modules/.pnpm/@testing-library+react@16.3.0_@testing-library+dom@10.4.1_@types+react-dom@19.0.0_@type_2cdadb9aaf9a026f45fcc74be32c5467/node_modules/@testing-library/react/dist/@testing-library/react.esm.js
3882
+ // ../node_modules/.pnpm/@testing-library+react@16.3.0_@testing-library+dom@10.4.0_@types+react-dom@19.0.0_@type_c73dee9f0e611c0cf8e2f38a680966d7/node_modules/@testing-library/react/dist/@testing-library/react.esm.js
4003
3883
  var reactAct = typeof React.act === "function" ? React.act : DeprecatedReactTestUtils.act;
4004
3884
  function getGlobalThis() {
4005
3885
  if (typeof globalThis !== "undefined") {
@@ -4147,82 +4027,22 @@ if (typeof process === "undefined" || !process.env?.RTL_SKIP_AUTO_CLEANUP) {
4147
4027
  var NAME_WORKER_STATE = "__vitest_worker__";
4148
4028
  function getWorkerState() {
4149
4029
  const workerState = globalThis[NAME_WORKER_STATE];
4150
- if (!workerState) {
4151
- const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
4152
- throw new Error(errorMsg);
4153
- }
4030
+ if (!workerState) throw new Error('Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- "vitest" is imported inside Vite / Vitest config file\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n');
4154
4031
  return workerState;
4155
4032
  }
4156
- function getCurrentEnvironment() {
4157
- const state = getWorkerState();
4158
- return state?.environment.name;
4159
- }
4160
- function isChildProcess() {
4161
- return typeof process !== "undefined" && !!process.send;
4162
- }
4163
- function resetModules(modules, resetMocks = false) {
4164
- const skipPaths = [
4165
- // Vitest
4166
- /\/vitest\/dist\//,
4167
- /\/vite-node\/dist\//,
4168
- // yarn's .store folder
4169
- /vitest-virtual-\w+\/dist/,
4170
- // cnpm
4171
- /@vitest\/dist/,
4172
- // don't clear mocks
4173
- ...!resetMocks ? [/^mock:/] : []
4174
- ];
4175
- modules.forEach((mod, path) => {
4176
- if (skipPaths.some((re) => re.test(path))) {
4177
- return;
4178
- }
4179
- modules.invalidateModule(mod);
4180
- });
4181
- }
4182
- function waitNextTick() {
4183
- const { setTimeout: setTimeout2 } = getSafeTimers();
4184
- return new Promise((resolve) => setTimeout2(resolve, 0));
4185
- }
4186
- async function waitForImportsToResolve() {
4187
- await waitNextTick();
4188
- const state = getWorkerState();
4189
- const promises = [];
4190
- let resolvingCount = 0;
4191
- for (const mod of state.moduleCache.values()) {
4192
- if (mod.promise && !mod.evaluated) {
4193
- promises.push(mod.promise);
4194
- }
4195
- if (mod.resolving) {
4196
- resolvingCount++;
4197
- }
4198
- }
4199
- if (!promises.length && !resolvingCount) {
4200
- return;
4201
- }
4202
- await Promise.allSettled(promises);
4203
- await waitForImportsToResolve();
4204
- }
4205
4033
 
4206
- // ../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_jsdom@25.0.1_msw@2.12.4_@types+node@24.10.1_typescript@5.9.3_/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
4034
+ // ../node_modules/.pnpm/vitest@4.0.16_@types+node@25.0.3_jiti@2.6.1_jsdom@25.0.1_msw@2.12.7_@types+node@25.0.3_typescript@5.9.3__tsx@4.21.0/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.js
4207
4035
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
4208
- function getDefaultExportFromCjs(x) {
4209
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4210
- }
4211
4036
 
4212
- // ../node_modules/.pnpm/vitest@2.1.9_@types+node@24.10.1_jsdom@25.0.1_msw@2.12.4_@types+node@24.10.1_typescript@5.9.3_/node_modules/vitest/dist/chunks/date.W2xKR2qe.js
4037
+ // ../node_modules/.pnpm/vitest@4.0.16_@types+node@25.0.3_jiti@2.6.1_jsdom@25.0.1_msw@2.12.7_@types+node@25.0.3_typescript@5.9.3__tsx@4.21.0/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js
4213
4038
  var RealDate = Date;
4214
- var now = null;
4215
4039
  var MockDate = class _MockDate extends RealDate {
4216
4040
  constructor(y, m, d, h, M, s, ms) {
4217
4041
  super();
4218
4042
  let date;
4219
4043
  switch (arguments.length) {
4220
4044
  case 0:
4221
- if (now !== null) {
4222
- date = new RealDate(now.valueOf());
4223
- } else {
4224
- date = new RealDate();
4225
- }
4045
+ date = new RealDate();
4226
4046
  break;
4227
4047
  case 1:
4228
4048
  date = new RealDate(y);
@@ -4250,257 +4070,122 @@ MockDate.parse = function(dateString) {
4250
4070
  MockDate.toString = function() {
4251
4071
  return RealDate.toString();
4252
4072
  };
4253
- function mockDate(date) {
4254
- const dateObj = new RealDate(date.valueOf());
4255
- if (Number.isNaN(dateObj.getTime())) {
4256
- throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
4257
- }
4258
- globalThis.Date = MockDate;
4259
- now = dateObj.valueOf();
4260
- }
4261
- function resetDate() {
4262
- globalThis.Date = RealDate;
4263
- }
4073
+
4074
+ // ../node_modules/.pnpm/vitest@4.0.16_@types+node@25.0.3_jiti@2.6.1_jsdom@25.0.1_msw@2.12.7_@types+node@25.0.3_typescript@5.9.3__tsx@4.21.0/node_modules/vitest/dist/chunks/vi.2VT5v0um.js
4264
4075
  var unsupported = [
4265
- // .poll is meant to retry matchers until they succeed, and
4266
- // snapshots will always succeed as long as the poll method doesn't thow an error
4267
- // in this case using the `vi.waitFor` method is more appropriate
4268
4076
  "matchSnapshot",
4269
4077
  "toMatchSnapshot",
4270
4078
  "toMatchInlineSnapshot",
4271
4079
  "toThrowErrorMatchingSnapshot",
4272
4080
  "toThrowErrorMatchingInlineSnapshot",
4273
- // toThrow will never succeed because we call the poll callback until it doesn't throw
4274
4081
  "throws",
4275
4082
  "Throw",
4276
4083
  "throw",
4277
4084
  "toThrow",
4278
4085
  "toThrowError"
4279
- // these are not supported because you can call them without `.poll`,
4280
- // we throw an error inside the rejects/resolves methods to prevent this
4281
- // rejects,
4282
- // resolves
4283
4086
  ];
4284
- function createExpectPoll(expect2) {
4087
+ function throwWithCause(error, source) {
4088
+ if (error.cause == null) error.cause = /* @__PURE__ */ new Error("Matcher did not succeed in time.");
4089
+ throw copyStackTrace$1(error, source);
4090
+ }
4091
+ function createExpectPoll(expect) {
4285
4092
  return function poll(fn2, options = {}) {
4286
- const state = getWorkerState();
4287
- const defaults = state.config.expect?.poll ?? {};
4288
- const {
4289
- interval = defaults.interval ?? 50,
4290
- timeout = defaults.timeout ?? 1e3,
4291
- message
4292
- } = options;
4293
- const assertion = expect2(null, message).withContext({
4294
- poll: true
4295
- });
4093
+ const defaults = getWorkerState().config.expect?.poll ?? {};
4094
+ const { interval = defaults.interval ?? 50, timeout = defaults.timeout ?? 1e3, message } = options;
4095
+ const assertion = expect(null, message).withContext({ poll: true });
4296
4096
  fn2 = fn2.bind(assertion);
4297
- const test2 = chai$1.util.flag(assertion, "vitest-test");
4298
- if (!test2) {
4299
- throw new Error("expect.poll() must be called inside a test");
4300
- }
4301
- const proxy = new Proxy(assertion, {
4302
- get(target, key, receiver) {
4303
- const assertionFunction = Reflect.get(target, key, receiver);
4304
- if (typeof assertionFunction !== "function") {
4305
- return assertionFunction instanceof chai$1.Assertion ? proxy : assertionFunction;
4306
- }
4307
- if (key === "assert") {
4308
- return assertionFunction;
4309
- }
4310
- if (typeof key === "string" && unsupported.includes(key)) {
4311
- throw new SyntaxError(
4312
- `expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`
4313
- );
4314
- }
4315
- return function(...args) {
4316
- const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
4317
- const promise = () => new Promise((resolve, reject) => {
4318
- let intervalId;
4319
- let lastError;
4320
- const { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = getSafeTimers();
4321
- const timeoutId = setTimeout2(() => {
4322
- clearTimeout2(intervalId);
4323
- reject(
4324
- copyStackTrace$1(
4325
- new Error(`Matcher did not succeed in ${timeout}ms`, {
4326
- cause: lastError
4327
- }),
4328
- STACK_TRACE_ERROR
4329
- )
4330
- );
4331
- }, timeout);
4332
- const check = async () => {
4097
+ const test2 = chai.util.flag(assertion, "vitest-test");
4098
+ if (!test2) throw new Error("expect.poll() must be called inside a test");
4099
+ const proxy = new Proxy(assertion, { get(target, key, receiver) {
4100
+ const assertionFunction = Reflect.get(target, key, receiver);
4101
+ if (typeof assertionFunction !== "function") return assertionFunction instanceof chai.Assertion ? proxy : assertionFunction;
4102
+ if (key === "assert") return assertionFunction;
4103
+ if (typeof key === "string" && unsupported.includes(key)) throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
4104
+ return function(...args) {
4105
+ const STACK_TRACE_ERROR = /* @__PURE__ */ new Error("STACK_TRACE_ERROR");
4106
+ const promise = async () => {
4107
+ const { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = getSafeTimers();
4108
+ let executionPhase = "fn";
4109
+ let hasTimedOut = false;
4110
+ const timerId = setTimeout2(() => {
4111
+ hasTimedOut = true;
4112
+ }, timeout);
4113
+ chai.util.flag(assertion, "_name", key);
4114
+ try {
4115
+ while (true) {
4116
+ const isLastAttempt = hasTimedOut;
4117
+ if (isLastAttempt) chai.util.flag(assertion, "_isLastPollAttempt", true);
4333
4118
  try {
4334
- chai$1.util.flag(assertion, "_name", key);
4119
+ executionPhase = "fn";
4335
4120
  const obj = await fn2();
4336
- chai$1.util.flag(assertion, "object", obj);
4337
- resolve(await assertionFunction.call(assertion, ...args));
4338
- clearTimeout2(intervalId);
4339
- clearTimeout2(timeoutId);
4121
+ chai.util.flag(assertion, "object", obj);
4122
+ executionPhase = "assertion";
4123
+ return await assertionFunction.call(assertion, ...args);
4340
4124
  } catch (err) {
4341
- lastError = err;
4342
- intervalId = setTimeout2(check, interval);
4125
+ if (isLastAttempt || executionPhase === "assertion" && chai.util.flag(assertion, "_poll.assert_once")) throwWithCause(err, STACK_TRACE_ERROR);
4126
+ await delay(interval, setTimeout2);
4343
4127
  }
4344
- };
4345
- check();
4346
- });
4347
- let awaited = false;
4348
- test2.onFinished ??= [];
4349
- test2.onFinished.push(() => {
4350
- if (!awaited) {
4351
- const negated = chai$1.util.flag(assertion, "negate") ? "not." : "";
4352
- const name = chai$1.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)";
4353
- const assertionString = `expect.${name}.${negated}${String(key)}()`;
4354
- const error = new Error(
4355
- `${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
4128
+ }
4129
+ } finally {
4130
+ clearTimeout2(timerId);
4131
+ }
4132
+ };
4133
+ let awaited = false;
4134
+ test2.onFinished ??= [];
4135
+ test2.onFinished.push(() => {
4136
+ if (!awaited) {
4137
+ const negated = chai.util.flag(assertion, "negate") ? "not." : "";
4138
+ const assertionString = `expect.${chai.util.flag(assertion, "_poll.element") ? "element(locator)" : "poll(assertion)"}.${negated}${String(key)}()`;
4139
+ throw copyStackTrace$1(/* @__PURE__ */ new Error(`${assertionString} was not awaited. This assertion is asynchronous and must be awaited; otherwise, it is not executed to avoid unhandled rejections:
4356
4140
 
4357
4141
  await ${assertionString}
4358
- `
4359
- );
4360
- throw copyStackTrace$1(error, STACK_TRACE_ERROR);
4361
- }
4362
- });
4363
- let resultPromise;
4364
- return {
4365
- then(onFulfilled, onRejected) {
4366
- awaited = true;
4367
- return (resultPromise ||= promise()).then(onFulfilled, onRejected);
4368
- },
4369
- catch(onRejected) {
4370
- return (resultPromise ||= promise()).catch(onRejected);
4371
- },
4372
- finally(onFinally) {
4373
- return (resultPromise ||= promise()).finally(onFinally);
4374
- },
4375
- [Symbol.toStringTag]: "Promise"
4376
- };
4142
+ `), STACK_TRACE_ERROR);
4143
+ }
4144
+ });
4145
+ let resultPromise;
4146
+ return {
4147
+ then(onFulfilled, onRejected) {
4148
+ awaited = true;
4149
+ return (resultPromise ||= promise()).then(onFulfilled, onRejected);
4150
+ },
4151
+ catch(onRejected) {
4152
+ return (resultPromise ||= promise()).catch(onRejected);
4153
+ },
4154
+ finally(onFinally) {
4155
+ return (resultPromise ||= promise()).finally(onFinally);
4156
+ },
4157
+ [Symbol.toStringTag]: "Promise"
4377
4158
  };
4378
- }
4379
- });
4159
+ };
4160
+ } });
4380
4161
  return proxy;
4381
4162
  };
4382
4163
  }
4383
4164
  function copyStackTrace$1(target, source) {
4384
- if (source.stack !== void 0) {
4385
- target.stack = source.stack.replace(source.message, target.message);
4386
- }
4165
+ if (source.stack !== void 0) target.stack = source.stack.replace(source.message, target.message);
4387
4166
  return target;
4388
4167
  }
4389
- function commonjsRequire(path) {
4390
- throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
4391
- }
4392
- var chaiSubset$1 = { exports: {} };
4393
- var chaiSubset = chaiSubset$1.exports;
4394
- var hasRequiredChaiSubset;
4395
- function requireChaiSubset() {
4396
- if (hasRequiredChaiSubset) return chaiSubset$1.exports;
4397
- hasRequiredChaiSubset = 1;
4398
- (function(module2, exports$1) {
4399
- (function() {
4400
- (function(chaiSubset2) {
4401
- if (typeof commonjsRequire === "function" && true && true) {
4402
- return module2.exports = chaiSubset2;
4403
- } else {
4404
- return chai.use(chaiSubset2);
4405
- }
4406
- })(function(chai3, utils) {
4407
- var Assertion2 = chai3.Assertion;
4408
- var assertionPrototype = Assertion2.prototype;
4409
- Assertion2.addMethod("containSubset", function(expected) {
4410
- var actual = utils.flag(this, "object");
4411
- var showDiff = chai3.config.showDiff;
4412
- assertionPrototype.assert.call(
4413
- this,
4414
- compare(expected, actual),
4415
- "expected #{act} to contain subset #{exp}",
4416
- "expected #{act} to not contain subset #{exp}",
4417
- expected,
4418
- actual,
4419
- showDiff
4420
- );
4421
- });
4422
- chai3.assert.containSubset = function(val, exp, msg) {
4423
- new chai3.Assertion(val, msg).to.be.containSubset(exp);
4424
- };
4425
- function compare(expected, actual) {
4426
- if (expected === actual) {
4427
- return true;
4428
- }
4429
- if (typeof actual !== typeof expected) {
4430
- return false;
4431
- }
4432
- if (typeof expected !== "object" || expected === null) {
4433
- return expected === actual;
4434
- }
4435
- if (!!expected && !actual) {
4436
- return false;
4437
- }
4438
- if (Array.isArray(expected)) {
4439
- if (typeof actual.length !== "number") {
4440
- return false;
4441
- }
4442
- var aa = Array.prototype.slice.call(actual);
4443
- return expected.every(function(exp) {
4444
- return aa.some(function(act4) {
4445
- return compare(exp, act4);
4446
- });
4447
- });
4448
- }
4449
- if (expected instanceof Date) {
4450
- if (actual instanceof Date) {
4451
- return expected.getTime() === actual.getTime();
4452
- } else {
4453
- return false;
4454
- }
4455
- }
4456
- return Object.keys(expected).every(function(key) {
4457
- var eo = expected[key];
4458
- var ao = actual[key];
4459
- if (typeof eo === "object" && eo !== null && ao !== null) {
4460
- return compare(eo, ao);
4461
- }
4462
- if (typeof eo === "function") {
4463
- return eo(ao);
4464
- }
4465
- return ao === eo;
4466
- });
4467
- }
4468
- });
4469
- }).call(chaiSubset);
4470
- })(chaiSubset$1);
4471
- return chaiSubset$1.exports;
4472
- }
4473
- var chaiSubsetExports = requireChaiSubset();
4474
- var Subset = /* @__PURE__ */ getDefaultExportFromCjs(chaiSubsetExports);
4475
- function createAssertionMessage(util2, assertion, hasArgs) {
4476
- const not = util2.flag(assertion, "negate") ? "not." : "";
4477
- const name = `${util2.flag(assertion, "_name")}(${"expected"})`;
4478
- const promiseName = util2.flag(assertion, "promise");
4479
- const promise = promiseName ? `.${promiseName}` : "";
4480
- return `expect(actual)${promise}.${not}${name}`;
4168
+ function createAssertionMessage(util, assertion, hasArgs) {
4169
+ const not = util.flag(assertion, "negate") ? "not." : "";
4170
+ const name = `${util.flag(assertion, "_name")}(${"expected"})`;
4171
+ const promiseName = util.flag(assertion, "promise");
4172
+ return `expect(actual)${promiseName ? `.${promiseName}` : ""}.${not}${name}`;
4481
4173
  }
4482
4174
  function recordAsyncExpect(_test, promise, assertion, error) {
4483
4175
  const test2 = _test;
4484
4176
  if (test2 && promise instanceof Promise) {
4485
4177
  promise = promise.finally(() => {
4486
- if (!test2.promises) {
4487
- return;
4488
- }
4178
+ if (!test2.promises) return;
4489
4179
  const index = test2.promises.indexOf(promise);
4490
- if (index !== -1) {
4491
- test2.promises.splice(index, 1);
4492
- }
4180
+ if (index !== -1) test2.promises.splice(index, 1);
4493
4181
  });
4494
- if (!test2.promises) {
4495
- test2.promises = [];
4496
- }
4182
+ if (!test2.promises) test2.promises = [];
4497
4183
  test2.promises.push(promise);
4498
4184
  let resolved = false;
4499
4185
  test2.onFinished ??= [];
4500
4186
  test2.onFinished.push(() => {
4501
4187
  if (!resolved) {
4502
- const processor = globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || "");
4503
- const stack = processor(error.stack);
4188
+ const stack = (globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || ""))(error.stack);
4504
4189
  console.warn([
4505
4190
  `Promise returned by \`${assertion}\` was not awaited. `,
4506
4191
  "Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
@@ -4510,9 +4195,9 @@ function recordAsyncExpect(_test, promise, assertion, error) {
4510
4195
  }
4511
4196
  });
4512
4197
  return {
4513
- then(onFullfilled, onRejected) {
4198
+ then(onFulfilled, onRejected) {
4514
4199
  resolved = true;
4515
- return promise.then(onFullfilled, onRejected);
4200
+ return promise.then(onFulfilled, onRejected);
4516
4201
  },
4517
4202
  catch(onRejected) {
4518
4203
  return promise.catch(onRejected);
@@ -4527,22 +4212,14 @@ function recordAsyncExpect(_test, promise, assertion, error) {
4527
4212
  }
4528
4213
  var _client;
4529
4214
  function getSnapshotClient() {
4530
- if (!_client) {
4531
- _client = new SnapshotClient({
4532
- isEqual: (received, expected) => {
4533
- return equals(received, expected, [iterableEquality, subsetEquality]);
4534
- }
4535
- });
4536
- }
4215
+ if (!_client) _client = new SnapshotClient({ isEqual: (received, expected) => {
4216
+ return equals(received, expected, [iterableEquality, subsetEquality]);
4217
+ } });
4537
4218
  return _client;
4538
4219
  }
4539
4220
  function getError(expected, promise) {
4540
4221
  if (typeof expected !== "function") {
4541
- if (!promise) {
4542
- throw new Error(
4543
- `expected must be a function, received ${typeof expected}`
4544
- );
4545
- }
4222
+ if (!promise) throw new Error(`expected must be a function, received ${typeof expected}`);
4546
4223
  return expected;
4547
4224
  }
4548
4225
  try {
@@ -4553,248 +4230,174 @@ function getError(expected, promise) {
4553
4230
  throw new Error("snapshot function didn't throw");
4554
4231
  }
4555
4232
  function getTestNames(test2) {
4556
- if (!test2) {
4557
- return {};
4558
- }
4559
4233
  return {
4560
4234
  filepath: test2.file.filepath,
4561
- name: getNames(test2).slice(1).join(" > ")
4235
+ name: getNames(test2).slice(1).join(" > "),
4236
+ testId: test2.id
4562
4237
  };
4563
4238
  }
4564
4239
  var SnapshotPlugin = (chai3, utils) => {
4565
- for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
4566
- utils.addMethod(
4567
- chai3.Assertion.prototype,
4568
- key,
4569
- function(properties, message) {
4570
- utils.flag(this, "_name", key);
4571
- const isNot = utils.flag(this, "negate");
4572
- if (isNot) {
4573
- throw new Error(`${key} cannot be used with "not"`);
4574
- }
4575
- const expected = utils.flag(this, "object");
4576
- const test2 = utils.flag(this, "vitest-test");
4577
- if (typeof properties === "string" && typeof message === "undefined") {
4578
- message = properties;
4579
- properties = void 0;
4580
- }
4581
- const errorMessage = utils.flag(this, "message");
4582
- getSnapshotClient().assert({
4583
- received: expected,
4584
- message,
4585
- isInline: false,
4586
- properties,
4587
- errorMessage,
4588
- ...getTestNames(test2)
4589
- });
4590
- }
4591
- );
4592
- }
4593
- utils.addMethod(
4594
- chai3.Assertion.prototype,
4595
- "toMatchFileSnapshot",
4596
- function(file, message) {
4597
- utils.flag(this, "_name", "toMatchFileSnapshot");
4598
- const isNot = utils.flag(this, "negate");
4599
- if (isNot) {
4600
- throw new Error('toMatchFileSnapshot cannot be used with "not"');
4601
- }
4602
- const error = new Error("resolves");
4603
- const expected = utils.flag(this, "object");
4604
- const test2 = utils.flag(this, "vitest-test");
4605
- const errorMessage = utils.flag(this, "message");
4606
- const promise = getSnapshotClient().assertRaw({
4607
- received: expected,
4608
- message,
4609
- isInline: false,
4610
- rawSnapshot: {
4611
- file
4612
- },
4613
- errorMessage,
4614
- ...getTestNames(test2)
4615
- });
4616
- return recordAsyncExpect(
4617
- test2,
4618
- promise,
4619
- createAssertionMessage(utils, this),
4620
- error
4621
- );
4622
- }
4623
- );
4624
- utils.addMethod(
4625
- chai3.Assertion.prototype,
4626
- "toMatchInlineSnapshot",
4627
- function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
4628
- utils.flag(this, "_name", "toMatchInlineSnapshot");
4629
- const isNot = utils.flag(this, "negate");
4630
- if (isNot) {
4631
- throw new Error('toMatchInlineSnapshot cannot be used with "not"');
4632
- }
4633
- const test2 = utils.flag(this, "vitest-test");
4634
- const isInsideEach = test2 && (test2.each || test2.suite?.each);
4635
- if (isInsideEach) {
4636
- throw new Error(
4637
- "InlineSnapshot cannot be used inside of test.each or describe.each"
4638
- );
4639
- }
4640
- const expected = utils.flag(this, "object");
4641
- const error = utils.flag(this, "error");
4642
- if (typeof properties === "string") {
4643
- message = inlineSnapshot;
4644
- inlineSnapshot = properties;
4645
- properties = void 0;
4646
- }
4647
- if (inlineSnapshot) {
4648
- inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
4649
- }
4650
- const errorMessage = utils.flag(this, "message");
4651
- getSnapshotClient().assert({
4652
- received: expected,
4653
- message,
4654
- isInline: true,
4655
- properties,
4656
- inlineSnapshot,
4657
- error,
4658
- errorMessage,
4659
- ...getTestNames(test2)
4660
- });
4661
- }
4662
- );
4663
- utils.addMethod(
4664
- chai3.Assertion.prototype,
4665
- "toThrowErrorMatchingSnapshot",
4666
- function(message) {
4667
- utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
4668
- const isNot = utils.flag(this, "negate");
4669
- if (isNot) {
4670
- throw new Error(
4671
- 'toThrowErrorMatchingSnapshot cannot be used with "not"'
4672
- );
4673
- }
4674
- const expected = utils.flag(this, "object");
4675
- const test2 = utils.flag(this, "vitest-test");
4676
- const promise = utils.flag(this, "promise");
4677
- const errorMessage = utils.flag(this, "message");
4678
- getSnapshotClient().assert({
4679
- received: getError(expected, promise),
4680
- message,
4681
- errorMessage,
4682
- ...getTestNames(test2)
4683
- });
4684
- }
4685
- );
4686
- utils.addMethod(
4687
- chai3.Assertion.prototype,
4688
- "toThrowErrorMatchingInlineSnapshot",
4689
- function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
4690
- const isNot = utils.flag(this, "negate");
4691
- if (isNot) {
4692
- throw new Error(
4693
- 'toThrowErrorMatchingInlineSnapshot cannot be used with "not"'
4694
- );
4695
- }
4696
- const test2 = utils.flag(this, "vitest-test");
4697
- const isInsideEach = test2 && (test2.each || test2.suite?.each);
4698
- if (isInsideEach) {
4699
- throw new Error(
4700
- "InlineSnapshot cannot be used inside of test.each or describe.each"
4701
- );
4702
- }
4703
- const expected = utils.flag(this, "object");
4704
- const error = utils.flag(this, "error");
4705
- const promise = utils.flag(this, "promise");
4706
- const errorMessage = utils.flag(this, "message");
4707
- if (inlineSnapshot) {
4708
- inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
4709
- }
4710
- getSnapshotClient().assert({
4711
- received: getError(expected, promise),
4712
- message,
4713
- inlineSnapshot,
4714
- isInline: true,
4715
- error,
4716
- errorMessage,
4717
- ...getTestNames(test2)
4718
- });
4719
- }
4720
- );
4240
+ function getTest(assertionName, obj) {
4241
+ const test2 = utils.flag(obj, "vitest-test");
4242
+ if (!test2) throw new Error(`'${assertionName}' cannot be used without test context`);
4243
+ return test2;
4244
+ }
4245
+ for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai3.Assertion.prototype, key, function(properties, message) {
4246
+ utils.flag(this, "_name", key);
4247
+ if (utils.flag(this, "negate")) throw new Error(`${key} cannot be used with "not"`);
4248
+ const expected = utils.flag(this, "object");
4249
+ const test2 = getTest(key, this);
4250
+ if (typeof properties === "string" && typeof message === "undefined") {
4251
+ message = properties;
4252
+ properties = void 0;
4253
+ }
4254
+ const errorMessage = utils.flag(this, "message");
4255
+ getSnapshotClient().assert({
4256
+ received: expected,
4257
+ message,
4258
+ isInline: false,
4259
+ properties,
4260
+ errorMessage,
4261
+ ...getTestNames(test2)
4262
+ });
4263
+ });
4264
+ utils.addMethod(chai3.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
4265
+ utils.flag(this, "_name", "toMatchFileSnapshot");
4266
+ if (utils.flag(this, "negate")) throw new Error('toMatchFileSnapshot cannot be used with "not"');
4267
+ const error = /* @__PURE__ */ new Error("resolves");
4268
+ const expected = utils.flag(this, "object");
4269
+ const test2 = getTest("toMatchFileSnapshot", this);
4270
+ const errorMessage = utils.flag(this, "message");
4271
+ return recordAsyncExpect(test2, getSnapshotClient().assertRaw({
4272
+ received: expected,
4273
+ message,
4274
+ isInline: false,
4275
+ rawSnapshot: { file },
4276
+ errorMessage,
4277
+ ...getTestNames(test2)
4278
+ }), createAssertionMessage(utils, this), error);
4279
+ });
4280
+ utils.addMethod(chai3.Assertion.prototype, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
4281
+ utils.flag(this, "_name", "toMatchInlineSnapshot");
4282
+ if (utils.flag(this, "negate")) throw new Error('toMatchInlineSnapshot cannot be used with "not"');
4283
+ const test2 = getTest("toMatchInlineSnapshot", this);
4284
+ if (test2.each || test2.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
4285
+ const expected = utils.flag(this, "object");
4286
+ const error = utils.flag(this, "error");
4287
+ if (typeof properties === "string") {
4288
+ message = inlineSnapshot;
4289
+ inlineSnapshot = properties;
4290
+ properties = void 0;
4291
+ }
4292
+ if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
4293
+ const errorMessage = utils.flag(this, "message");
4294
+ getSnapshotClient().assert({
4295
+ received: expected,
4296
+ message,
4297
+ isInline: true,
4298
+ properties,
4299
+ inlineSnapshot,
4300
+ error,
4301
+ errorMessage,
4302
+ ...getTestNames(test2)
4303
+ });
4304
+ });
4305
+ utils.addMethod(chai3.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
4306
+ utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
4307
+ if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingSnapshot cannot be used with "not"');
4308
+ const expected = utils.flag(this, "object");
4309
+ const test2 = getTest("toThrowErrorMatchingSnapshot", this);
4310
+ const promise = utils.flag(this, "promise");
4311
+ const errorMessage = utils.flag(this, "message");
4312
+ getSnapshotClient().assert({
4313
+ received: getError(expected, promise),
4314
+ message,
4315
+ errorMessage,
4316
+ ...getTestNames(test2)
4317
+ });
4318
+ });
4319
+ utils.addMethod(chai3.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT__(inlineSnapshot, message) {
4320
+ if (utils.flag(this, "negate")) throw new Error('toThrowErrorMatchingInlineSnapshot cannot be used with "not"');
4321
+ const test2 = getTest("toThrowErrorMatchingInlineSnapshot", this);
4322
+ if (test2.each || test2.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
4323
+ const expected = utils.flag(this, "object");
4324
+ const error = utils.flag(this, "error");
4325
+ const promise = utils.flag(this, "promise");
4326
+ const errorMessage = utils.flag(this, "message");
4327
+ if (inlineSnapshot) inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
4328
+ getSnapshotClient().assert({
4329
+ received: getError(expected, promise),
4330
+ message,
4331
+ inlineSnapshot,
4332
+ isInline: true,
4333
+ error,
4334
+ errorMessage,
4335
+ ...getTestNames(test2)
4336
+ });
4337
+ });
4721
4338
  utils.addMethod(chai3.expect, "addSnapshotSerializer", addSerializer);
4722
4339
  };
4723
- chai$1.use(JestExtend);
4724
- chai$1.use(JestChaiExpect);
4725
- chai$1.use(Subset);
4726
- chai$1.use(SnapshotPlugin);
4727
- chai$1.use(JestAsymmetricMatchers);
4340
+ chai.use(JestExtend);
4341
+ chai.use(JestChaiExpect);
4342
+ chai.use(SnapshotPlugin);
4343
+ chai.use(JestAsymmetricMatchers);
4728
4344
  function createExpect(test2) {
4729
- const expect2 = (value, message) => {
4730
- const { assertionCalls } = getState(expect2);
4731
- setState({ assertionCalls: assertionCalls + 1 }, expect2);
4732
- const assert22 = chai$1.expect(value, message);
4345
+ const expect = ((value, message) => {
4346
+ const { assertionCalls } = getState(expect);
4347
+ setState({ assertionCalls: assertionCalls + 1 }, expect);
4348
+ const assert2 = chai.expect(value, message);
4733
4349
  const _test = getCurrentTest();
4734
- if (_test) {
4735
- return assert22.withTest(_test);
4736
- } else {
4737
- return assert22;
4738
- }
4739
- };
4740
- Object.assign(expect2, chai$1.expect);
4741
- Object.assign(expect2, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
4742
- expect2.getState = () => getState(expect2);
4743
- expect2.setState = (state) => setState(state, expect2);
4350
+ if (_test)
4351
+ return assert2.withTest(_test);
4352
+ else return assert2;
4353
+ });
4354
+ Object.assign(expect, chai.expect);
4355
+ Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
4356
+ expect.getState = () => getState(expect);
4357
+ expect.setState = (state) => setState(state, expect);
4744
4358
  const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
4745
- setState(
4746
- {
4747
- // this should also add "snapshotState" that is added conditionally
4748
- ...globalState,
4749
- assertionCalls: 0,
4750
- isExpectingAssertions: false,
4751
- isExpectingAssertionsError: null,
4752
- expectedAssertionsNumber: null,
4753
- expectedAssertionsNumberErrorGen: null,
4754
- environment: getCurrentEnvironment(),
4755
- get testPath() {
4756
- return getWorkerState().filepath;
4757
- },
4758
- currentTestName: globalState.currentTestName
4359
+ setState({
4360
+ ...globalState,
4361
+ assertionCalls: 0,
4362
+ isExpectingAssertions: false,
4363
+ isExpectingAssertionsError: null,
4364
+ expectedAssertionsNumber: null,
4365
+ expectedAssertionsNumberErrorGen: null,
4366
+ get testPath() {
4367
+ return getWorkerState().filepath;
4759
4368
  },
4760
- expect2
4761
- );
4762
- expect2.extend = (matchers) => chai$1.expect.extend(expect2, matchers);
4763
- expect2.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
4764
- expect2.soft = (...args) => {
4765
- return expect2(...args).withContext({ soft: true });
4369
+ currentTestName: globalState.currentTestName
4370
+ }, expect);
4371
+ expect.assert = chai.assert;
4372
+ expect.extend = (matchers) => chai.expect.extend(expect, matchers);
4373
+ expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
4374
+ expect.soft = (...args) => {
4375
+ return expect(...args).withContext({ soft: true });
4766
4376
  };
4767
- expect2.poll = createExpectPoll(expect2);
4768
- expect2.unreachable = (message) => {
4769
- chai$1.assert.fail(
4770
- `expected${message ? ` "${message}" ` : " "}not to be reached`
4771
- );
4377
+ expect.poll = createExpectPoll(expect);
4378
+ expect.unreachable = (message) => {
4379
+ chai.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
4772
4380
  };
4773
4381
  function assertions(expected) {
4774
- const errorGen = () => new Error(
4775
- `expected number of assertions to be ${expected}, but got ${expect2.getState().assertionCalls}`
4776
- );
4777
- if (Error.captureStackTrace) {
4778
- Error.captureStackTrace(errorGen(), assertions);
4779
- }
4780
- expect2.setState({
4382
+ const errorGen = () => /* @__PURE__ */ new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
4383
+ if (Error.captureStackTrace) Error.captureStackTrace(errorGen(), assertions);
4384
+ expect.setState({
4781
4385
  expectedAssertionsNumber: expected,
4782
4386
  expectedAssertionsNumberErrorGen: errorGen
4783
4387
  });
4784
4388
  }
4785
4389
  function hasAssertions() {
4786
- const error = new Error("expected any number of assertion, but got none");
4787
- if (Error.captureStackTrace) {
4788
- Error.captureStackTrace(error, hasAssertions);
4789
- }
4790
- expect2.setState({
4390
+ const error = /* @__PURE__ */ new Error("expected any number of assertion, but got none");
4391
+ if (Error.captureStackTrace) Error.captureStackTrace(error, hasAssertions);
4392
+ expect.setState({
4791
4393
  isExpectingAssertions: true,
4792
4394
  isExpectingAssertionsError: error
4793
4395
  });
4794
4396
  }
4795
- chai$1.util.addMethod(expect2, "assertions", assertions);
4796
- chai$1.util.addMethod(expect2, "hasAssertions", hasAssertions);
4797
- return expect2;
4397
+ chai.util.addMethod(expect, "assertions", assertions);
4398
+ chai.util.addMethod(expect, "hasAssertions", hasAssertions);
4399
+ expect.extend(customMatchers);
4400
+ return expect;
4798
4401
  }
4799
4402
  var globalExpect = createExpect();
4800
4403
  Object.defineProperty(globalThis, GLOBAL_EXPECT, {
@@ -4802,6 +4405,8 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
4802
4405
  writable: true,
4803
4406
  configurable: true
4804
4407
  });
4408
+ chai.assert;
4409
+ chai.should;
4805
4410
  var fakeTimersSrc = {};
4806
4411
  var global2;
4807
4412
  var hasRequiredGlobal;
@@ -4909,42 +4514,14 @@ function requireCalledInOrder() {
4909
4514
  calledInOrder_1 = calledInOrder;
4910
4515
  return calledInOrder_1;
4911
4516
  }
4912
- var functionName;
4913
- var hasRequiredFunctionName;
4914
- function requireFunctionName() {
4915
- if (hasRequiredFunctionName) return functionName;
4916
- hasRequiredFunctionName = 1;
4917
- functionName = function functionName2(func) {
4918
- if (!func) {
4919
- return "";
4920
- }
4921
- try {
4922
- return func.displayName || func.name || // Use function decomposition as a last resort to get function
4923
- // name. Does not rely on function decomposition to work - if it
4924
- // doesn't debugging will be slightly less informative
4925
- // (i.e. toString will say 'spy' rather than 'myFunc').
4926
- (String(func).match(/function ([^\s(]+)/) || [])[1];
4927
- } catch (e) {
4928
- return "";
4929
- }
4930
- };
4931
- return functionName;
4932
- }
4933
4517
  var className_1;
4934
4518
  var hasRequiredClassName;
4935
4519
  function requireClassName() {
4936
4520
  if (hasRequiredClassName) return className_1;
4937
4521
  hasRequiredClassName = 1;
4938
- var functionName2 = requireFunctionName();
4939
4522
  function className(value) {
4940
- return value.constructor && value.constructor.name || // The next branch is for IE11 support only:
4941
- // Because the name property is not set on the prototype
4942
- // of the Function object, we finally try to grab the
4943
- // name from its definition. This will never be reached
4944
- // in node, so we are not able to test this properly.
4945
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
4946
- typeof value.constructor === "function" && /* istanbul ignore next */
4947
- functionName2(value.constructor) || null;
4523
+ const name = value.constructor && value.constructor.name;
4524
+ return name || null;
4948
4525
  }
4949
4526
  className_1 = className;
4950
4527
  return className_1;
@@ -5000,6 +4577,27 @@ function requireEvery() {
5000
4577
  };
5001
4578
  return every;
5002
4579
  }
4580
+ var functionName;
4581
+ var hasRequiredFunctionName;
4582
+ function requireFunctionName() {
4583
+ if (hasRequiredFunctionName) return functionName;
4584
+ hasRequiredFunctionName = 1;
4585
+ functionName = function functionName2(func) {
4586
+ if (!func) {
4587
+ return "";
4588
+ }
4589
+ try {
4590
+ return func.displayName || func.name || // Use function decomposition as a last resort to get function
4591
+ // name. Does not rely on function decomposition to work - if it
4592
+ // doesn't debugging will be slightly less informative
4593
+ // (i.e. toString will say 'spy' rather than 'myFunc').
4594
+ (String(func).match(/function ([^\s(]+)/) || [])[1];
4595
+ } catch (e) {
4596
+ return "";
4597
+ }
4598
+ };
4599
+ return functionName;
4600
+ }
5003
4601
  var orderByFirstCall_1;
5004
4602
  var hasRequiredOrderByFirstCall;
5005
4603
  function requireOrderByFirstCall() {
@@ -5251,12 +4849,16 @@ function requireFakeTimersSrc() {
5251
4849
  if (hasRequiredFakeTimersSrc) return fakeTimersSrc;
5252
4850
  hasRequiredFakeTimersSrc = 1;
5253
4851
  const globalObject = requireLib().global;
5254
- let timersModule;
4852
+ let timersModule, timersPromisesModule;
5255
4853
  if (typeof __vitest_required__ !== "undefined") {
5256
4854
  try {
5257
4855
  timersModule = __vitest_required__.timers;
5258
4856
  } catch (e) {
5259
4857
  }
4858
+ try {
4859
+ timersPromisesModule = __vitest_required__.timersPromises;
4860
+ } catch (e) {
4861
+ }
5260
4862
  }
5261
4863
  function withGlobal(_global) {
5262
4864
  const maxTimeout = Math.pow(2, 31) - 1;
@@ -5267,26 +4869,57 @@ function requireFakeTimersSrc() {
5267
4869
  const NOOP_ARRAY = function() {
5268
4870
  return [];
5269
4871
  };
5270
- const timeoutResult = _global.setTimeout(NOOP, 0);
5271
- const addTimerReturnsObject = typeof timeoutResult === "object";
5272
- const hrtimePresent = _global.process && typeof _global.process.hrtime === "function";
5273
- const hrtimeBigintPresent = hrtimePresent && typeof _global.process.hrtime.bigint === "function";
5274
- const nextTickPresent = _global.process && typeof _global.process.nextTick === "function";
4872
+ const isPresent = {};
4873
+ let timeoutResult, addTimerReturnsObject = false;
4874
+ if (_global.setTimeout) {
4875
+ isPresent.setTimeout = true;
4876
+ timeoutResult = _global.setTimeout(NOOP, 0);
4877
+ addTimerReturnsObject = typeof timeoutResult === "object";
4878
+ }
4879
+ isPresent.clearTimeout = Boolean(_global.clearTimeout);
4880
+ isPresent.setInterval = Boolean(_global.setInterval);
4881
+ isPresent.clearInterval = Boolean(_global.clearInterval);
4882
+ isPresent.hrtime = _global.process && typeof _global.process.hrtime === "function";
4883
+ isPresent.hrtimeBigint = isPresent.hrtime && typeof _global.process.hrtime.bigint === "function";
4884
+ isPresent.nextTick = _global.process && typeof _global.process.nextTick === "function";
5275
4885
  const utilPromisify = _global.process && _global.__vitest_required__ && _global.__vitest_required__.util.promisify;
5276
- const performancePresent = _global.performance && typeof _global.performance.now === "function";
4886
+ isPresent.performance = _global.performance && typeof _global.performance.now === "function";
5277
4887
  const hasPerformancePrototype = _global.Performance && (typeof _global.Performance).match(/^(function|object)$/);
5278
4888
  const hasPerformanceConstructorPrototype = _global.performance && _global.performance.constructor && _global.performance.constructor.prototype;
5279
- const queueMicrotaskPresent = _global.hasOwnProperty("queueMicrotask");
5280
- const requestAnimationFramePresent = _global.requestAnimationFrame && typeof _global.requestAnimationFrame === "function";
5281
- const cancelAnimationFramePresent = _global.cancelAnimationFrame && typeof _global.cancelAnimationFrame === "function";
5282
- const requestIdleCallbackPresent = _global.requestIdleCallback && typeof _global.requestIdleCallback === "function";
5283
- const cancelIdleCallbackPresent = _global.cancelIdleCallback && typeof _global.cancelIdleCallback === "function";
5284
- const setImmediatePresent = _global.setImmediate && typeof _global.setImmediate === "function";
5285
- const intlPresent = _global.Intl && typeof _global.Intl === "object";
5286
- _global.clearTimeout(timeoutResult);
4889
+ isPresent.queueMicrotask = _global.hasOwnProperty("queueMicrotask");
4890
+ isPresent.requestAnimationFrame = _global.requestAnimationFrame && typeof _global.requestAnimationFrame === "function";
4891
+ isPresent.cancelAnimationFrame = _global.cancelAnimationFrame && typeof _global.cancelAnimationFrame === "function";
4892
+ isPresent.requestIdleCallback = _global.requestIdleCallback && typeof _global.requestIdleCallback === "function";
4893
+ isPresent.cancelIdleCallbackPresent = _global.cancelIdleCallback && typeof _global.cancelIdleCallback === "function";
4894
+ isPresent.setImmediate = _global.setImmediate && typeof _global.setImmediate === "function";
4895
+ isPresent.clearImmediate = _global.clearImmediate && typeof _global.clearImmediate === "function";
4896
+ isPresent.Intl = _global.Intl && typeof _global.Intl === "object";
4897
+ if (_global.clearTimeout) {
4898
+ _global.clearTimeout(timeoutResult);
4899
+ }
5287
4900
  const NativeDate = _global.Date;
5288
- const NativeIntl = _global.Intl;
4901
+ const NativeIntl = isPresent.Intl ? Object.defineProperties(
4902
+ /* @__PURE__ */ Object.create(null),
4903
+ Object.getOwnPropertyDescriptors(_global.Intl)
4904
+ ) : void 0;
5289
4905
  let uniqueTimerId = idCounterStart;
4906
+ if (NativeDate === void 0) {
4907
+ throw new Error(
4908
+ "The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
4909
+ );
4910
+ }
4911
+ isPresent.Date = true;
4912
+ class FakePerformanceEntry {
4913
+ constructor(name, entryType, startTime, duration) {
4914
+ this.name = name;
4915
+ this.entryType = entryType;
4916
+ this.startTime = startTime;
4917
+ this.duration = duration;
4918
+ }
4919
+ toJSON() {
4920
+ return JSON.stringify({ ...this });
4921
+ }
4922
+ }
5290
4923
  function isNumberFinite(num) {
5291
4924
  if (Number.isFinite) {
5292
4925
  return Number.isFinite(num);
@@ -5387,80 +5020,66 @@ ${job.error.stack.split("\n").slice(matchedLineIndex + 1).join("\n")}`;
5387
5020
  }
5388
5021
  return infiniteLoopError;
5389
5022
  }
5390
- function mirrorDateProperties(target, source) {
5391
- let prop;
5392
- for (prop in source) {
5393
- if (source.hasOwnProperty(prop)) {
5394
- target[prop] = source[prop];
5023
+ function createDate() {
5024
+ class ClockDate extends NativeDate {
5025
+ /**
5026
+ * @param {number} year
5027
+ * @param {number} month
5028
+ * @param {number} date
5029
+ * @param {number} hour
5030
+ * @param {number} minute
5031
+ * @param {number} second
5032
+ * @param {number} ms
5033
+ * @returns void
5034
+ */
5035
+ // eslint-disable-next-line no-unused-vars
5036
+ constructor(year, month, date, hour, minute, second, ms) {
5037
+ if (arguments.length === 0) {
5038
+ super(ClockDate.clock.now);
5039
+ } else {
5040
+ super(...arguments);
5041
+ }
5042
+ Object.defineProperty(this, "constructor", {
5043
+ value: NativeDate,
5044
+ enumerable: false
5045
+ });
5046
+ }
5047
+ static [Symbol.hasInstance](instance) {
5048
+ return instance instanceof NativeDate;
5395
5049
  }
5396
5050
  }
5397
- if (source.now) {
5398
- target.now = function now2() {
5399
- return target.clock.now;
5051
+ ClockDate.isFake = true;
5052
+ if (NativeDate.now) {
5053
+ ClockDate.now = function now2() {
5054
+ return ClockDate.clock.now;
5400
5055
  };
5401
- } else {
5402
- delete target.now;
5403
5056
  }
5404
- if (source.toSource) {
5405
- target.toSource = function toSource() {
5406
- return source.toSource();
5057
+ if (NativeDate.toSource) {
5058
+ ClockDate.toSource = function toSource() {
5059
+ return NativeDate.toSource();
5407
5060
  };
5408
- } else {
5409
- delete target.toSource;
5410
5061
  }
5411
- target.toString = function toString() {
5412
- return source.toString();
5062
+ ClockDate.toString = function toString() {
5063
+ return NativeDate.toString();
5413
5064
  };
5414
- target.prototype = source.prototype;
5415
- target.parse = source.parse;
5416
- target.UTC = source.UTC;
5417
- target.prototype.toUTCString = source.prototype.toUTCString;
5418
- target.isFake = true;
5419
- return target;
5420
- }
5421
- function createDate() {
5422
- function ClockDate(year, month, date, hour, minute, second, ms) {
5423
- if (!(this instanceof ClockDate)) {
5424
- return new NativeDate(ClockDate.clock.now).toString();
5425
- }
5426
- switch (arguments.length) {
5427
- case 0:
5428
- return new NativeDate(ClockDate.clock.now);
5429
- case 1:
5430
- return new NativeDate(year);
5431
- case 2:
5432
- return new NativeDate(year, month);
5433
- case 3:
5434
- return new NativeDate(year, month, date);
5435
- case 4:
5436
- return new NativeDate(year, month, date, hour);
5437
- case 5:
5438
- return new NativeDate(year, month, date, hour, minute);
5439
- case 6:
5440
- return new NativeDate(
5441
- year,
5442
- month,
5443
- date,
5444
- hour,
5445
- minute,
5446
- second
5447
- );
5448
- default:
5449
- return new NativeDate(
5450
- year,
5451
- month,
5452
- date,
5453
- hour,
5454
- minute,
5455
- second,
5456
- ms
5065
+ const ClockDateProxy = new Proxy(ClockDate, {
5066
+ // handler for [[Call]] invocations (i.e. not using `new`)
5067
+ apply() {
5068
+ if (this instanceof ClockDate) {
5069
+ throw new TypeError(
5070
+ "A Proxy should only capture `new` calls with the `construct` handler. This is not supposed to be possible, so check the logic."
5457
5071
  );
5072
+ }
5073
+ return new NativeDate(ClockDate.clock.now).toString();
5458
5074
  }
5459
- }
5460
- return mirrorDateProperties(ClockDate, NativeDate);
5075
+ });
5076
+ return ClockDateProxy;
5461
5077
  }
5462
5078
  function createIntl() {
5463
- const ClockIntl = { ...NativeIntl };
5079
+ const ClockIntl = {};
5080
+ Object.getOwnPropertyNames(NativeIntl).forEach(
5081
+ (property) => ClockIntl[property] = NativeIntl[property]
5082
+ );
5464
5083
  ClockIntl.DateTimeFormat = function(...args) {
5465
5084
  const realFormatter = new NativeIntl.DateTimeFormat(...args);
5466
5085
  const formatter = {};
@@ -5746,11 +5365,21 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
5746
5365
  timersModule[entry.methodName] = entry.original;
5747
5366
  }
5748
5367
  }
5368
+ if (clock.timersPromisesModuleMethods !== void 0) {
5369
+ for (let j = 0; j < clock.timersPromisesModuleMethods.length; j++) {
5370
+ const entry = clock.timersPromisesModuleMethods[j];
5371
+ timersPromisesModule[entry.methodName] = entry.original;
5372
+ }
5373
+ }
5749
5374
  }
5750
5375
  if (config2.shouldAdvanceTime === true) {
5751
5376
  _global.clearInterval(clock.attachedInterval);
5752
5377
  }
5753
5378
  clock.methods = [];
5379
+ for (const [listener, signal] of clock.abortListenerMap.entries()) {
5380
+ signal.removeEventListener("abort", listener);
5381
+ clock.abortListenerMap.delete(listener);
5382
+ }
5754
5383
  if (!clock.timers) {
5755
5384
  return [];
5756
5385
  }
@@ -5765,8 +5394,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
5765
5394
  );
5766
5395
  clock[`_${method}`] = target[method];
5767
5396
  if (method === "Date") {
5768
- const date = mirrorDateProperties(clock[method], target[method]);
5769
- target[method] = date;
5397
+ target[method] = clock[method];
5770
5398
  } else if (method === "Intl") {
5771
5399
  target[method] = clock[method];
5772
5400
  } else if (method === "performance") {
@@ -5809,36 +5437,38 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
5809
5437
  clearInterval: _global.clearInterval,
5810
5438
  Date: _global.Date
5811
5439
  };
5812
- if (setImmediatePresent) {
5440
+ if (isPresent.setImmediate) {
5813
5441
  timers.setImmediate = _global.setImmediate;
5442
+ }
5443
+ if (isPresent.clearImmediate) {
5814
5444
  timers.clearImmediate = _global.clearImmediate;
5815
5445
  }
5816
- if (hrtimePresent) {
5446
+ if (isPresent.hrtime) {
5817
5447
  timers.hrtime = _global.process.hrtime;
5818
5448
  }
5819
- if (nextTickPresent) {
5449
+ if (isPresent.nextTick) {
5820
5450
  timers.nextTick = _global.process.nextTick;
5821
5451
  }
5822
- if (performancePresent) {
5452
+ if (isPresent.performance) {
5823
5453
  timers.performance = _global.performance;
5824
5454
  }
5825
- if (requestAnimationFramePresent) {
5455
+ if (isPresent.requestAnimationFrame) {
5826
5456
  timers.requestAnimationFrame = _global.requestAnimationFrame;
5827
5457
  }
5828
- if (queueMicrotaskPresent) {
5829
- timers.queueMicrotask = true;
5458
+ if (isPresent.queueMicrotask) {
5459
+ timers.queueMicrotask = _global.queueMicrotask;
5830
5460
  }
5831
- if (cancelAnimationFramePresent) {
5461
+ if (isPresent.cancelAnimationFrame) {
5832
5462
  timers.cancelAnimationFrame = _global.cancelAnimationFrame;
5833
5463
  }
5834
- if (requestIdleCallbackPresent) {
5464
+ if (isPresent.requestIdleCallback) {
5835
5465
  timers.requestIdleCallback = _global.requestIdleCallback;
5836
5466
  }
5837
- if (cancelIdleCallbackPresent) {
5467
+ if (isPresent.cancelIdleCallback) {
5838
5468
  timers.cancelIdleCallback = _global.cancelIdleCallback;
5839
5469
  }
5840
- if (intlPresent) {
5841
- timers.Intl = _global.Intl;
5470
+ if (isPresent.Intl) {
5471
+ timers.Intl = NativeIntl;
5842
5472
  }
5843
5473
  const originalSetTimeout = _global.setImmediate || _global.setTimeout;
5844
5474
  function createClock(start, loopLimit) {
@@ -5846,11 +5476,6 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
5846
5476
  loopLimit = loopLimit || 1e3;
5847
5477
  let nanos = 0;
5848
5478
  const adjustedSystemTime = [0, 0];
5849
- if (NativeDate === void 0) {
5850
- throw new Error(
5851
- "The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)"
5852
- );
5853
- }
5854
5479
  const clock = {
5855
5480
  now: start,
5856
5481
  Date: createDate(),
@@ -5886,13 +5511,13 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
5886
5511
  const millis = hrt[0] * 1e3 + hrt[1] / 1e6;
5887
5512
  return millis;
5888
5513
  }
5889
- if (hrtimeBigintPresent) {
5514
+ if (isPresent.hrtimeBigint) {
5890
5515
  hrtime.bigint = function() {
5891
5516
  const parts = hrtime();
5892
5517
  return BigInt(parts[0]) * BigInt(1e9) + BigInt(parts[1]);
5893
5518
  };
5894
5519
  }
5895
- if (intlPresent) {
5520
+ if (isPresent.Intl) {
5896
5521
  clock.Intl = createIntl();
5897
5522
  clock.Intl.clock = clock;
5898
5523
  }
@@ -5955,7 +5580,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
5955
5580
  clock.clearInterval = function clearInterval2(timerId) {
5956
5581
  return clearTimer(clock, timerId, "Interval");
5957
5582
  };
5958
- if (setImmediatePresent) {
5583
+ if (isPresent.setImmediate) {
5959
5584
  clock.setImmediate = function setImmediate(func) {
5960
5585
  return addTimer(clock, {
5961
5586
  func,
@@ -6188,6 +5813,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
6188
5813
  function doRun() {
6189
5814
  originalSetTimeout(function() {
6190
5815
  try {
5816
+ runJobs(clock);
6191
5817
  let numTimers;
6192
5818
  if (i < clock.loopLimit) {
6193
5819
  if (!clock.timers) {
@@ -6235,6 +5861,7 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
6235
5861
  try {
6236
5862
  const timer = lastTimer(clock);
6237
5863
  if (!timer) {
5864
+ runJobs(clock);
6238
5865
  resolve(clock.now);
6239
5866
  }
6240
5867
  resolve(clock.tickAsync(timer.callAt - clock.now));
@@ -6277,11 +5904,11 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
6277
5904
  }
6278
5905
  clock.tick(ms);
6279
5906
  };
6280
- if (performancePresent) {
5907
+ if (isPresent.performance) {
6281
5908
  clock.performance = /* @__PURE__ */ Object.create(null);
6282
5909
  clock.performance.now = fakePerformanceNow;
6283
5910
  }
6284
- if (hrtimePresent) {
5911
+ if (isPresent.hrtime) {
6285
5912
  clock.hrtime = hrtime;
6286
5913
  }
6287
5914
  return clock;
@@ -6308,17 +5935,24 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
6308
5935
  "config.target is no longer supported. Use `withGlobal(target)` instead."
6309
5936
  );
6310
5937
  }
5938
+ function handleMissingTimer(timer) {
5939
+ if (config2.ignoreMissingTimers) {
5940
+ return;
5941
+ }
5942
+ throw new ReferenceError(
5943
+ `non-existent timers and/or objects cannot be faked: '${timer}'`
5944
+ );
5945
+ }
6311
5946
  let i, l;
6312
5947
  const clock = createClock(config2.now, config2.loopLimit);
6313
5948
  clock.shouldClearNativeTimers = config2.shouldClearNativeTimers;
6314
5949
  clock.uninstall = function() {
6315
5950
  return uninstall(clock, config2);
6316
5951
  };
5952
+ clock.abortListenerMap = /* @__PURE__ */ new Map();
6317
5953
  clock.methods = config2.toFake || [];
6318
5954
  if (clock.methods.length === 0) {
6319
- clock.methods = Object.keys(timers).filter(function(key) {
6320
- return key !== "nextTick" && key !== "queueMicrotask";
6321
- });
5955
+ clock.methods = Object.keys(timers);
6322
5956
  }
6323
5957
  if (config2.shouldAdvanceTime === true) {
6324
5958
  const intervalTick = doIntervalTick.bind(
@@ -6347,17 +5981,25 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
6347
5981
  clock.performance[name] = name.indexOf("getEntries") === 0 ? NOOP_ARRAY : NOOP;
6348
5982
  }
6349
5983
  });
5984
+ clock.performance.mark = (name) => new FakePerformanceEntry(name, "mark", 0, 0);
5985
+ clock.performance.measure = (name) => new FakePerformanceEntry(name, "measure", 0, 100);
5986
+ clock.performance.timeOrigin = getEpoch(config2.now);
6350
5987
  } else if ((config2.toFake || []).includes("performance")) {
6351
- throw new ReferenceError(
6352
- "non-existent performance object cannot be faked"
6353
- );
5988
+ return handleMissingTimer("performance");
6354
5989
  }
6355
5990
  }
6356
5991
  if (_global === globalObject && timersModule) {
6357
5992
  clock.timersModuleMethods = [];
6358
5993
  }
5994
+ if (_global === globalObject && timersPromisesModule) {
5995
+ clock.timersPromisesModuleMethods = [];
5996
+ }
6359
5997
  for (i = 0, l = clock.methods.length; i < l; i++) {
6360
5998
  const nameOfMethodToReplace = clock.methods[i];
5999
+ if (!isPresent[nameOfMethodToReplace]) {
6000
+ handleMissingTimer(nameOfMethodToReplace);
6001
+ continue;
6002
+ }
6361
6003
  if (nameOfMethodToReplace === "hrtime") {
6362
6004
  if (_global.process && typeof _global.process.hrtime === "function") {
6363
6005
  hijackMethod(_global.process, nameOfMethodToReplace, clock);
@@ -6377,6 +6019,194 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
6377
6019
  });
6378
6020
  timersModule[nameOfMethodToReplace] = _global[nameOfMethodToReplace];
6379
6021
  }
6022
+ if (clock.timersPromisesModuleMethods !== void 0) {
6023
+ if (nameOfMethodToReplace === "setTimeout") {
6024
+ clock.timersPromisesModuleMethods.push({
6025
+ methodName: "setTimeout",
6026
+ original: timersPromisesModule.setTimeout
6027
+ });
6028
+ timersPromisesModule.setTimeout = (delay2, value, options = {}) => new Promise((resolve, reject) => {
6029
+ const abort = () => {
6030
+ options.signal.removeEventListener(
6031
+ "abort",
6032
+ abort
6033
+ );
6034
+ clock.abortListenerMap.delete(abort);
6035
+ clock.clearTimeout(handle);
6036
+ reject(options.signal.reason);
6037
+ };
6038
+ const handle = clock.setTimeout(() => {
6039
+ if (options.signal) {
6040
+ options.signal.removeEventListener(
6041
+ "abort",
6042
+ abort
6043
+ );
6044
+ clock.abortListenerMap.delete(abort);
6045
+ }
6046
+ resolve(value);
6047
+ }, delay2);
6048
+ if (options.signal) {
6049
+ if (options.signal.aborted) {
6050
+ abort();
6051
+ } else {
6052
+ options.signal.addEventListener(
6053
+ "abort",
6054
+ abort
6055
+ );
6056
+ clock.abortListenerMap.set(
6057
+ abort,
6058
+ options.signal
6059
+ );
6060
+ }
6061
+ }
6062
+ });
6063
+ } else if (nameOfMethodToReplace === "setImmediate") {
6064
+ clock.timersPromisesModuleMethods.push({
6065
+ methodName: "setImmediate",
6066
+ original: timersPromisesModule.setImmediate
6067
+ });
6068
+ timersPromisesModule.setImmediate = (value, options = {}) => new Promise((resolve, reject) => {
6069
+ const abort = () => {
6070
+ options.signal.removeEventListener(
6071
+ "abort",
6072
+ abort
6073
+ );
6074
+ clock.abortListenerMap.delete(abort);
6075
+ clock.clearImmediate(handle);
6076
+ reject(options.signal.reason);
6077
+ };
6078
+ const handle = clock.setImmediate(() => {
6079
+ if (options.signal) {
6080
+ options.signal.removeEventListener(
6081
+ "abort",
6082
+ abort
6083
+ );
6084
+ clock.abortListenerMap.delete(abort);
6085
+ }
6086
+ resolve(value);
6087
+ });
6088
+ if (options.signal) {
6089
+ if (options.signal.aborted) {
6090
+ abort();
6091
+ } else {
6092
+ options.signal.addEventListener(
6093
+ "abort",
6094
+ abort
6095
+ );
6096
+ clock.abortListenerMap.set(
6097
+ abort,
6098
+ options.signal
6099
+ );
6100
+ }
6101
+ }
6102
+ });
6103
+ } else if (nameOfMethodToReplace === "setInterval") {
6104
+ clock.timersPromisesModuleMethods.push({
6105
+ methodName: "setInterval",
6106
+ original: timersPromisesModule.setInterval
6107
+ });
6108
+ timersPromisesModule.setInterval = (delay2, value, options = {}) => ({
6109
+ [Symbol.asyncIterator]: () => {
6110
+ const createResolvable = () => {
6111
+ let resolve, reject;
6112
+ const promise = new Promise((res, rej) => {
6113
+ resolve = res;
6114
+ reject = rej;
6115
+ });
6116
+ promise.resolve = resolve;
6117
+ promise.reject = reject;
6118
+ return promise;
6119
+ };
6120
+ let done = false;
6121
+ let hasThrown = false;
6122
+ let returnCall;
6123
+ let nextAvailable = 0;
6124
+ const nextQueue = [];
6125
+ const handle = clock.setInterval(() => {
6126
+ if (nextQueue.length > 0) {
6127
+ nextQueue.shift().resolve();
6128
+ } else {
6129
+ nextAvailable++;
6130
+ }
6131
+ }, delay2);
6132
+ const abort = () => {
6133
+ options.signal.removeEventListener(
6134
+ "abort",
6135
+ abort
6136
+ );
6137
+ clock.abortListenerMap.delete(abort);
6138
+ clock.clearInterval(handle);
6139
+ done = true;
6140
+ for (const resolvable of nextQueue) {
6141
+ resolvable.resolve();
6142
+ }
6143
+ };
6144
+ if (options.signal) {
6145
+ if (options.signal.aborted) {
6146
+ done = true;
6147
+ } else {
6148
+ options.signal.addEventListener(
6149
+ "abort",
6150
+ abort
6151
+ );
6152
+ clock.abortListenerMap.set(
6153
+ abort,
6154
+ options.signal
6155
+ );
6156
+ }
6157
+ }
6158
+ return {
6159
+ next: async () => {
6160
+ if (options.signal?.aborted && !hasThrown) {
6161
+ hasThrown = true;
6162
+ throw options.signal.reason;
6163
+ }
6164
+ if (done) {
6165
+ return { done: true, value: void 0 };
6166
+ }
6167
+ if (nextAvailable > 0) {
6168
+ nextAvailable--;
6169
+ return { done: false, value };
6170
+ }
6171
+ const resolvable = createResolvable();
6172
+ nextQueue.push(resolvable);
6173
+ await resolvable;
6174
+ if (returnCall && nextQueue.length === 0) {
6175
+ returnCall.resolve();
6176
+ }
6177
+ if (options.signal?.aborted && !hasThrown) {
6178
+ hasThrown = true;
6179
+ throw options.signal.reason;
6180
+ }
6181
+ if (done) {
6182
+ return { done: true, value: void 0 };
6183
+ }
6184
+ return { done: false, value };
6185
+ },
6186
+ return: async () => {
6187
+ if (done) {
6188
+ return { done: true, value: void 0 };
6189
+ }
6190
+ if (nextQueue.length > 0) {
6191
+ returnCall = createResolvable();
6192
+ await returnCall;
6193
+ }
6194
+ clock.clearInterval(handle);
6195
+ done = true;
6196
+ if (options.signal) {
6197
+ options.signal.removeEventListener(
6198
+ "abort",
6199
+ abort
6200
+ );
6201
+ clock.abortListenerMap.delete(abort);
6202
+ }
6203
+ return { done: true, value: void 0 };
6204
+ }
6205
+ };
6206
+ }
6207
+ });
6208
+ }
6209
+ }
6380
6210
  }
6381
6211
  return clock;
6382
6212
  }
@@ -6394,604 +6224,33 @@ To automatically clean-up native timers, use \`shouldClearNativeTimers\`.`
6394
6224
  fakeTimersSrc.withGlobal = withGlobal;
6395
6225
  return fakeTimersSrc;
6396
6226
  }
6397
- var fakeTimersSrcExports = requireFakeTimersSrc();
6398
- var FakeTimers = class {
6399
- _global;
6400
- _clock;
6401
- _fakingTime;
6402
- _fakingDate;
6403
- _fakeTimers;
6404
- _userConfig;
6405
- _now = RealDate.now;
6406
- constructor({
6407
- global: global3,
6408
- config: config2
6409
- }) {
6410
- this._userConfig = config2;
6411
- this._fakingDate = false;
6412
- this._fakingTime = false;
6413
- this._fakeTimers = fakeTimersSrcExports.withGlobal(global3);
6414
- this._global = global3;
6415
- }
6416
- clearAllTimers() {
6417
- if (this._fakingTime) {
6418
- this._clock.reset();
6419
- }
6420
- }
6421
- dispose() {
6422
- this.useRealTimers();
6423
- }
6424
- runAllTimers() {
6425
- if (this._checkFakeTimers()) {
6426
- this._clock.runAll();
6427
- }
6428
- }
6429
- async runAllTimersAsync() {
6430
- if (this._checkFakeTimers()) {
6431
- await this._clock.runAllAsync();
6432
- }
6433
- }
6434
- runOnlyPendingTimers() {
6435
- if (this._checkFakeTimers()) {
6436
- this._clock.runToLast();
6437
- }
6438
- }
6439
- async runOnlyPendingTimersAsync() {
6440
- if (this._checkFakeTimers()) {
6441
- await this._clock.runToLastAsync();
6442
- }
6443
- }
6444
- advanceTimersToNextTimer(steps = 1) {
6445
- if (this._checkFakeTimers()) {
6446
- for (let i = steps; i > 0; i--) {
6447
- this._clock.next();
6448
- this._clock.tick(0);
6449
- if (this._clock.countTimers() === 0) {
6450
- break;
6451
- }
6452
- }
6453
- }
6454
- }
6455
- async advanceTimersToNextTimerAsync(steps = 1) {
6456
- if (this._checkFakeTimers()) {
6457
- for (let i = steps; i > 0; i--) {
6458
- await this._clock.nextAsync();
6459
- this._clock.tick(0);
6460
- if (this._clock.countTimers() === 0) {
6461
- break;
6462
- }
6463
- }
6464
- }
6465
- }
6466
- advanceTimersByTime(msToRun) {
6467
- if (this._checkFakeTimers()) {
6468
- this._clock.tick(msToRun);
6469
- }
6470
- }
6471
- async advanceTimersByTimeAsync(msToRun) {
6472
- if (this._checkFakeTimers()) {
6473
- await this._clock.tickAsync(msToRun);
6474
- }
6475
- }
6476
- advanceTimersToNextFrame() {
6477
- if (this._checkFakeTimers()) {
6478
- this._clock.runToFrame();
6479
- }
6480
- }
6481
- runAllTicks() {
6482
- if (this._checkFakeTimers()) {
6483
- this._clock.runMicrotasks();
6484
- }
6485
- }
6486
- useRealTimers() {
6487
- if (this._fakingDate) {
6488
- resetDate();
6489
- this._fakingDate = false;
6490
- }
6491
- if (this._fakingTime) {
6492
- this._clock.uninstall();
6493
- this._fakingTime = false;
6494
- }
6495
- }
6496
- useFakeTimers() {
6497
- if (this._fakingDate) {
6498
- throw new Error(
6499
- '"setSystemTime" was called already and date was mocked. Reset timers using `vi.useRealTimers()` if you want to use fake timers again.'
6500
- );
6501
- }
6502
- if (!this._fakingTime) {
6503
- const toFake = Object.keys(this._fakeTimers.timers).filter(
6504
- (timer) => timer !== "nextTick"
6505
- );
6506
- if (this._userConfig?.toFake?.includes("nextTick") && isChildProcess()) {
6507
- throw new Error(
6508
- "process.nextTick cannot be mocked inside child_process"
6509
- );
6510
- }
6511
- const existingFakedMethods = (this._userConfig?.toFake || toFake).filter(
6512
- (method) => {
6513
- switch (method) {
6514
- case "setImmediate":
6515
- case "clearImmediate":
6516
- return method in this._global && this._global[method];
6517
- default:
6518
- return true;
6519
- }
6520
- }
6521
- );
6522
- this._clock = this._fakeTimers.install({
6523
- now: Date.now(),
6524
- ...this._userConfig,
6525
- toFake: existingFakedMethods
6526
- });
6527
- this._fakingTime = true;
6528
- }
6529
- }
6530
- reset() {
6531
- if (this._checkFakeTimers()) {
6532
- const { now: now2 } = this._clock;
6533
- this._clock.reset();
6534
- this._clock.setSystemTime(now2);
6535
- }
6536
- }
6537
- setSystemTime(now2) {
6538
- if (this._fakingTime) {
6539
- this._clock.setSystemTime(now2);
6540
- } else {
6541
- mockDate(now2 ?? this.getRealSystemTime());
6542
- this._fakingDate = true;
6543
- }
6544
- }
6545
- getRealSystemTime() {
6546
- return this._now();
6547
- }
6548
- getTimerCount() {
6549
- if (this._checkFakeTimers()) {
6550
- return this._clock.countTimers();
6551
- }
6552
- return 0;
6553
- }
6554
- configure(config2) {
6555
- this._userConfig = config2;
6556
- }
6557
- isFakeTimers() {
6558
- return this._fakingTime;
6559
- }
6560
- _checkFakeTimers() {
6561
- if (!this._fakingTime) {
6562
- throw new Error(
6563
- 'Timers are not mocked. Try calling "vi.useFakeTimers()" first.'
6564
- );
6565
- }
6566
- return this._fakingTime;
6567
- }
6568
- };
6569
- function copyStackTrace2(target, source) {
6570
- if (source.stack !== void 0) {
6571
- target.stack = source.stack.replace(source.message, target.message);
6572
- }
6573
- return target;
6574
- }
6575
- function waitFor2(callback, options = {}) {
6576
- const { setTimeout: setTimeout2, setInterval: setInterval2, clearTimeout: clearTimeout2, clearInterval: clearInterval2 } = getSafeTimers();
6577
- const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
6578
- const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
6579
- return new Promise((resolve, reject) => {
6580
- let lastError;
6581
- let promiseStatus = "idle";
6582
- let timeoutId;
6583
- let intervalId;
6584
- const onResolve = (result) => {
6585
- if (timeoutId) {
6586
- clearTimeout2(timeoutId);
6587
- }
6588
- if (intervalId) {
6589
- clearInterval2(intervalId);
6590
- }
6591
- resolve(result);
6592
- };
6593
- const handleTimeout = () => {
6594
- if (intervalId) {
6595
- clearInterval2(intervalId);
6596
- }
6597
- let error = lastError;
6598
- if (!error) {
6599
- error = copyStackTrace2(
6600
- new Error("Timed out in waitFor!"),
6601
- STACK_TRACE_ERROR
6602
- );
6603
- }
6604
- reject(error);
6605
- };
6606
- const checkCallback = () => {
6607
- if (vi.isFakeTimers()) {
6608
- vi.advanceTimersByTime(interval);
6609
- }
6610
- if (promiseStatus === "pending") {
6611
- return;
6612
- }
6613
- try {
6614
- const result = callback();
6615
- if (result !== null && typeof result === "object" && typeof result.then === "function") {
6616
- const thenable = result;
6617
- promiseStatus = "pending";
6618
- thenable.then(
6619
- (resolvedValue) => {
6620
- promiseStatus = "resolved";
6621
- onResolve(resolvedValue);
6622
- },
6623
- (rejectedValue) => {
6624
- promiseStatus = "rejected";
6625
- lastError = rejectedValue;
6626
- }
6627
- );
6628
- } else {
6629
- onResolve(result);
6630
- return true;
6631
- }
6632
- } catch (error) {
6633
- lastError = error;
6634
- }
6635
- };
6636
- if (checkCallback() === true) {
6637
- return;
6638
- }
6639
- timeoutId = setTimeout2(handleTimeout, timeout);
6640
- intervalId = setInterval2(checkCallback, interval);
6641
- });
6642
- }
6643
- function waitUntil(callback, options = {}) {
6644
- const { setTimeout: setTimeout2, setInterval: setInterval2, clearTimeout: clearTimeout2, clearInterval: clearInterval2 } = getSafeTimers();
6645
- const { interval = 50, timeout = 1e3 } = typeof options === "number" ? { timeout: options } : options;
6646
- const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
6647
- return new Promise((resolve, reject) => {
6648
- let promiseStatus = "idle";
6649
- let timeoutId;
6650
- let intervalId;
6651
- const onReject = (error) => {
6652
- if (intervalId) {
6653
- clearInterval2(intervalId);
6654
- }
6655
- if (!error) {
6656
- error = copyStackTrace2(
6657
- new Error("Timed out in waitUntil!"),
6658
- STACK_TRACE_ERROR
6659
- );
6660
- }
6661
- reject(error);
6662
- };
6663
- const onResolve = (result) => {
6664
- if (!result) {
6665
- return;
6666
- }
6667
- if (timeoutId) {
6668
- clearTimeout2(timeoutId);
6669
- }
6670
- if (intervalId) {
6671
- clearInterval2(intervalId);
6672
- }
6673
- resolve(result);
6674
- return true;
6675
- };
6676
- const checkCallback = () => {
6677
- if (vi.isFakeTimers()) {
6678
- vi.advanceTimersByTime(interval);
6679
- }
6680
- if (promiseStatus === "pending") {
6681
- return;
6682
- }
6683
- try {
6684
- const result = callback();
6685
- if (result !== null && typeof result === "object" && typeof result.then === "function") {
6686
- const thenable = result;
6687
- promiseStatus = "pending";
6688
- thenable.then(
6689
- (resolvedValue) => {
6690
- promiseStatus = "resolved";
6691
- onResolve(resolvedValue);
6692
- },
6693
- (rejectedValue) => {
6694
- promiseStatus = "rejected";
6695
- onReject(rejectedValue);
6696
- }
6697
- );
6698
- } else {
6699
- return onResolve(result);
6700
- }
6701
- } catch (error) {
6702
- onReject(error);
6703
- }
6704
- };
6705
- if (checkCallback() === true) {
6706
- return;
6707
- }
6708
- timeoutId = setTimeout2(onReject, timeout);
6709
- intervalId = setInterval2(checkCallback, interval);
6710
- });
6711
- }
6712
- function createVitest() {
6713
- let _mockedDate = null;
6714
- let _config = null;
6715
- const workerState = getWorkerState();
6716
- let _timers;
6717
- const timers = () => _timers ||= new FakeTimers({
6718
- global: globalThis,
6719
- config: workerState.config.fakeTimers
6720
- });
6721
- const _stubsGlobal = /* @__PURE__ */ new Map();
6722
- const _stubsEnv = /* @__PURE__ */ new Map();
6723
- const _envBooleans = ["PROD", "DEV", "SSR"];
6724
- const utils = {
6725
- useFakeTimers(config2) {
6726
- if (isChildProcess()) {
6727
- if (config2?.toFake?.includes("nextTick") || workerState.config?.fakeTimers?.toFake?.includes("nextTick")) {
6728
- throw new Error(
6729
- 'vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.'
6730
- );
6731
- }
6732
- }
6733
- if (config2) {
6734
- timers().configure({ ...workerState.config.fakeTimers, ...config2 });
6735
- } else {
6736
- timers().configure(workerState.config.fakeTimers);
6737
- }
6738
- timers().useFakeTimers();
6739
- return utils;
6740
- },
6741
- isFakeTimers() {
6742
- return timers().isFakeTimers();
6743
- },
6744
- useRealTimers() {
6745
- timers().useRealTimers();
6746
- _mockedDate = null;
6747
- return utils;
6748
- },
6749
- runOnlyPendingTimers() {
6750
- timers().runOnlyPendingTimers();
6751
- return utils;
6752
- },
6753
- async runOnlyPendingTimersAsync() {
6754
- await timers().runOnlyPendingTimersAsync();
6755
- return utils;
6756
- },
6757
- runAllTimers() {
6758
- timers().runAllTimers();
6759
- return utils;
6760
- },
6761
- async runAllTimersAsync() {
6762
- await timers().runAllTimersAsync();
6763
- return utils;
6764
- },
6765
- runAllTicks() {
6766
- timers().runAllTicks();
6767
- return utils;
6768
- },
6769
- advanceTimersByTime(ms) {
6770
- timers().advanceTimersByTime(ms);
6771
- return utils;
6772
- },
6773
- async advanceTimersByTimeAsync(ms) {
6774
- await timers().advanceTimersByTimeAsync(ms);
6775
- return utils;
6776
- },
6777
- advanceTimersToNextTimer() {
6778
- timers().advanceTimersToNextTimer();
6779
- return utils;
6780
- },
6781
- async advanceTimersToNextTimerAsync() {
6782
- await timers().advanceTimersToNextTimerAsync();
6783
- return utils;
6784
- },
6785
- advanceTimersToNextFrame() {
6786
- timers().advanceTimersToNextFrame();
6787
- return utils;
6788
- },
6789
- getTimerCount() {
6790
- return timers().getTimerCount();
6791
- },
6792
- setSystemTime(time) {
6793
- const date = time instanceof Date ? time : new Date(time);
6794
- _mockedDate = date;
6795
- timers().setSystemTime(date);
6796
- return utils;
6797
- },
6798
- getMockedSystemTime() {
6799
- return _mockedDate;
6800
- },
6801
- getRealSystemTime() {
6802
- return timers().getRealSystemTime();
6803
- },
6804
- clearAllTimers() {
6805
- timers().clearAllTimers();
6806
- return utils;
6807
- },
6808
- // mocks
6809
- spyOn,
6810
- fn,
6811
- waitFor: waitFor2,
6812
- waitUntil,
6813
- hoisted(factory) {
6814
- assertTypes(factory, '"vi.hoisted" factory', ["function"]);
6815
- return factory();
6816
- },
6817
- mock(path, factory) {
6818
- if (typeof path !== "string") {
6819
- throw new TypeError(
6820
- `vi.mock() expects a string path, but received a ${typeof path}`
6821
- );
6822
- }
6823
- const importer = getImporter("mock");
6824
- _mocker().queueMock(
6825
- path,
6826
- importer,
6827
- typeof factory === "function" ? () => factory(
6828
- () => _mocker().importActual(
6829
- path,
6830
- importer,
6831
- _mocker().getMockContext().callstack
6832
- )
6833
- ) : factory
6834
- );
6835
- },
6836
- unmock(path) {
6837
- if (typeof path !== "string") {
6838
- throw new TypeError(
6839
- `vi.unmock() expects a string path, but received a ${typeof path}`
6840
- );
6841
- }
6842
- _mocker().queueUnmock(path, getImporter("unmock"));
6843
- },
6844
- doMock(path, factory) {
6845
- if (typeof path !== "string") {
6846
- throw new TypeError(
6847
- `vi.doMock() expects a string path, but received a ${typeof path}`
6848
- );
6849
- }
6850
- const importer = getImporter("doMock");
6851
- _mocker().queueMock(
6852
- path,
6853
- importer,
6854
- typeof factory === "function" ? () => factory(
6855
- () => _mocker().importActual(
6856
- path,
6857
- importer,
6858
- _mocker().getMockContext().callstack
6859
- )
6860
- ) : factory
6861
- );
6862
- },
6863
- doUnmock(path) {
6864
- if (typeof path !== "string") {
6865
- throw new TypeError(
6866
- `vi.doUnmock() expects a string path, but received a ${typeof path}`
6867
- );
6868
- }
6869
- _mocker().queueUnmock(path, getImporter("doUnmock"));
6870
- },
6871
- async importActual(path) {
6872
- return _mocker().importActual(
6873
- path,
6874
- getImporter("importActual"),
6875
- _mocker().getMockContext().callstack
6876
- );
6877
- },
6878
- async importMock(path) {
6879
- return _mocker().importMock(path, getImporter("importMock"));
6880
- },
6881
- // this is typed in the interface so it's not necessary to type it here
6882
- mocked(item, _options = {}) {
6883
- return item;
6884
- },
6885
- isMockFunction(fn2) {
6886
- return isMockFunction(fn2);
6887
- },
6888
- clearAllMocks() {
6889
- mocks.forEach((spy) => spy.mockClear());
6890
- return utils;
6891
- },
6892
- resetAllMocks() {
6893
- mocks.forEach((spy) => spy.mockReset());
6894
- return utils;
6895
- },
6896
- restoreAllMocks() {
6897
- mocks.forEach((spy) => spy.mockRestore());
6898
- return utils;
6899
- },
6900
- stubGlobal(name, value) {
6901
- if (!_stubsGlobal.has(name)) {
6902
- _stubsGlobal.set(
6903
- name,
6904
- Object.getOwnPropertyDescriptor(globalThis, name)
6905
- );
6906
- }
6907
- Object.defineProperty(globalThis, name, {
6908
- value,
6909
- writable: true,
6910
- configurable: true,
6911
- enumerable: true
6912
- });
6913
- return utils;
6914
- },
6915
- stubEnv(name, value) {
6916
- if (!_stubsEnv.has(name)) {
6917
- _stubsEnv.set(name, process.env[name]);
6918
- }
6919
- if (_envBooleans.includes(name)) {
6920
- process.env[name] = value ? "1" : "";
6921
- } else if (value === void 0) {
6922
- delete process.env[name];
6923
- } else {
6924
- process.env[name] = String(value);
6925
- }
6926
- return utils;
6927
- },
6928
- unstubAllGlobals() {
6929
- _stubsGlobal.forEach((original, name) => {
6930
- if (!original) {
6931
- Reflect.deleteProperty(globalThis, name);
6932
- } else {
6933
- Object.defineProperty(globalThis, name, original);
6934
- }
6935
- });
6936
- _stubsGlobal.clear();
6937
- return utils;
6938
- },
6939
- unstubAllEnvs() {
6940
- _stubsEnv.forEach((original, name) => {
6941
- if (original === void 0) {
6942
- delete process.env[name];
6943
- } else {
6944
- process.env[name] = original;
6945
- }
6946
- });
6947
- _stubsEnv.clear();
6948
- return utils;
6949
- },
6950
- resetModules() {
6951
- resetModules(workerState.moduleCache);
6952
- return utils;
6953
- },
6954
- async dynamicImportSettled() {
6955
- return waitForImportsToResolve();
6956
- },
6957
- setConfig(config2) {
6958
- if (!_config) {
6959
- _config = { ...workerState.config };
6960
- }
6961
- Object.assign(workerState.config, config2);
6962
- },
6963
- resetConfig() {
6964
- if (_config) {
6965
- Object.assign(workerState.config, _config);
6966
- }
6967
- }
6968
- };
6969
- return utils;
6970
- }
6971
- var vitest = createVitest();
6972
- var vi = vitest;
6973
- function _mocker() {
6974
- return typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : new Proxy(
6975
- {},
6976
- {
6977
- get(_, name) {
6978
- throw new Error(
6979
- `Vitest mocker was not initialized in this environment. vi.${String(name)}() is forbidden.`
6980
- );
6981
- }
6982
- }
6983
- );
6227
+ requireFakeTimersSrc();
6228
+ typeof process < "u" && process.platform === "win32";
6229
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
6230
+ var intToChar = new Uint8Array(64);
6231
+ var charToInt = new Uint8Array(128);
6232
+ for (let i = 0; i < chars.length; i++) {
6233
+ let c = chars.charCodeAt(i);
6234
+ intToChar[i] = c, charToInt[c] = i;
6984
6235
  }
6985
- function getImporter(name) {
6986
- const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
6987
- const stackArray = stackTrace.split("\n");
6988
- const importerStackIndex = stackArray.findIndex((stack2) => {
6989
- return stack2.includes(` at Object.${name}`) || stack2.includes(`${name}@`);
6990
- });
6991
- const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
6992
- return stack?.file || "";
6236
+ var customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/";
6237
+ `
6238
+
6239
+ export async function resolve(specifier, context, nextResolve) {
6240
+ if (specifier.startsWith(${JSON.stringify(customizationHookNamespace)})) {
6241
+ const data = specifier.slice(${JSON.stringify(customizationHookNamespace)}.length)
6242
+ const [parsedSpecifier, parsedImporter] = JSON.parse(data)
6243
+ specifier = parsedSpecifier
6244
+ context.parentURL = parsedImporter
6245
+ }
6246
+ return nextResolve(specifier, context)
6993
6247
  }
6994
6248
 
6249
+ `;
6250
+ new Proxy({}, { get(_, p) {
6251
+ throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
6252
+ } });
6253
+
6995
6254
  // src/test/setup.ts
6996
6255
  globalExpect.extend(matchers_exports);
6997
6256
  afterEach$1(() => {