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/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 4bcf3c7..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[] | 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. */