Skip to content

Commit

Permalink
Add beforeAll hook to CSF types
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jun 21, 2024
1 parent fa77c25 commit 46e1c3c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ export type LoaderFunction<TRenderer extends Renderer = Renderer, TArgs = Args>
type Awaitable<T> = T | PromiseLike<T>;
export type CleanupCallback = () => Awaitable<unknown>;

export type BeforeAll = () => Awaitable<CleanupCallback | void>;

export type BeforeEach<TRenderer extends Renderer = Renderer, TArgs = Args> = (
context: StoryContext<TRenderer, TArgs>
) => Awaitable<CleanupCallback | void>;
Expand Down Expand Up @@ -390,6 +392,13 @@ export type ProjectAnnotations<
> = BaseAnnotations<TRenderer, TArgs> & {
argsEnhancers?: ArgsEnhancer<TRenderer, Args>[];
argTypesEnhancers?: ArgTypesEnhancer<TRenderer, Args>[];

/**
* Function to be called once, before rendering any story. When the function is async, it will be awaited.
* A cleanup function may be returned. This function may only be defined globally.
*/
beforeAll?: BeforeAll;

/**
* @deprecated Project `globals` renamed to `initiaGlobals`
*/
Expand Down

0 comments on commit 46e1c3c

Please sign in to comment.