Skip to content

Commit

Permalink
Merge pull request #114 from ComponentDriven/next
Browse files Browse the repository at this point in the history
Release 0.1.12
  • Loading branch information
kasperpeulen authored Nov 29, 2024
2 parents 4630c85 + 2560342 commit 8470970
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
yarn release
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"type": "git",
"url": "https://github.com/ComponentDriven/csf.git"
},
"author": "Storybook Bot <[email protected]>",
"license": "MIT",
"exports": {
".": {
Expand Down Expand Up @@ -130,5 +131,6 @@
"npm",
"released"
]
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
8 changes: 8 additions & 0 deletions src/story.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ async function doSomething() {
a = 2;
}

async function validateSomething() {}

async function cleanup() {
a = 1;
}
Expand All @@ -55,6 +57,9 @@ const simple: XMeta = {
await doSomething();
return cleanup;
},
async experimental_afterEach() {
await validateSomething();
},
args: { x: '1' },
argTypes: { x: { type: { name: 'string' } } },
};
Expand All @@ -71,6 +76,9 @@ const strict: XMeta<ButtonArgs> = {
await doSomething();
return cleanup;
},
async experimental_afterEach() {
await validateSomething();
},
argTypes: { x: { type: { name: 'string' } } },
};

Expand Down
46 changes: 37 additions & 9 deletions src/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ interface ControlBase {
disable?: boolean;
}

interface Report {
type: string;
version?: number;
result: unknown;
status: 'failed' | 'passed' | 'warning';
}

interface ReportingAPI {
reports: Report[];
addReport: (report: Report) => void;
}

type Control =
| ControlType
| false
Expand Down Expand Up @@ -263,6 +275,10 @@ export type BeforeEach<TRenderer extends Renderer = Renderer, TArgs = Args> = (
context: StoryContext<TRenderer, TArgs>
) => Awaitable<CleanupCallback | void>;

export type AfterEach<TRenderer extends Renderer = Renderer, TArgs = Args> = (
context: StoryContext<TRenderer, TArgs>
) => Awaitable<void>;

export interface Canvas {}

export interface StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args>
Expand All @@ -278,6 +294,7 @@ export interface StoryContext<TRenderer extends Renderer = Renderer, TArgs = Arg
context: this;
canvas: Canvas;
mount: TRenderer['mount'];
reporting: ReportingAPI;
}

/** @deprecated Use {@link StoryContext} instead. */
Expand Down Expand Up @@ -341,33 +358,33 @@ export interface BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs =
* Wrapper components or Storybook decorators that wrap a story.
*
* Decorators defined in Meta will be applied to every story variation.
* @see [Decorators](https://storybook.js.org/docs/addons/introduction/#1-decorators)
* @see [Decorators](https://storybook.js.org/docs/writing-stories/decorators)
*/
decorators?:
| DecoratorFunction<TRenderer, Simplify<TArgs>>[]
| DecoratorFunction<TRenderer, Simplify<TArgs>>;

/**
* Custom metadata for a story.
* @see [Parameters](https://storybook.js.org/docs/basics/writing-stories/#parameters)
* @see [Parameters](https://storybook.js.org/docs/writing-stories/parameters)
*/
parameters?: Parameters;

/**
* Dynamic data that are provided (and possibly updated by) Storybook and its addons.
* @see [Arg story inputs](https://storybook.js.org/docs/react/api/csf#args-story-inputs)
* @see [Args](https://storybook.js.org/docs/writing-stories/args)
*/
args?: Partial<TArgs>;

/**
* ArgTypes encode basic metadata for args, such as `name`, `description`, `defaultValue` for an arg. These get automatically filled in by Storybook Docs.
* @see [Control annotations](https://github.com/storybookjs/storybook/blob/91e9dee33faa8eff0b342a366845de7100415367/addons/controls/README.md#control-annotations)
* @see [ArgTypes](https://storybook.js.org/docs/api/arg-types)
*/
argTypes?: Partial<ArgTypes<TArgs>>;

/**
* Asynchronous functions which provide data for a story.
* @see [Loaders](https://storybook.js.org/docs/react/writing-stories/loaders)
* @see [Loaders](https://storybook.js.org/docs/writing-stories/loaders)
*/
loaders?: LoaderFunction<TRenderer, TArgs>[] | LoaderFunction<TRenderer, TArgs>;

Expand All @@ -381,6 +398,17 @@ export interface BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs =
*/
beforeEach?: BeforeEach<TRenderer, TArgs>[] | BeforeEach<TRenderer, TArgs>;

/**
* Function to be called after each play function for post-test assertions.
* Don't use this function for cleaning up state.
* You can use the return callback of `beforeEach` for that, which is run when switching stories.
* When the function is async, it will be awaited.
*
* `afterEach` can be added to preview, the default export and to a specific story.
* They are run (and awaited) reverse order: preview, default export, story
*/
experimental_afterEach?: AfterEach<TRenderer, TArgs>[] | AfterEach<TRenderer, TArgs>;

/**
* Define a custom render function for the story(ies). If not passed, a default render function by the renderer will be used.
*/
Expand Down Expand Up @@ -438,7 +466,7 @@ export interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TAr
* title: 'Design System/Atoms/Button'
* }
*
* @see [Story Hierarchy](https://storybook.js.org/docs/basics/writing-stories/#story-hierarchy)
* @see [Story Hierarchy](https://storybook.js.org/docs/writing-stories/naming-components-and-hierarchy#structure-and-hierarchy)
*/
title?: ComponentTitle;

Expand All @@ -447,7 +475,7 @@ export interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TAr
*
* By default is inferred from sanitizing the title
*
* @see [Story Hierarchy](https://storybook.js.org/docs/basics/writing-stories/#story-hierarchy)
* @see [Permalink to stories](https://storybook.js.org/docs/configure/sidebar-and-urls#permalink-to-stories)
*/
id?: ComponentId;

Expand All @@ -457,7 +485,7 @@ export interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TAr
* includeStories: ['SimpleStory', 'ComplexStory']
* includeStories: /.*Story$/
*
* @see [Non-story exports](https://storybook.js.org/docs/formats/component-story-format/#non-story-exports)
* @see [Non-story exports](https://storybook.js.org/docs/api/csf#non-story-exports)
*/
includeStories?: StoryDescriptor;

Expand All @@ -467,7 +495,7 @@ export interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TAr
* excludeStories: ['simpleData', 'complexData']
* excludeStories: /.*Data$/
*
* @see [Non-story exports](https://storybook.js.org/docs/formats/component-story-format/#non-story-exports)
* @see [Non-story exports](https://storybook.js.org/docs/api/csf#non-story-exports)
*/
excludeStories?: StoryDescriptor;

Expand Down

0 comments on commit 8470970

Please sign in to comment.