storybook 9.0.0-alpha.6 → 9.0.0-alpha.8
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/cli/bin/index.cjs +1 -1
- package/dist/cli/bin/index.js +1 -1
- package/dist/common/index.cjs +96 -96
- package/dist/common/index.js +96 -96
- package/dist/core-server/index.cjs +2690 -2615
- package/dist/core-server/index.d.ts +206 -1
- package/dist/core-server/index.js +2894 -2819
- package/dist/instrumenter/index.cjs +1784 -1546
- package/dist/instrumenter/index.js +2219 -2053
- package/dist/manager/globals-module-info.cjs +11 -5
- package/dist/manager/globals-module-info.js +10 -4
- package/dist/manager/globals-runtime.js +22009 -23692
- package/dist/manager/runtime.js +2366 -2344
- package/dist/manager-api/index.cjs +1205 -1137
- package/dist/manager-api/index.d.ts +269 -7
- package/dist/manager-api/index.js +958 -890
- package/dist/preview/runtime.js +14915 -16665
- package/dist/preview-api/index.d.ts +67 -66
- package/dist/telemetry/index.cjs +1083 -2010
- package/dist/telemetry/index.d.ts +25 -4
- package/dist/telemetry/index.js +1118 -2041
- package/dist/test/index.cjs +12572 -11930
- package/dist/test/index.js +12542 -11972
- 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 +245 -1
- package/package.json +5 -5
|
@@ -4,7 +4,7 @@ export { Listener as ChannelListener } from 'storybook/internal/channels';
|
|
|
4
4
|
import { RouterData, NavigateOptions } from 'storybook/internal/router';
|
|
5
5
|
import { Addon_Types, Addon_TypesEnum, Addon_Collection, Addon_TypesMapping, Addon_BaseType, Addon_SidebarTopType, Addon_SidebarBottomType, Addon_TestProviderType, Addon_PageType, Addon_WrapperType, Addon_Config, API_ProviderData, API_StateMerger, API_Provider, StoryId, Globals, GlobalTypes, API_PanelPositions, API_Layout, API_UI, API_Notification, API_IframeRenderer, API_ComposedRef, API_SetRefData, API_ComposedRefUpdate, API_Refs, API_Settings, API_HashEntry, API_ViewMode, API_LeafEntry, API_PreparedStoryIndex, API_StoryEntry, Args, API_IndexHash, API_DocsEntry, API_FilterFunction, API_LoadedRefData, API_Version, API_Versions, API_UnknownEntries, NormalizedProjectAnnotations, ProjectAnnotations, ComposedStoryFn, API_OptionsData, Parameters, ArgTypes } from 'storybook/internal/types';
|
|
6
6
|
export { Addon_Type as Addon, API_ComponentEntry as ComponentEntry, API_ComposedRef as ComposedRef, API_DocsEntry as DocsEntry, API_GroupEntry as GroupEntry, API_HashEntry as HashEntry, API_IndexHash as IndexHash, API_LeafEntry as LeafEntry, API_Refs as Refs, API_RootEntry as RootEntry, API_IndexHash as StoriesHash, API_StoryEntry as StoryEntry } from 'storybook/internal/types';
|
|
7
|
-
import { TestProviderState, TestProviderId, TestProviders, WhatsNewData } from 'storybook/internal/core-events';
|
|
7
|
+
import { TestProviderState as TestProviderState$1, TestProviderId as TestProviderId$1, TestProviders, WhatsNewData } from 'storybook/internal/core-events';
|
|
8
8
|
import { ThemeVars } from 'storybook/theming';
|
|
9
9
|
import { toId, StoryId as StoryId$1 } from 'storybook/internal/csf';
|
|
10
10
|
|
|
@@ -178,11 +178,11 @@ interface RunOptions {
|
|
|
178
178
|
entryId?: StoryId;
|
|
179
179
|
}
|
|
180
180
|
type SubAPI$b = {
|
|
181
|
-
getTestProviderState(id: string): TestProviderState | undefined;
|
|
182
|
-
updateTestProviderState(id: TestProviderId, update: Partial<TestProviderState>): void;
|
|
183
|
-
clearTestProviderState(id: TestProviderId): void;
|
|
184
|
-
runTestProvider(id: TestProviderId, options?: RunOptions): () => void;
|
|
185
|
-
cancelTestProvider(id: TestProviderId): void;
|
|
181
|
+
getTestProviderState(id: string): TestProviderState$1 | undefined;
|
|
182
|
+
updateTestProviderState(id: TestProviderId$1, update: Partial<TestProviderState$1>): void;
|
|
183
|
+
clearTestProviderState(id: TestProviderId$1): void;
|
|
184
|
+
runTestProvider(id: TestProviderId$1, options?: RunOptions): () => void;
|
|
185
|
+
cancelTestProvider(id: TestProviderId$1): void;
|
|
186
186
|
};
|
|
187
187
|
|
|
188
188
|
interface SubState$9 {
|
|
@@ -1171,6 +1171,254 @@ type StatusStoreByTypeId = StatusStore & {
|
|
|
1171
1171
|
};
|
|
1172
1172
|
type UseStatusStore = <T = StatusesByStoryIdAndTypeId>(selector?: (statuses: StatusesByStoryIdAndTypeId) => T) => T;
|
|
1173
1173
|
|
|
1174
|
+
type TestProviderState = 'test-provider-state:pending' | 'test-provider-state:running' | 'test-provider-state:succeeded' | 'test-provider-state:crashed';
|
|
1175
|
+
type TestProviderId = string;
|
|
1176
|
+
type TestProviderStateByProviderId = Record<TestProviderId, TestProviderState>;
|
|
1177
|
+
type TestProviderStoreEventType = 'run-all' | 'clear-all' | 'settings-changed';
|
|
1178
|
+
type TestProviderStoreEvent = BaseEvent & {
|
|
1179
|
+
type: TestProviderStoreEventType;
|
|
1180
|
+
};
|
|
1181
|
+
type BaseTestProviderStore = {
|
|
1182
|
+
/**
|
|
1183
|
+
* Notifies all listeners that settings have changed for test providers. The Storybook UI will
|
|
1184
|
+
* highlight the test providers to tell the user that settings has changed.
|
|
1185
|
+
*/
|
|
1186
|
+
settingsChanged: () => void;
|
|
1187
|
+
/**
|
|
1188
|
+
* Subscribe to clicks on the "Run All" button, that is supposed to trigger all test providers to
|
|
1189
|
+
* run. Your test provider should do the "main thing" when this happens, similar to when the user
|
|
1190
|
+
* triggers your test provider specifically.
|
|
1191
|
+
*
|
|
1192
|
+
* @example
|
|
1193
|
+
*
|
|
1194
|
+
* ```typescript
|
|
1195
|
+
* // Subscribe to run-all events
|
|
1196
|
+
* const unsubscribe = myTestProviderStore.onRunAll(() => {
|
|
1197
|
+
* await runAllMyTests();
|
|
1198
|
+
* });
|
|
1199
|
+
* ```
|
|
1200
|
+
*/
|
|
1201
|
+
onRunAll: (listener: () => void) => () => void;
|
|
1202
|
+
/**
|
|
1203
|
+
* Subscribe to clicks on the "Clear All" button, that is supposed to clear all state from test
|
|
1204
|
+
* providers. Storybook already clears all statuses, but if your test provider has more
|
|
1205
|
+
* non-status-based state, you can use this to clear that here.
|
|
1206
|
+
*
|
|
1207
|
+
* @remarks
|
|
1208
|
+
* The purpose of this is _not_ to clear your test provider's settings, only the test results.
|
|
1209
|
+
* @example
|
|
1210
|
+
*
|
|
1211
|
+
* ```typescript
|
|
1212
|
+
* // Subscribe to clear-all events
|
|
1213
|
+
* const unsubscribe = myTestProviderStore.onClearAll(() => {
|
|
1214
|
+
* clearMyTestResults();
|
|
1215
|
+
* });
|
|
1216
|
+
*
|
|
1217
|
+
* // Later, when no longer needed
|
|
1218
|
+
* unsubscribe();
|
|
1219
|
+
* ```
|
|
1220
|
+
*/
|
|
1221
|
+
onClearAll: (listener: () => void) => () => void;
|
|
1222
|
+
};
|
|
1223
|
+
/**
|
|
1224
|
+
* Represents a store for a specific test provider, identified by its unique ID. This store provides
|
|
1225
|
+
* methods to manage the state of an individual test provider, including getting and setting its
|
|
1226
|
+
* state, running operations with automatic state management, and accessing its unique identifier.
|
|
1227
|
+
*
|
|
1228
|
+
* Each test provider has its own instance of this store, allowing for independent state management
|
|
1229
|
+
* across different test providers in the application.
|
|
1230
|
+
*
|
|
1231
|
+
* @example
|
|
1232
|
+
*
|
|
1233
|
+
* ```typescript
|
|
1234
|
+
* // Get a store for a specific test provider
|
|
1235
|
+
* const grammarStore = getTestProviderStoreById('addon-grammar');
|
|
1236
|
+
*
|
|
1237
|
+
* // Check the current state
|
|
1238
|
+
* if (grammarStore.getState() === 'test-provider-state:pending') {
|
|
1239
|
+
* console.log('Grammar tests are ready to run');
|
|
1240
|
+
* }
|
|
1241
|
+
*
|
|
1242
|
+
* // Run tests with automatic state management
|
|
1243
|
+
* grammarStore.runWithState(async () => {
|
|
1244
|
+
* await runGrammarTests();
|
|
1245
|
+
* });
|
|
1246
|
+
* ```
|
|
1247
|
+
*
|
|
1248
|
+
* @see {@link TestProviderState} for possible state values
|
|
1249
|
+
* @see {@link BaseTestProviderStore} for methods inherited from the base store
|
|
1250
|
+
*/
|
|
1251
|
+
type TestProviderStoreById = BaseTestProviderStore & {
|
|
1252
|
+
/**
|
|
1253
|
+
* Gets the current state of this specific test provider
|
|
1254
|
+
*
|
|
1255
|
+
* The state represents the current execution status of the test provider, which can be one of the
|
|
1256
|
+
* following:
|
|
1257
|
+
*
|
|
1258
|
+
* - 'test-provider-state:pending': Tests have not been run yet
|
|
1259
|
+
* - 'test-provider-state:running': Tests are currently running
|
|
1260
|
+
* - 'test-provider-state:succeeded': Tests completed successfully
|
|
1261
|
+
* - 'test-provider-state:crashed': Running tests failed or encountered an error
|
|
1262
|
+
*
|
|
1263
|
+
* Storybook UI will use this state to determine what to show in the UI.
|
|
1264
|
+
*
|
|
1265
|
+
* @remarks
|
|
1266
|
+
* The 'test-provider-state:crashed' is meant to signify that the test run as a whole failed to
|
|
1267
|
+
* execute for some reason. It should _not_ be set just because a number of tests failed, use
|
|
1268
|
+
* statuses and the status store for that. See {@link TestStatusStore} for managing individual test
|
|
1269
|
+
* statuses.
|
|
1270
|
+
* @example
|
|
1271
|
+
*
|
|
1272
|
+
* ```typescript
|
|
1273
|
+
* // Get the current state of a specific test provider
|
|
1274
|
+
* const state = testProviderStore.getState();
|
|
1275
|
+
*
|
|
1276
|
+
* // Conditionally render UI based on the state
|
|
1277
|
+
* const TestStatus = () => {
|
|
1278
|
+
* const state = testProviderStore.getState();
|
|
1279
|
+
*
|
|
1280
|
+
* if (state === 'test-provider-state:running') {
|
|
1281
|
+
* return <Spinner />;
|
|
1282
|
+
* } else if (state === 'test-provider-state:succeeded') {
|
|
1283
|
+
* return <SuccessIcon />;
|
|
1284
|
+
* } else if (state === 'test-provider-state:crashed') {
|
|
1285
|
+
* return <ErrorIcon />;
|
|
1286
|
+
* }
|
|
1287
|
+
*
|
|
1288
|
+
* return <PendingIcon />;
|
|
1289
|
+
* };
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
1292
|
+
getState: () => TestProviderState;
|
|
1293
|
+
/**
|
|
1294
|
+
* Sets the state of this specific test provider
|
|
1295
|
+
*
|
|
1296
|
+
* This method allows you to manually update the execution state of the test provider. It's
|
|
1297
|
+
* typically used when you need to reflect the current status of test execution in the UI or when
|
|
1298
|
+
* you want to programmatically control the test provider's state.
|
|
1299
|
+
*
|
|
1300
|
+
* Common use cases include:
|
|
1301
|
+
*
|
|
1302
|
+
* - Setting to 'running' when tests start
|
|
1303
|
+
* - Setting to 'succeeded' when tests complete successfully
|
|
1304
|
+
* - Setting to 'crashed' when tests fail or encounter errors
|
|
1305
|
+
* - Setting to 'pending' to reset the state
|
|
1306
|
+
*
|
|
1307
|
+
* The state represents the current execution status of the test provider, which can be one of the
|
|
1308
|
+
* following:
|
|
1309
|
+
*
|
|
1310
|
+
* - 'test-provider-state:pending': Tests have not been run yet
|
|
1311
|
+
* - 'test-provider-state:running': Tests are currently running
|
|
1312
|
+
* - 'test-provider-state:succeeded': Tests completed successfully
|
|
1313
|
+
* - 'test-provider-state:crashed': Running tests failed or encountered an error
|
|
1314
|
+
*
|
|
1315
|
+
* Storybook UI will use this state to determine what to show in the UI.
|
|
1316
|
+
*
|
|
1317
|
+
* @remarks
|
|
1318
|
+
* The 'test-provider-state:crashed' is meant to signify that the test run as a whole failed to
|
|
1319
|
+
* execute for some reason. It should _not_ be set just because a number of tests failed, use
|
|
1320
|
+
* statuses and the status store for that. See {@link TestStatusStore} for managing individual test
|
|
1321
|
+
* statuses.
|
|
1322
|
+
*
|
|
1323
|
+
* For most use cases, consider using {@link runWithState} instead, which provides automatic state
|
|
1324
|
+
* management and error handling during test execution.
|
|
1325
|
+
* @example
|
|
1326
|
+
*
|
|
1327
|
+
* ```typescript
|
|
1328
|
+
* // Update the state when tests start running
|
|
1329
|
+
* const startTests = async () => {
|
|
1330
|
+
* testProviderStore.setState('test-provider-state:running');
|
|
1331
|
+
* ... run tests ...
|
|
1332
|
+
* };
|
|
1333
|
+
* ```
|
|
1334
|
+
*/
|
|
1335
|
+
setState: (state: TestProviderState) => void;
|
|
1336
|
+
/**
|
|
1337
|
+
* Runs a callback and automatically updates the test provider's state with running, succeeded or
|
|
1338
|
+
* crashed, depending on the end result.
|
|
1339
|
+
*
|
|
1340
|
+
* - Immediately changes the state to 'running'
|
|
1341
|
+
* - If the callback returns/resolves, change the state to 'succeeded'.
|
|
1342
|
+
* - If the callback throws an error/rejects, change the state to 'crashed'.
|
|
1343
|
+
*
|
|
1344
|
+
* This approach helps prevent state inconsistencies that might occur if exceptions are thrown
|
|
1345
|
+
* during test execution.
|
|
1346
|
+
*
|
|
1347
|
+
* @example
|
|
1348
|
+
*
|
|
1349
|
+
* ```typescript
|
|
1350
|
+
* // Run tests with automatic state management
|
|
1351
|
+
* const runTests = () => {
|
|
1352
|
+
* testProviderStore.runWithState(async () => {
|
|
1353
|
+
* // The state is automatically set to 'running' before this callback
|
|
1354
|
+
*
|
|
1355
|
+
* // Run tests here...
|
|
1356
|
+
* const results = await executeTests();
|
|
1357
|
+
* });
|
|
1358
|
+
* };
|
|
1359
|
+
* ```
|
|
1360
|
+
*/
|
|
1361
|
+
runWithState: (callback: () => void | Promise<void>) => Promise<void>;
|
|
1362
|
+
/** The unique identifier for this test provider */
|
|
1363
|
+
testProviderId: TestProviderId;
|
|
1364
|
+
};
|
|
1365
|
+
/**
|
|
1366
|
+
* React OR preview hook for accessing the state of _all_ test providers. This hook will only
|
|
1367
|
+
* trigger a re-render when the state changes. It is recommended to pass the optional selector, to
|
|
1368
|
+
* get more fine-grained control of re-renders.
|
|
1369
|
+
*
|
|
1370
|
+
* @example
|
|
1371
|
+
*
|
|
1372
|
+
* ```typescript
|
|
1373
|
+
* const TestStatus = () => {
|
|
1374
|
+
* const state = useTestProviderStore((state) => state['my-test-provider']);
|
|
1375
|
+
* };
|
|
1376
|
+
* ```
|
|
1377
|
+
*/
|
|
1378
|
+
type UseTestProviderStore = <T = TestProviderStateByProviderId>(
|
|
1379
|
+
/**
|
|
1380
|
+
* Optional selector function to extract or transform specific parts of the state
|
|
1381
|
+
*
|
|
1382
|
+
* @example
|
|
1383
|
+
*
|
|
1384
|
+
* ```typescript
|
|
1385
|
+
* // Use the entire state
|
|
1386
|
+
* const allProviderStates = useTestProviderStore();
|
|
1387
|
+
*
|
|
1388
|
+
* // Get state for a specific provider
|
|
1389
|
+
* const myProviderState = useTestProviderStore((state) => state['my-test-provider']);
|
|
1390
|
+
*
|
|
1391
|
+
* // Get a count of providers in each state
|
|
1392
|
+
* const statusCounts = useTestProviderStore((state) => {
|
|
1393
|
+
* const counts = {
|
|
1394
|
+
* pending: 0,
|
|
1395
|
+
* running: 0,
|
|
1396
|
+
* succeeded: 0,
|
|
1397
|
+
* crashed: 0,
|
|
1398
|
+
* };
|
|
1399
|
+
*
|
|
1400
|
+
* Object.values(state).forEach((status) => {
|
|
1401
|
+
* if (status === 'test-provider-state:pending') counts.pending++;
|
|
1402
|
+
* else if (status === 'test-provider-state:running') counts.running++;
|
|
1403
|
+
* else if (status === 'test-provider-state:succeeded') counts.succeeded++;
|
|
1404
|
+
* else if (status === 'test-provider-state:crashed') counts.crashed++;
|
|
1405
|
+
* });
|
|
1406
|
+
*
|
|
1407
|
+
* return counts;
|
|
1408
|
+
* });
|
|
1409
|
+
*
|
|
1410
|
+
* // Check if all tests have completed
|
|
1411
|
+
* const allTestsCompleted = useTestProviderStore((state) => {
|
|
1412
|
+
* return Object.values(state).every(
|
|
1413
|
+
* (status) =>
|
|
1414
|
+
* status === 'test-provider-state:succeeded' ||
|
|
1415
|
+
* status === 'test-provider-state:crashed'
|
|
1416
|
+
* );
|
|
1417
|
+
* });
|
|
1418
|
+
* ```
|
|
1419
|
+
*/
|
|
1420
|
+
selector?: (state: TestProviderStateByProviderId) => T) => T;
|
|
1421
|
+
|
|
1174
1422
|
declare const fullStatusStore: StatusStore & {
|
|
1175
1423
|
selectStatuses: (statuses: Status[]) => void;
|
|
1176
1424
|
typeId: undefined;
|
|
@@ -1178,6 +1426,20 @@ declare const fullStatusStore: StatusStore & {
|
|
|
1178
1426
|
declare const getStatusStoreByTypeId: (typeId: StatusTypeId) => StatusStoreByTypeId;
|
|
1179
1427
|
declare const useStatusStore: UseStatusStore;
|
|
1180
1428
|
|
|
1429
|
+
declare const fullTestProviderStore: {
|
|
1430
|
+
settingsChanged: () => void;
|
|
1431
|
+
onRunAll: (listener: () => void) => () => void;
|
|
1432
|
+
onClearAll: (listener: () => void) => () => void;
|
|
1433
|
+
} & {
|
|
1434
|
+
getFullState: UniversalStore<TestProviderStateByProviderId, TestProviderStoreEvent>["getState"];
|
|
1435
|
+
setFullState: UniversalStore<TestProviderStateByProviderId, TestProviderStoreEvent>["setState"];
|
|
1436
|
+
onSettingsChanged: (listener: (testProviderId: TestProviderId) => void) => () => void;
|
|
1437
|
+
runAll: () => void;
|
|
1438
|
+
clearAll: () => void;
|
|
1439
|
+
};
|
|
1440
|
+
declare const getTestProviderStoreById: (testProviderId: TestProviderId) => TestProviderStoreById;
|
|
1441
|
+
declare const useTestProviderStore: UseTestProviderStore;
|
|
1442
|
+
|
|
1181
1443
|
declare const ActiveTabs: {
|
|
1182
1444
|
SIDEBAR: "sidebar";
|
|
1183
1445
|
CANVAS: "canvas";
|
|
@@ -1247,4 +1509,4 @@ declare function useArgTypes(): ArgTypes;
|
|
|
1247
1509
|
|
|
1248
1510
|
declare const typesX: typeof Addon_TypesEnum;
|
|
1249
1511
|
|
|
1250
|
-
export { type API, type API_EventMap, ActiveTabs, AddonStore, type Combo, ManagerConsumer as Consumer, type KeyboardEventLike, ManagerContext, type ManagerProviderProps, ManagerProvider as Provider, RequestResponseError, type State, type Options as StoreOptions, addons, combineParameters, controlOrMetaKey, controlOrMetaSymbol, eventMatchesShortcut, eventToShortcut, MockUniversalStore as experimental_MockUniversalStore, UniversalStore as experimental_UniversalStore, getStatusStoreByTypeId as experimental_getStatusStore, experimental_requestResponse, useStatusStore as experimental_useStatusStore, useUniversalStore as experimental_useUniversalStore, fullStatusStore as internal_fullStatusStore, isMacLike, isShortcutTaken, keyToSymbol, _default as merge, mockChannel, optionOrAltSymbol, shortcutMatchesShortcut, shortcutToHumanString, typesX as types, useAddonState, useArgTypes, useArgs, useChannel, useGlobalTypes, useGlobals, useParameter, useSharedState, useStoryPrepared, useStorybookApi, useStorybookState };
|
|
1512
|
+
export { type API, type API_EventMap, ActiveTabs, AddonStore, type Combo, ManagerConsumer as Consumer, type KeyboardEventLike, ManagerContext, type ManagerProviderProps, ManagerProvider as Provider, RequestResponseError, type State, type Options as StoreOptions, addons, combineParameters, controlOrMetaKey, controlOrMetaSymbol, eventMatchesShortcut, eventToShortcut, MockUniversalStore as experimental_MockUniversalStore, UniversalStore as experimental_UniversalStore, getStatusStoreByTypeId as experimental_getStatusStore, getTestProviderStoreById as experimental_getTestProviderStore, experimental_requestResponse, useStatusStore as experimental_useStatusStore, useTestProviderStore as experimental_useTestProviderStore, useUniversalStore as experimental_useUniversalStore, fullStatusStore as internal_fullStatusStore, fullTestProviderStore as internal_fullTestProviderStore, isMacLike, isShortcutTaken, keyToSymbol, _default as merge, mockChannel, optionOrAltSymbol, shortcutMatchesShortcut, shortcutToHumanString, typesX as types, useAddonState, useArgTypes, useArgs, useChannel, useGlobalTypes, useGlobals, useParameter, useSharedState, useStoryPrepared, useStorybookApi, useStorybookState };
|