storybook 9.0.0-alpha.5 → 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.
- package/dist/bin/index.cjs +63 -63
- package/dist/bin/index.js +63 -63
- package/dist/builder-manager/index.cjs +253 -280
- package/dist/builder-manager/index.js +305 -332
- package/dist/cli/bin/index.cjs +1 -1
- package/dist/cli/bin/index.js +1 -1
- package/dist/common/index.cjs +63 -63
- package/dist/common/index.js +63 -63
- package/dist/components/index.cjs +2102 -2069
- package/dist/components/index.js +2311 -2278
- package/dist/core-server/index.cjs +10816 -10501
- package/dist/core-server/index.d.ts +260 -2
- package/dist/core-server/index.js +10920 -10611
- package/dist/core-server/presets/common-preset.cjs +59 -59
- package/dist/core-server/presets/common-preset.js +57 -57
- package/dist/csf/index.d.ts +1 -1
- package/dist/instrumenter/index.cjs +1784 -1546
- package/dist/instrumenter/index.js +2220 -2054
- package/dist/manager/globals-module-info.cjs +22 -8
- package/dist/manager/globals-module-info.js +20 -6
- package/dist/manager/globals-runtime.js +22673 -23887
- package/dist/manager/runtime.js +3286 -3200
- package/dist/manager-api/index.cjs +3506 -3179
- package/dist/manager-api/index.d.ts +325 -24
- package/dist/manager-api/index.js +3245 -2957
- package/dist/manager-errors.d.ts +25 -1
- package/dist/manager-errors.js +42 -26
- package/dist/preview/runtime.js +15216 -16734
- package/dist/preview-api/index.cjs +1234 -1683
- package/dist/preview-api/index.d.ts +3 -309
- package/dist/preview-api/index.js +1360 -1785
- package/dist/preview-errors.cjs +98 -81
- package/dist/preview-errors.d.ts +25 -1
- package/dist/preview-errors.js +109 -93
- package/dist/server-errors.cjs +92 -75
- package/dist/server-errors.d.ts +25 -1
- package/dist/server-errors.js +83 -66
- package/dist/test/index.cjs +12779 -11872
- package/dist/test/index.js +12417 -11582
- package/dist/test/preview.cjs +1466 -1467
- package/dist/test/preview.js +4 -5
- package/dist/test/spy.cjs +11 -12
- package/dist/test/spy.js +14 -15
- package/dist/types/index.d.ts +271 -13
- package/package.json +9 -9
package/dist/test/preview.js
CHANGED
|
@@ -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 =
|
|
14348
|
-
|
|
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
|
|
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
|
|
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) =>
|
|
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
|
-
|
|
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 &&
|
|
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(
|
|
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
|
|
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,
|
|
58
|
-
(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[
|
|
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 =
|
|
187
|
-
|
|
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
|
|
5
|
+
function v(t, e) {
|
|
6
6
|
if (!t)
|
|
7
7
|
throw new Error(e);
|
|
8
8
|
}
|
|
9
|
-
n(
|
|
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
|
-
|
|
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
|
-
|
|
68
|
+
v(
|
|
69
69
|
!g("undefined", t),
|
|
70
70
|
"spyOn could not find an object to spy upon"
|
|
71
|
-
),
|
|
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
|
-
|
|
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
|
|
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 =
|
|
158
|
-
|
|
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),
|
|
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
|
-
|
|
214
|
+
x.forEach((t) => t.mockClear());
|
|
216
215
|
}
|
|
217
216
|
n(X, "clearAllMocks");
|
|
218
217
|
function Z() {
|
|
219
|
-
|
|
218
|
+
x.forEach((t) => t.mockReset());
|
|
220
219
|
}
|
|
221
220
|
n(Z, "resetAllMocks");
|
|
222
221
|
function ee() {
|
|
223
|
-
|
|
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
|
-
|
|
234
|
+
x as mocks,
|
|
236
235
|
H as onMockCall,
|
|
237
236
|
Z as resetAllMocks,
|
|
238
237
|
ee as restoreAllMocks,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1632,19 +1632,8 @@ interface API_Versions$1 {
|
|
|
1632
1632
|
next?: API_Version;
|
|
1633
1633
|
current?: API_Version;
|
|
1634
1634
|
}
|
|
1635
|
-
type API_StatusValue = 'pending' | 'success' | 'error' | 'warn' | 'unknown';
|
|
1636
|
-
interface API_StatusObject {
|
|
1637
|
-
status: API_StatusValue;
|
|
1638
|
-
title: string;
|
|
1639
|
-
description: string;
|
|
1640
|
-
data?: any;
|
|
1641
|
-
onClick?: () => void;
|
|
1642
|
-
sidebarContextMenu?: boolean;
|
|
1643
|
-
}
|
|
1644
|
-
type API_StatusState = Record<StoryId, Record<string, API_StatusObject>>;
|
|
1645
|
-
type API_StatusUpdate = Record<StoryId, API_StatusObject | null>;
|
|
1646
1635
|
type API_FilterFunction = (item: API_PreparedIndexEntry & {
|
|
1647
|
-
|
|
1636
|
+
statuses: StatusByTypeId;
|
|
1648
1637
|
}) => boolean;
|
|
1649
1638
|
|
|
1650
1639
|
interface SetStoriesStory {
|
|
@@ -2538,4 +2527,273 @@ type SupportedFrameworks = 'angular' | 'ember' | 'experimental-nextjs-vite' | 'h
|
|
|
2538
2527
|
|
|
2539
2528
|
type SupportedRenderers = 'react' | 'react-native' | 'vue3' | 'angular' | 'ember' | 'preact' | 'svelte' | 'qwik' | 'html' | 'web-components' | 'server' | 'solid' | 'nuxt';
|
|
2540
2529
|
|
|
2541
|
-
|
|
2530
|
+
type StatusValue = 'status-value:pending' | 'status-value:success' | 'status-value:error' | 'status-value:warning' | 'status-value:unknown';
|
|
2531
|
+
type StatusTypeId = string;
|
|
2532
|
+
type StatusByTypeId = Record<StatusTypeId, Status>;
|
|
2533
|
+
type StatusesByStoryIdAndTypeId = Record<StoryId, StatusByTypeId>;
|
|
2534
|
+
interface Status {
|
|
2535
|
+
value: StatusValue;
|
|
2536
|
+
typeId: StatusTypeId;
|
|
2537
|
+
storyId: StoryId;
|
|
2538
|
+
title: string;
|
|
2539
|
+
description: string;
|
|
2540
|
+
data?: any;
|
|
2541
|
+
sidebarContextMenu?: boolean;
|
|
2542
|
+
}
|
|
2543
|
+
type StatusStore = {
|
|
2544
|
+
getAll: () => StatusesByStoryIdAndTypeId;
|
|
2545
|
+
set: (statuses: Status[]) => void;
|
|
2546
|
+
onAllStatusChange: (listener: (statuses: StatusesByStoryIdAndTypeId, previousStatuses: StatusesByStoryIdAndTypeId) => void) => () => void;
|
|
2547
|
+
onSelect: (listener: (selectedStatuses: Status[]) => void) => () => void;
|
|
2548
|
+
unset: (storyIds?: StoryId[]) => void;
|
|
2549
|
+
};
|
|
2550
|
+
type StatusStoreByTypeId = StatusStore & {
|
|
2551
|
+
typeId: StatusTypeId;
|
|
2552
|
+
};
|
|
2553
|
+
type UseStatusStore = <T = StatusesByStoryIdAndTypeId>(selector?: (statuses: StatusesByStoryIdAndTypeId) => T) => T;
|
|
2554
|
+
|
|
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.
|
|
3
|
+
"version": "9.0.0-alpha.7",
|
|
4
4
|
"description": "Storybook framework-agnostic API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"type": "module",
|
|
24
24
|
"imports": {
|
|
25
|
+
"#manager-status-store": {
|
|
26
|
+
"storybook": "./src/manager/status-store.mock.ts",
|
|
27
|
+
"default": "./src/manager/status-store.ts"
|
|
28
|
+
},
|
|
25
29
|
"#utils": {
|
|
26
30
|
"storybook": "./template/stories/utils.mock.ts",
|
|
27
31
|
"default": "./template/stories/utils.ts"
|
|
@@ -441,18 +445,15 @@
|
|
|
441
445
|
"@testing-library/jest-dom": "^6.6.3",
|
|
442
446
|
"@testing-library/user-event": "^14.6.1",
|
|
443
447
|
"@types/uuid": "^9.0.1",
|
|
444
|
-
"@vitest/expect": "
|
|
445
|
-
"@vitest/spy": "
|
|
448
|
+
"@vitest/expect": "3.0.9",
|
|
449
|
+
"@vitest/spy": "3.0.9",
|
|
446
450
|
"better-opn": "^3.0.2",
|
|
447
|
-
"browser-assert": "^1.2.1",
|
|
448
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",
|
|
449
452
|
"esbuild-register": "^3.5.0",
|
|
450
453
|
"jsdoc-type-pratt-parser": "^4.0.0",
|
|
451
454
|
"polished": "^4.2.2",
|
|
452
|
-
"process": "^0.11.10",
|
|
453
455
|
"recast": "^0.23.5",
|
|
454
456
|
"semver": "^7.6.2",
|
|
455
|
-
"util": "^0.12.5",
|
|
456
457
|
"uuid": "^9.0.0",
|
|
457
458
|
"ws": "^8.18.0"
|
|
458
459
|
},
|
|
@@ -479,7 +480,7 @@
|
|
|
479
480
|
"@radix-ui/react-scroll-area": "1.2.0-rc.7",
|
|
480
481
|
"@radix-ui/react-slot": "^1.0.2",
|
|
481
482
|
"@storybook/docs-mdx": "4.0.0-next.1",
|
|
482
|
-
"@storybook/icons": "^1.
|
|
483
|
+
"@storybook/icons": "^1.4.0",
|
|
483
484
|
"@tanstack/react-virtual": "^3.3.0",
|
|
484
485
|
"@testing-library/react": "^14.0.0",
|
|
485
486
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -498,7 +499,7 @@
|
|
|
498
499
|
"@types/react-transition-group": "^4",
|
|
499
500
|
"@types/semver": "^7.5.8",
|
|
500
501
|
"@types/ws": "^8",
|
|
501
|
-
"@vitest/utils": "^
|
|
502
|
+
"@vitest/utils": "^3.0.9",
|
|
502
503
|
"@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.10",
|
|
503
504
|
"@yarnpkg/fslib": "2.10.3",
|
|
504
505
|
"@yarnpkg/libzip": "2.3.0",
|
|
@@ -526,7 +527,6 @@
|
|
|
526
527
|
"ejs": "^3.1.10",
|
|
527
528
|
"es-toolkit": "^1.22.0",
|
|
528
529
|
"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",
|
|
529
|
-
"esbuild-plugin-alias": "^0.2.1",
|
|
530
530
|
"execa": "^8.0.1",
|
|
531
531
|
"fd-package-json": "^1.2.0",
|
|
532
532
|
"fetch-retry": "^6.0.0",
|