diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d803cb8..1eccc71 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/package.json b/package.json index b55955d..b6c6aab 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "type": "git", "url": "https://github.com/ComponentDriven/csf.git" }, + "author": "Storybook Bot ", "license": "MIT", "exports": { ".": { @@ -130,5 +131,6 @@ "npm", "released" ] - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/story.test.ts b/src/story.test.ts index f49c18f..f7c2de4 100644 --- a/src/story.test.ts +++ b/src/story.test.ts @@ -39,6 +39,8 @@ async function doSomething() { a = 2; } +async function validateSomething() {} + async function cleanup() { a = 1; } @@ -55,6 +57,9 @@ const simple: XMeta = { await doSomething(); return cleanup; }, + async experimental_afterEach() { + await validateSomething(); + }, args: { x: '1' }, argTypes: { x: { type: { name: 'string' } } }, }; @@ -71,6 +76,9 @@ const strict: XMeta = { await doSomething(); return cleanup; }, + async experimental_afterEach() { + await validateSomething(); + }, argTypes: { x: { type: { name: 'string' } } }, }; diff --git a/src/story.ts b/src/story.ts index f16ec5a..2596758 100644 --- a/src/story.ts +++ b/src/story.ts @@ -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 @@ -263,6 +275,10 @@ export type BeforeEach = ( context: StoryContext ) => Awaitable; +export type AfterEach = ( + context: StoryContext +) => Awaitable; + export interface Canvas {} export interface StoryContext @@ -278,6 +294,7 @@ export interface StoryContext>[] @@ -349,25 +366,25 @@ export interface BaseAnnotations; /** * 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>; /** * 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[] | LoaderFunction; @@ -381,6 +398,17 @@ export interface BaseAnnotations[] | BeforeEach; + /** + * 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[] | AfterEach; + /** * Define a custom render function for the story(ies). If not passed, a default render function by the renderer will be used. */ @@ -438,7 +466,7 @@ export interface ComponentAnnotations