vest 5.4.4 → 5.4.5-dev-20241111-bedd

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.
@@ -489,6 +489,7 @@ const suiteResultCache = vestUtils.cache();
489
489
  const preAggCache = vestUtils.cache();
490
490
  function useCreateVestState({ suiteName, VestReconciler, }) {
491
491
  const stateRef = {
492
+ afterEachCallbacks: vestUtils.tinyState.createTinyState(() => []),
492
493
  doneCallbacks: vestUtils.tinyState.createTinyState(() => []),
493
494
  fieldCallbacks: vestUtils.tinyState.createTinyState(() => ({})),
494
495
  preAggCache,
@@ -507,6 +508,9 @@ function useDoneCallbacks() {
507
508
  function useFieldCallbacks() {
508
509
  return useX().fieldCallbacks();
509
510
  }
511
+ function useAfterEachCallbacks() {
512
+ return useX().afterEachCallbacks();
513
+ }
510
514
  function useSuiteName() {
511
515
  return useX().suiteName;
512
516
  }
@@ -532,8 +536,10 @@ function useExpireSuiteResultCache() {
532
536
  function useResetCallbacks() {
533
537
  const [, , resetDoneCallbacks] = useDoneCallbacks();
534
538
  const [, , resetFieldCallbacks] = useFieldCallbacks();
539
+ const [, , resetAfterEachCallbacks] = useAfterEachCallbacks();
535
540
  resetDoneCallbacks();
536
541
  resetFieldCallbacks();
542
+ resetAfterEachCallbacks();
537
543
  }
538
544
  function useResetSuite() {
539
545
  useResetCallbacks();
@@ -1681,6 +1687,13 @@ function useRunDoneCallbacks() {
1681
1687
  const [doneCallbacks] = useDoneCallbacks();
1682
1688
  vestUtils.callEach(doneCallbacks);
1683
1689
  }
1690
+ function useRunAfterEachCallbacks(fieldName) {
1691
+ if (SuiteWalker.useHasRemainingWithTestNameMatching(fieldName)) {
1692
+ return;
1693
+ }
1694
+ const [afterEachCallbacks] = useAfterEachCallbacks();
1695
+ vestUtils.callEach(afterEachCallbacks);
1696
+ }
1684
1697
 
1685
1698
  // eslint-disable-next-line max-statements, max-lines-per-function
1686
1699
  function useInitVestBus() {
@@ -1704,6 +1717,7 @@ function useInitVestBus() {
1704
1717
  if (!VestTest.isCanceled(isolate)) {
1705
1718
  const { fieldName } = VestTest.getData(isolate);
1706
1719
  useRunFieldCallbacks(fieldName);
1720
+ useRunAfterEachCallbacks(fieldName);
1707
1721
  }
1708
1722
  }
1709
1723
  if (!SuiteWalker.useHasPending()) {
@@ -1786,10 +1800,20 @@ function shouldSkipDoneRegistration(callback, fieldName, output) {
1786
1800
  }
1787
1801
 
1788
1802
  function useSuiteRunResult() {
1803
+ const persistedDone = vestjsRuntime.VestRuntime.persist(done);
1789
1804
  return vestUtils.freezeAssign({
1790
- done: vestjsRuntime.VestRuntime.persist(done),
1805
+ afterEach: vestjsRuntime.VestRuntime.persist(afterEach),
1806
+ done: persistedDone,
1807
+ after: persistedDone,
1791
1808
  }, useCreateSuiteResult());
1792
1809
  }
1810
+ // @vx-allow use-use
1811
+ function afterEach(callback) {
1812
+ const output = useSuiteRunResult();
1813
+ const [, setAfterEachCallbacks] = useAfterEachCallbacks();
1814
+ setAfterEachCallbacks(prev => [...prev, callback]);
1815
+ return output;
1816
+ }
1793
1817
  /**
1794
1818
  * Registers done callbacks.
1795
1819
  * @register {Object} Vest output object.