storybook 9.0.0-alpha.6 → 9.0.0-alpha.7

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.
@@ -14344,9 +14344,8 @@ function JT(e) {
14344
14344
  o(d, "mockCall");
14345
14345
  let p = t.name;
14346
14346
  t.getMockName = () => p || "vi.fn()", t.mockName = (b) => (p = b, t), t.mockClear = () => (l.reset(), n = [], a = [], i = [], t), t.mockReset =
14347
- () => (t.mockClear(), r = /* @__PURE__ */ o(() => {
14348
- }, "implementation"), u = [], t), t.mockRestore = () => (t.mockReset(), l.restore(), r = void 0, t), t.getMockImplementation = () => r, t.
14349
- mockImplementation = (b) => (r = b, l.willCall(d), t), t.mockImplementationOnce = (b) => (u.push(b), t);
14347
+ () => (t.mockClear(), r = void 0, u = [], t), t.mockRestore = () => (t.mockReset(), l.restore(), t), t.getMockImplementation = () => c ? r :
14348
+ u.at(0) || r, t.mockImplementation = (b) => (r = b, l.willCall(d), t), t.mockImplementationOnce = (b) => (u.push(b), t);
14350
14349
  function h(b, w) {
14351
14350
  let C = r;
14352
14351
  r = b, l.willCall(d), c = !0;
@@ -14430,8 +14429,8 @@ var nO = /* @__PURE__ */ o(({ parameters: e }) => {
14430
14429
  }, "traverseArgs"), oO = /* @__PURE__ */ o(({ initialArgs: e }) => {
14431
14430
  ql(e);
14432
14431
  }, "nameSpiesAndWrapActionsInSpies"), aO = /* @__PURE__ */ o(async (e) => {
14433
- globalThis.HTMLElement && e.canvasElement instanceof globalThis.HTMLElement && (e.canvas = zi(e.canvasElement)), globalThis.window && (e.userEvent =
14434
- tO({ userEvent: za.setup() }, { intercept: !0 }).userEvent);
14432
+ globalThis.HTMLElement && e.canvasElement instanceof globalThis.HTMLElement && (e.canvas = zi(e.canvasElement)), globalThis.window?.navigator?.
14433
+ clipboard && (e.userEvent = tO({ userEvent: za.setup() }, { intercept: !0 }).userEvent);
14435
14434
  }, "enhanceContext"), kF = /* @__PURE__ */ o(() => rO({
14436
14435
  loaders: [nO, oO, aO]
14437
14436
  }), "default");
package/dist/test/spy.cjs CHANGED
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
- var x = Object.defineProperty;
2
+ var v = Object.defineProperty;
3
3
  var _ = Object.getOwnPropertyDescriptor;
4
4
  var N = Object.getOwnPropertyNames;
5
5
  var K = Object.prototype.hasOwnProperty;
6
- var n = (t, e) => x(t, "name", { value: e, configurable: !0 });
6
+ var n = (t, e) => v(t, "name", { value: e, configurable: !0 });
7
7
  var U = (t, e) => {
8
8
  for (var r in e)
9
- x(t, r, { get: e[r], enumerable: !0 });
9
+ v(t, r, { get: e[r], enumerable: !0 });
10
10
  }, W = (t, e, r, l) => {
11
11
  if (e && typeof e == "object" || typeof e == "function")
12
12
  for (let o of N(e))
13
- !K.call(t, o) && o !== r && x(t, o, { get: () => e[o], enumerable: !(l = _(e, o)) || l.enumerable });
13
+ !K.call(t, o) && o !== r && v(t, o, { get: () => e[o], enumerable: !(l = _(e, o)) || l.enumerable });
14
14
  return t;
15
15
  };
16
- var Y = (t) => W(x({}, "__esModule", { value: !0 }), t);
16
+ var Y = (t) => W(v({}, "__esModule", { value: !0 }), t);
17
17
 
18
18
  // src/test/spy.ts
19
19
  var oe = {};
@@ -52,10 +52,10 @@ function M(t, e, r) {
52
52
  Object.defineProperty(t, e, { value: r });
53
53
  }
54
54
  n(M, "l");
55
- var v = Symbol.for("tinyspy:spy"), q = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ n((t) => {
55
+ var x = Symbol.for("tinyspy:spy"), q = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ n((t) => {
56
56
  t.called = !1, t.callCount = 0, t.calls = [], t.results = [], t.resolves = [], t.next = [];
57
- }, "P"), B = /* @__PURE__ */ n((t) => (w(t, v, { value: { reset: /* @__PURE__ */ n(() => z(t[v]), "reset") } }), t[v]), "K"), h = /* @__PURE__ */ n(
58
- (t) => t[v] || B(t), "T");
57
+ }, "P"), B = /* @__PURE__ */ n((t) => (w(t, x, { value: { reset: /* @__PURE__ */ n(() => z(t[x]), "reset") } }), t[x]), "K"), h = /* @__PURE__ */ n(
58
+ (t) => t[x] || B(t), "T");
59
59
  function G(t) {
60
60
  O(
61
61
  g("function", t) || g("undefined", t),
@@ -130,7 +130,7 @@ function R(t, e, r) {
130
130
  r || (r = i);
131
131
  let s = G(r);
132
132
  o === "value" && j(s, i);
133
- let u = s[v];
133
+ let u = s[x];
134
134
  return M(u, "restore", I), M(u, "getOriginal", () => m ? i() : i), M(u, "willCall", (k) => (u.impl = k, s)), f(
135
135
  m ? () => (j(s, r), s) : s
136
136
  ), q.add(s), s;
@@ -183,9 +183,8 @@ function D(t) {
183
183
  n(i, "mockCall");
184
184
  let f = e.name;
185
185
  e.getMockName = () => f || "vi.fn()", e.mockName = (s) => (f = s, e), e.mockClear = () => (c.reset(), l = [], o = [], p = [], e), e.mockReset =
186
- () => (e.mockClear(), r = /* @__PURE__ */ n(() => {
187
- }, "implementation"), a = [], e), e.mockRestore = () => (e.mockReset(), c.restore(), r = void 0, e), e.getMockImplementation = () => r, e.
188
- mockImplementation = (s) => (r = s, c.willCall(i), e), e.mockImplementationOnce = (s) => (a.push(s), e);
186
+ () => (e.mockClear(), r = void 0, a = [], e), e.mockRestore = () => (e.mockReset(), c.restore(), e), e.getMockImplementation = () => m ? r :
187
+ a.at(0) || r, e.mockImplementation = (s) => (r = s, c.willCall(i), e), e.mockImplementationOnce = (s) => (a.push(s), e);
189
188
  function I(s, u) {
190
189
  let k = r;
191
190
  r = s, c.willCall(i), m = !0;
package/dist/test/spy.js CHANGED
@@ -2,11 +2,11 @@ var F = Object.defineProperty;
2
2
  var n = (t, e) => F(t, "name", { value: e, configurable: !0 });
3
3
 
4
4
  // ../node_modules/tinyspy/dist/index.js
5
- function x(t, e) {
5
+ function v(t, e) {
6
6
  if (!t)
7
7
  throw new Error(e);
8
8
  }
9
- n(x, "d");
9
+ n(v, "d");
10
10
  function g(t, e) {
11
11
  return typeof e === t;
12
12
  }
@@ -28,7 +28,7 @@ var T = Symbol.for("tinyspy:spy"), _ = /* @__PURE__ */ new Set(), N = /* @__PURE
28
28
  }, "P"), K = /* @__PURE__ */ n((t) => (b(t, T, { value: { reset: /* @__PURE__ */ n(() => N(t[T]), "reset") } }), t[T]), "K"), h = /* @__PURE__ */ n(
29
29
  (t) => t[T] || K(t), "T");
30
30
  function U(t) {
31
- x(
31
+ v(
32
32
  g("function", t) || g("undefined", t),
33
33
  "cannot spy on a non-function value"
34
34
  );
@@ -65,10 +65,10 @@ var S = /* @__PURE__ */ n((t, e) => Object.getOwnPropertyDescriptor(t, e), "k"),
65
65
  e != null && typeof e == "function" && e.prototype != null && Object.setPrototypeOf(t.prototype, e.prototype);
66
66
  }, "O");
67
67
  function w(t, e, r) {
68
- x(
68
+ v(
69
69
  !g("undefined", t),
70
70
  "spyOn could not find an object to spy upon"
71
- ), x(
71
+ ), v(
72
72
  g("object", t) || g("function", t),
73
73
  "cannot spyOn on a primitive value"
74
74
  );
@@ -83,7 +83,7 @@ function w(t, e, r) {
83
83
  return [e.setter, "set"];
84
84
  throw new Error("specify getter or setter to spy on");
85
85
  })(), p = S(t, l), c = Object.getPrototypeOf(t), y = c && S(c, l), a = p || y;
86
- x(
86
+ v(
87
87
  a || l in t,
88
88
  `${String(l)} does not exist`
89
89
  );
@@ -109,7 +109,7 @@ function w(t, e, r) {
109
109
  n(w, "C");
110
110
 
111
111
  // ../node_modules/@vitest/spy/dist/index.js
112
- var v = /* @__PURE__ */ new Set();
112
+ var x = /* @__PURE__ */ new Set();
113
113
  function W(t) {
114
114
  return typeof t == "function" && "_isMockFunction" in t && t._isMockFunction;
115
115
  }
@@ -154,9 +154,8 @@ function E(t) {
154
154
  n(i, "mockCall");
155
155
  let f = e.name;
156
156
  e.getMockName = () => f || "vi.fn()", e.mockName = (o) => (f = o, e), e.mockClear = () => (c.reset(), l = [], s = [], p = [], e), e.mockReset =
157
- () => (e.mockClear(), r = /* @__PURE__ */ n(() => {
158
- }, "implementation"), a = [], e), e.mockRestore = () => (e.mockReset(), c.restore(), r = void 0, e), e.getMockImplementation = () => r, e.
159
- mockImplementation = (o) => (r = o, c.willCall(i), e), e.mockImplementationOnce = (o) => (a.push(o), e);
157
+ () => (e.mockClear(), r = void 0, a = [], e), e.mockRestore = () => (e.mockReset(), c.restore(), e), e.getMockImplementation = () => m ? r :
158
+ a.at(0) || r, e.mockImplementation = (o) => (r = o, c.willCall(i), e), e.mockImplementationOnce = (o) => (a.push(o), e);
160
159
  function O(o, u) {
161
160
  let k = r;
162
161
  r = o, c.willCall(i), m = !0;
@@ -172,7 +171,7 @@ function E(t) {
172
171
  e.mockRejectedValue = (o) => e.mockImplementation(() => Promise.reject(o)), e.mockRejectedValueOnce = (o) => e.mockImplementationOnce(() => Promise.
173
172
  reject(o)), Object.defineProperty(e, "mock", {
174
173
  get: /* @__PURE__ */ n(() => y, "get")
175
- }), c.willCall(i), v.add(e), e;
174
+ }), c.willCall(i), x.add(e), e;
176
175
  }
177
176
  n(E, "enhanceSpy");
178
177
  function R(t) {
@@ -212,15 +211,15 @@ function V(t) {
212
211
  }
213
212
  n(V, "listenWhenCalled");
214
213
  function X() {
215
- v.forEach((t) => t.mockClear());
214
+ x.forEach((t) => t.mockClear());
216
215
  }
217
216
  n(X, "clearAllMocks");
218
217
  function Z() {
219
- v.forEach((t) => t.mockReset());
218
+ x.forEach((t) => t.mockReset());
220
219
  }
221
220
  n(Z, "resetAllMocks");
222
221
  function ee() {
223
- v.forEach((t) => t.mockRestore());
222
+ x.forEach((t) => t.mockRestore());
224
223
  }
225
224
  n(ee, "restoreAllMocks");
226
225
  function te(t, e = {}) {
@@ -232,7 +231,7 @@ export {
232
231
  Q as fn,
233
232
  W as isMockFunction,
234
233
  te as mocked,
235
- v as mocks,
234
+ x as mocks,
236
235
  H as onMockCall,
237
236
  Z as resetAllMocks,
238
237
  ee as restoreAllMocks,
@@ -2552,4 +2552,248 @@ type StatusStoreByTypeId = StatusStore & {
2552
2552
  };
2553
2553
  type UseStatusStore = <T = StatusesByStoryIdAndTypeId>(selector?: (statuses: StatusesByStoryIdAndTypeId) => T) => T;
2554
2554
 
2555
- export { type API_ActiveTabsType, type API_BaseEntry, type API_ComponentEntry, type API_ComposedRef, type API_ComposedRefUpdate, type API_DocsEntry, type API_FilterFunction, type API_GroupEntry, type API_HashEntry, type API_IframeRenderer, type API_IndexHash, type API_Layout, type API_LeafEntry, type API_LoadedRefData, type API_MatchOptions, type API_Notification, type API_OptionsData, type API_PanelPositions, type API_PreparedIndexEntry, type API_PreparedStoryIndex, type API_Provider, type API_ProviderData, type API_RefId, type API_RefUrl, type API_Refs, type API_ReleaseNotes, type API_RenderOptions, type API_RootEntry, type API_RouteOptions, type API_SetRefData, type API_Settings, type API_SidebarOptions, type API_StateMerger, type API_StoryEntry, type API_StoryMapper, type API_UI, type API_UIOptions, type API_UnknownEntries, type API_Version, type API_Versions$1 as API_Versions, type API_ViewMode, type Addon_AddStoryArgs, type Addon_Annotations, type Addon_ArgType, type Addon_ArgsStoryFn, type Addon_BaseAnnotations, type Addon_BaseDecorators, type Addon_BaseMeta, type Addon_BaseStoryFn, type Addon_BaseStoryObject, type Addon_BaseType, type Addon_ClientApiAddon, type Addon_ClientApiAddons, type Addon_ClientApiReturnFn, type Addon_ClientStoryApi, type Addon_Collection, type Addon_Comparator, type Addon_Config, type Addon_DecoratorFunction, type Addon_Elements, type Addon_LegacyStoryFn, type Addon_LoadFn, type Addon_Loadable, type Addon_Loader, type Addon_LoaderFunction, type Addon_Loaders, type Addon_MakeDecoratorResult, type Addon_OptionsParameter, type Addon_OptionsParameterV7, type Addon_PageType, type Addon_PartialStoryFn, type Addon_RenderOptions, type Addon_RequireContext, type Addon_SidebarBottomType, type Addon_SidebarTopType, type Addon_StoryApi, type Addon_StoryContext, type Addon_StoryContextUpdate, type Addon_StoryFn, type Addon_StorySortComparator, type Addon_StorySortComparatorV7, type Addon_StorySortMethod, type Addon_StorySortObjectParameter, type Addon_StorySortParameter, type Addon_StorySortParameterV7, type Addon_StoryWrapper, type Addon_TestProviderState, type Addon_TestProviderType, type Addon_ToolbarConfig, type Addon_Type, type Addon_Types, Addon_TypesEnum, type Addon_TypesMapping, type Addon_WrapperSettings, type Addon_WrapperType, type Addons_ArgTypes, type BaseIndexEntry, type BaseIndexInput, type BaseStory, type BoundStory, type Builder, type BuilderName, type BuilderOptions, type BuilderResult, type BuilderStats, type Builder_EnvsRaw, type Builder_Unpromise, type Builder_WithRequiredProperty, type CLIBaseOptions, type CLIOptions, type CSFFile, type CompatibleString, type ComposeStoryFn, type ComposedStoryFn, type CoreCommon_AddonEntry, type CoreCommon_AddonInfo, type CoreCommon_OptionsEntry, type CoreCommon_ResolvedAddonPreset, type CoreCommon_ResolvedAddonVirtual, type CoreCommon_StorybookInfo, type CoreConfig, type DocsContextProps, type DocsIndexEntry, type DocsIndexInput, type DocsOptions, type DocsPreparedPayload, type DocsRenderFunction, type Entry, type GlobalsUpdatedPayload, type IndexEntry, type IndexEntryLegacy, type IndexInput, type IndexInputStats, type IndexedCSFFile, type IndexedStory, type Indexer, type IndexerOptions, type LoadOptions, type LoadedPreset, type Middleware, type ModuleExport, type ModuleExports, type ModuleImportFn, type NamedOrDefaultProjectAnnotations, type NormalizedComponentAnnotations, type NormalizedProjectAnnotations, type NormalizedStoriesSpecifier, type NormalizedStoryAnnotations, type Options, type PackageJson, type PartialArgsStoryFn, type Path, type PreparedMeta, type PreparedStory, type Preset, type PresetConfig, type PresetProperty, type PresetPropertyFn, type PresetValue, type Presets, type PreviewAnnotation, type ProjectAnnotations, type Ref, type RenderContext, type RenderContextCallbacks, type RenderToCanvas, type Renderer, type RendererName, type ResolvedModuleExport, type ResolvedModuleExportFromType, type ResolvedModuleExportType, type SetGlobalsPayload, type SetStoriesPayload, type SetStoriesStory, type SetStoriesStoryData, type Stats, type Status, type StatusByTypeId, type StatusStore, type StatusStoreByTypeId, type StatusTypeId, type StatusValue, type StatusesByStoryIdAndTypeId, type Store_CSFExports, type StoriesEntry, type StoriesSpecifier, type StoriesWithPartialProps, type StoryIndex, type StoryIndexEntry, type StoryIndexInput, type StoryIndexV2, type StoryIndexV3, type StoryPreparedPayload, type StoryRenderOptions, type StorybookConfig, type StorybookConfigOptions, type StorybookConfigRaw, type StorybookInternalParameters, type StorybookParameters, type SupportedFrameworks, type SupportedRenderers, type TagOptions, type TagsOptions, type TeardownRenderToCanvas, type TestBuildConfig, type TestBuildFlags, type TypescriptOptions, type UseStatusStore, type V3CompatIndexEntry, type VersionCheck, type ViewMode, type WebRenderer };
2555
+ type TestProviderState = 'test-provider-state:pending' | 'test-provider-state:running' | 'test-provider-state:succeeded' | 'test-provider-state:crashed';
2556
+ type TestProviderId = string;
2557
+ type TestProviderStateByProviderId = Record<TestProviderId, TestProviderState>;
2558
+ type BaseTestProviderStore = {
2559
+ /**
2560
+ * Notifies all listeners that settings have changed for test providers. The Storybook UI will
2561
+ * highlight the test providers to tell the user that settings has changed.
2562
+ */
2563
+ settingsChanged: () => void;
2564
+ /**
2565
+ * Subscribe to clicks on the "Run All" button, that is supposed to trigger all test providers to
2566
+ * run. Your test provider should do the "main thing" when this happens, similar to when the user
2567
+ * triggers your test provider specifically.
2568
+ *
2569
+ * @example
2570
+ *
2571
+ * ```typescript
2572
+ * // Subscribe to run-all events
2573
+ * const unsubscribe = myTestProviderStore.onRunAll(() => {
2574
+ * await runAllMyTests();
2575
+ * });
2576
+ * ```
2577
+ */
2578
+ onRunAll: (listener: () => void) => () => void;
2579
+ /**
2580
+ * Subscribe to clicks on the "Clear All" button, that is supposed to clear all state from test
2581
+ * providers. Storybook already clears all statuses, but if your test provider has more
2582
+ * non-status-based state, you can use this to clear that here.
2583
+ *
2584
+ * @remarks
2585
+ * The purpose of this is _not_ to clear your test provider's settings, only the test results.
2586
+ * @example
2587
+ *
2588
+ * ```typescript
2589
+ * // Subscribe to clear-all events
2590
+ * const unsubscribe = myTestProviderStore.onClearAll(() => {
2591
+ * clearMyTestResults();
2592
+ * });
2593
+ *
2594
+ * // Later, when no longer needed
2595
+ * unsubscribe();
2596
+ * ```
2597
+ */
2598
+ onClearAll: (listener: () => void) => () => void;
2599
+ };
2600
+ /**
2601
+ * Represents a store for a specific test provider, identified by its unique ID. This store provides
2602
+ * methods to manage the state of an individual test provider, including getting and setting its
2603
+ * state, running operations with automatic state management, and accessing its unique identifier.
2604
+ *
2605
+ * Each test provider has its own instance of this store, allowing for independent state management
2606
+ * across different test providers in the application.
2607
+ *
2608
+ * @example
2609
+ *
2610
+ * ```typescript
2611
+ * // Get a store for a specific test provider
2612
+ * const grammarStore = getTestProviderStoreById('addon-grammar');
2613
+ *
2614
+ * // Check the current state
2615
+ * if (grammarStore.getState() === 'test-provider-state:pending') {
2616
+ * console.log('Grammar tests are ready to run');
2617
+ * }
2618
+ *
2619
+ * // Run tests with automatic state management
2620
+ * grammarStore.runWithState(async () => {
2621
+ * await runGrammarTests();
2622
+ * });
2623
+ * ```
2624
+ *
2625
+ * @see {@link TestProviderState} for possible state values
2626
+ * @see {@link BaseTestProviderStore} for methods inherited from the base store
2627
+ */
2628
+ type TestProviderStoreById = BaseTestProviderStore & {
2629
+ /**
2630
+ * Gets the current state of this specific test provider
2631
+ *
2632
+ * The state represents the current execution status of the test provider, which can be one of the
2633
+ * following:
2634
+ *
2635
+ * - 'test-provider-state:pending': Tests have not been run yet
2636
+ * - 'test-provider-state:running': Tests are currently running
2637
+ * - 'test-provider-state:succeeded': Tests completed successfully
2638
+ * - 'test-provider-state:crashed': Running tests failed or encountered an error
2639
+ *
2640
+ * Storybook UI will use this state to determine what to show in the UI.
2641
+ *
2642
+ * @remarks
2643
+ * The 'test-provider-state:crashed' is meant to signify that the test run as a whole failed to
2644
+ * execute for some reason. It should _not_ be set just because a number of tests failed, use
2645
+ * statuses and the status store for that. See {@link TestStatusStore} for managing individual test
2646
+ * statuses.
2647
+ * @example
2648
+ *
2649
+ * ```typescript
2650
+ * // Get the current state of a specific test provider
2651
+ * const state = testProviderStore.getState();
2652
+ *
2653
+ * // Conditionally render UI based on the state
2654
+ * const TestStatus = () => {
2655
+ * const state = testProviderStore.getState();
2656
+ *
2657
+ * if (state === 'test-provider-state:running') {
2658
+ * return <Spinner />;
2659
+ * } else if (state === 'test-provider-state:succeeded') {
2660
+ * return <SuccessIcon />;
2661
+ * } else if (state === 'test-provider-state:crashed') {
2662
+ * return <ErrorIcon />;
2663
+ * }
2664
+ *
2665
+ * return <PendingIcon />;
2666
+ * };
2667
+ * ```
2668
+ */
2669
+ getState: () => TestProviderState;
2670
+ /**
2671
+ * Sets the state of this specific test provider
2672
+ *
2673
+ * This method allows you to manually update the execution state of the test provider. It's
2674
+ * typically used when you need to reflect the current status of test execution in the UI or when
2675
+ * you want to programmatically control the test provider's state.
2676
+ *
2677
+ * Common use cases include:
2678
+ *
2679
+ * - Setting to 'running' when tests start
2680
+ * - Setting to 'succeeded' when tests complete successfully
2681
+ * - Setting to 'crashed' when tests fail or encounter errors
2682
+ * - Setting to 'pending' to reset the state
2683
+ *
2684
+ * The state represents the current execution status of the test provider, which can be one of the
2685
+ * following:
2686
+ *
2687
+ * - 'test-provider-state:pending': Tests have not been run yet
2688
+ * - 'test-provider-state:running': Tests are currently running
2689
+ * - 'test-provider-state:succeeded': Tests completed successfully
2690
+ * - 'test-provider-state:crashed': Running tests failed or encountered an error
2691
+ *
2692
+ * Storybook UI will use this state to determine what to show in the UI.
2693
+ *
2694
+ * @remarks
2695
+ * The 'test-provider-state:crashed' is meant to signify that the test run as a whole failed to
2696
+ * execute for some reason. It should _not_ be set just because a number of tests failed, use
2697
+ * statuses and the status store for that. See {@link TestStatusStore} for managing individual test
2698
+ * statuses.
2699
+ *
2700
+ * For most use cases, consider using {@link runWithState} instead, which provides automatic state
2701
+ * management and error handling during test execution.
2702
+ * @example
2703
+ *
2704
+ * ```typescript
2705
+ * // Update the state when tests start running
2706
+ * const startTests = async () => {
2707
+ * testProviderStore.setState('test-provider-state:running');
2708
+ * ... run tests ...
2709
+ * };
2710
+ * ```
2711
+ */
2712
+ setState: (state: TestProviderState) => void;
2713
+ /**
2714
+ * Runs a callback and automatically updates the test provider's state with running, succeeded or
2715
+ * crashed, depending on the end result.
2716
+ *
2717
+ * - Immediately changes the state to 'running'
2718
+ * - If the callback returns/resolves, change the state to 'succeeded'.
2719
+ * - If the callback throws an error/rejects, change the state to 'crashed'.
2720
+ *
2721
+ * This approach helps prevent state inconsistencies that might occur if exceptions are thrown
2722
+ * during test execution.
2723
+ *
2724
+ * @example
2725
+ *
2726
+ * ```typescript
2727
+ * // Run tests with automatic state management
2728
+ * const runTests = () => {
2729
+ * testProviderStore.runWithState(async () => {
2730
+ * // The state is automatically set to 'running' before this callback
2731
+ *
2732
+ * // Run tests here...
2733
+ * const results = await executeTests();
2734
+ * });
2735
+ * };
2736
+ * ```
2737
+ */
2738
+ runWithState: (callback: () => void | Promise<void>) => Promise<void>;
2739
+ /** The unique identifier for this test provider */
2740
+ testProviderId: TestProviderId;
2741
+ };
2742
+ /**
2743
+ * React OR preview hook for accessing the state of _all_ test providers. This hook will only
2744
+ * trigger a re-render when the state changes. It is recommended to pass the optional selector, to
2745
+ * get more fine-grained control of re-renders.
2746
+ *
2747
+ * @example
2748
+ *
2749
+ * ```typescript
2750
+ * const TestStatus = () => {
2751
+ * const state = useTestProviderStore((state) => state['my-test-provider']);
2752
+ * };
2753
+ * ```
2754
+ */
2755
+ type UseTestProviderStore = <T = TestProviderStateByProviderId>(
2756
+ /**
2757
+ * Optional selector function to extract or transform specific parts of the state
2758
+ *
2759
+ * @example
2760
+ *
2761
+ * ```typescript
2762
+ * // Use the entire state
2763
+ * const allProviderStates = useTestProviderStore();
2764
+ *
2765
+ * // Get state for a specific provider
2766
+ * const myProviderState = useTestProviderStore((state) => state['my-test-provider']);
2767
+ *
2768
+ * // Get a count of providers in each state
2769
+ * const statusCounts = useTestProviderStore((state) => {
2770
+ * const counts = {
2771
+ * pending: 0,
2772
+ * running: 0,
2773
+ * succeeded: 0,
2774
+ * crashed: 0,
2775
+ * };
2776
+ *
2777
+ * Object.values(state).forEach((status) => {
2778
+ * if (status === 'test-provider-state:pending') counts.pending++;
2779
+ * else if (status === 'test-provider-state:running') counts.running++;
2780
+ * else if (status === 'test-provider-state:succeeded') counts.succeeded++;
2781
+ * else if (status === 'test-provider-state:crashed') counts.crashed++;
2782
+ * });
2783
+ *
2784
+ * return counts;
2785
+ * });
2786
+ *
2787
+ * // Check if all tests have completed
2788
+ * const allTestsCompleted = useTestProviderStore((state) => {
2789
+ * return Object.values(state).every(
2790
+ * (status) =>
2791
+ * status === 'test-provider-state:succeeded' ||
2792
+ * status === 'test-provider-state:crashed'
2793
+ * );
2794
+ * });
2795
+ * ```
2796
+ */
2797
+ selector?: (state: TestProviderStateByProviderId) => T) => T;
2798
+
2799
+ export { type API_ActiveTabsType, type API_BaseEntry, type API_ComponentEntry, type API_ComposedRef, type API_ComposedRefUpdate, type API_DocsEntry, type API_FilterFunction, type API_GroupEntry, type API_HashEntry, type API_IframeRenderer, type API_IndexHash, type API_Layout, type API_LeafEntry, type API_LoadedRefData, type API_MatchOptions, type API_Notification, type API_OptionsData, type API_PanelPositions, type API_PreparedIndexEntry, type API_PreparedStoryIndex, type API_Provider, type API_ProviderData, type API_RefId, type API_RefUrl, type API_Refs, type API_ReleaseNotes, type API_RenderOptions, type API_RootEntry, type API_RouteOptions, type API_SetRefData, type API_Settings, type API_SidebarOptions, type API_StateMerger, type API_StoryEntry, type API_StoryMapper, type API_UI, type API_UIOptions, type API_UnknownEntries, type API_Version, type API_Versions$1 as API_Versions, type API_ViewMode, type Addon_AddStoryArgs, type Addon_Annotations, type Addon_ArgType, type Addon_ArgsStoryFn, type Addon_BaseAnnotations, type Addon_BaseDecorators, type Addon_BaseMeta, type Addon_BaseStoryFn, type Addon_BaseStoryObject, type Addon_BaseType, type Addon_ClientApiAddon, type Addon_ClientApiAddons, type Addon_ClientApiReturnFn, type Addon_ClientStoryApi, type Addon_Collection, type Addon_Comparator, type Addon_Config, type Addon_DecoratorFunction, type Addon_Elements, type Addon_LegacyStoryFn, type Addon_LoadFn, type Addon_Loadable, type Addon_Loader, type Addon_LoaderFunction, type Addon_Loaders, type Addon_MakeDecoratorResult, type Addon_OptionsParameter, type Addon_OptionsParameterV7, type Addon_PageType, type Addon_PartialStoryFn, type Addon_RenderOptions, type Addon_RequireContext, type Addon_SidebarBottomType, type Addon_SidebarTopType, type Addon_StoryApi, type Addon_StoryContext, type Addon_StoryContextUpdate, type Addon_StoryFn, type Addon_StorySortComparator, type Addon_StorySortComparatorV7, type Addon_StorySortMethod, type Addon_StorySortObjectParameter, type Addon_StorySortParameter, type Addon_StorySortParameterV7, type Addon_StoryWrapper, type Addon_TestProviderState, type Addon_TestProviderType, type Addon_ToolbarConfig, type Addon_Type, type Addon_Types, Addon_TypesEnum, type Addon_TypesMapping, type Addon_WrapperSettings, type Addon_WrapperType, type Addons_ArgTypes, type BaseIndexEntry, type BaseIndexInput, type BaseStory, type BoundStory, type Builder, type BuilderName, type BuilderOptions, type BuilderResult, type BuilderStats, type Builder_EnvsRaw, type Builder_Unpromise, type Builder_WithRequiredProperty, type CLIBaseOptions, type CLIOptions, type CSFFile, type CompatibleString, type ComposeStoryFn, type ComposedStoryFn, type CoreCommon_AddonEntry, type CoreCommon_AddonInfo, type CoreCommon_OptionsEntry, type CoreCommon_ResolvedAddonPreset, type CoreCommon_ResolvedAddonVirtual, type CoreCommon_StorybookInfo, type CoreConfig, type DocsContextProps, type DocsIndexEntry, type DocsIndexInput, type DocsOptions, type DocsPreparedPayload, type DocsRenderFunction, type Entry, type GlobalsUpdatedPayload, type IndexEntry, type IndexEntryLegacy, type IndexInput, type IndexInputStats, type IndexedCSFFile, type IndexedStory, type Indexer, type IndexerOptions, type LoadOptions, type LoadedPreset, type Middleware, type ModuleExport, type ModuleExports, type ModuleImportFn, type NamedOrDefaultProjectAnnotations, type NormalizedComponentAnnotations, type NormalizedProjectAnnotations, type NormalizedStoriesSpecifier, type NormalizedStoryAnnotations, type Options, type PackageJson, type PartialArgsStoryFn, type Path, type PreparedMeta, type PreparedStory, type Preset, type PresetConfig, type PresetProperty, type PresetPropertyFn, type PresetValue, type Presets, type PreviewAnnotation, type ProjectAnnotations, type Ref, type RenderContext, type RenderContextCallbacks, type RenderToCanvas, type Renderer, type RendererName, type ResolvedModuleExport, type ResolvedModuleExportFromType, type ResolvedModuleExportType, type SetGlobalsPayload, type SetStoriesPayload, type SetStoriesStory, type SetStoriesStoryData, type Stats, type Status, type StatusByTypeId, type StatusStore, type StatusStoreByTypeId, type StatusTypeId, type StatusValue, type StatusesByStoryIdAndTypeId, type Store_CSFExports, type StoriesEntry, type StoriesSpecifier, type StoriesWithPartialProps, type StoryIndex, type StoryIndexEntry, type StoryIndexInput, type StoryIndexV2, type StoryIndexV3, type StoryPreparedPayload, type StoryRenderOptions, type StorybookConfig, type StorybookConfigOptions, type StorybookConfigRaw, type StorybookInternalParameters, type StorybookParameters, type SupportedFrameworks, type SupportedRenderers, type TagOptions, type TagsOptions, type TeardownRenderToCanvas, type TestBuildConfig, type TestBuildFlags, type TestProviderId, type TestProviderState, type TestProviderStoreById, type TypescriptOptions, type UseStatusStore, type UseTestProviderStore, type V3CompatIndexEntry, type VersionCheck, type ViewMode, type WebRenderer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook",
3
- "version": "9.0.0-alpha.6",
3
+ "version": "9.0.0-alpha.7",
4
4
  "description": "Storybook framework-agnostic API",
5
5
  "keywords": [
6
6
  "storybook"
@@ -445,8 +445,8 @@
445
445
  "@testing-library/jest-dom": "^6.6.3",
446
446
  "@testing-library/user-event": "^14.6.1",
447
447
  "@types/uuid": "^9.0.1",
448
- "@vitest/expect": "2.0.5",
449
- "@vitest/spy": "2.0.5",
448
+ "@vitest/expect": "3.0.9",
449
+ "@vitest/spy": "3.0.9",
450
450
  "better-opn": "^3.0.2",
451
451
  "esbuild": "^0.18.0 || ^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0 || ^0.25.0",
452
452
  "esbuild-register": "^3.5.0",
@@ -499,7 +499,7 @@
499
499
  "@types/react-transition-group": "^4",
500
500
  "@types/semver": "^7.5.8",
501
501
  "@types/ws": "^8",
502
- "@vitest/utils": "^2.1.1",
502
+ "@vitest/utils": "^3.0.9",
503
503
  "@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.10",
504
504
  "@yarnpkg/fslib": "2.10.3",
505
505
  "@yarnpkg/libzip": "2.3.0",