From adfd56a340d1dd508bd433131a98ee5a72a1ac6b Mon Sep 17 00:00:00 2001 From: Nathan Brown Date: Fri, 1 Mar 2024 11:56:20 -0500 Subject: [PATCH 1/9] Update links to Storybook documentation --- src/story.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/story.ts b/src/story.ts index 5841ddb..bc46144 100644 --- a/src/story.ts +++ b/src/story.ts @@ -198,7 +198,7 @@ export type BaseAnnotations * 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>[] @@ -206,25 +206,25 @@ export type BaseAnnotations /** * 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; /** * 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; @@ -262,7 +262,7 @@ export interface ComponentAnnotations Date: Wed, 13 Nov 2024 12:37:07 +0100 Subject: [PATCH 2/9] Add ReportingAPI interface and reporting property to StoryContext --- src/story.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/story.ts b/src/story.ts index 4bcf3c7..e0a26c9 100644 --- a/src/story.ts +++ b/src/story.ts @@ -63,6 +63,18 @@ interface ControlBase { disable?: boolean; } +interface Report { + id: string; + version: number; + result: unknown; + status: 'failed' | 'passed' | 'warning'; +} + +interface ReportingAPI { + reports: Report[]; + addReport: (report: Report) => void; +} + type Control = | ControlType | false @@ -278,6 +290,7 @@ export interface StoryContext Date: Thu, 7 Nov 2024 16:55:27 +0100 Subject: [PATCH 3/9] Add the afterEach hook --- src/story.test.ts | 8 ++++++++ src/story.ts | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/story.test.ts b/src/story.test.ts index f49c18f..8948e3c 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 afterEach() { + await validateSomething(); + }, args: { x: '1' }, argTypes: { x: { type: { name: 'string' } } }, }; @@ -71,6 +76,9 @@ const strict: XMeta = { await doSomething(); return cleanup; }, + async afterEach() { + await validateSomething(); + }, argTypes: { x: { type: { name: 'string' } } }, }; diff --git a/src/story.ts b/src/story.ts index e0a26c9..4ce3585 100644 --- a/src/story.ts +++ b/src/story.ts @@ -275,6 +275,10 @@ export type BeforeEach = ( context: StoryContext ) => Awaitable; +export type AfterEach = ( + context: StoryContext +) => Awaitable; + export interface Canvas {} export interface StoryContext @@ -394,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 + */ + afterEach?: AfterEach[] | BeforeEach; + /** * Define a custom render function for the story(ies). If not passed, a default render function by the renderer will be used. */ From 7611f0c76ac05d880fe3c8954ab6bb461a669eba Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Tue, 12 Nov 2024 15:30:26 +0100 Subject: [PATCH 4/9] Fix typo --- src/story.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/story.ts b/src/story.ts index 4ce3585..047de7b 100644 --- a/src/story.ts +++ b/src/story.ts @@ -407,7 +407,7 @@ export interface BaseAnnotations[] | BeforeEach; + 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. From 0513a2b469b75825938233fdffea7ab1d08317ef Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Mon, 25 Nov 2024 14:02:10 +0100 Subject: [PATCH 5/9] Update type for reporting api --- src/story.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/story.ts b/src/story.ts index 047de7b..5894edd 100644 --- a/src/story.ts +++ b/src/story.ts @@ -65,7 +65,7 @@ interface ControlBase { interface Report { id: string; - version: number; + version?: number; result: unknown; status: 'failed' | 'passed' | 'warning'; } From 100825f894cf450265bca15653ce85f244314ee3 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Mon, 25 Nov 2024 14:16:15 +0100 Subject: [PATCH 6/9] Fix GitHub token issue --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From be293af84482a76639e2d71688ba554c090109bd Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Fri, 29 Nov 2024 08:56:44 +0100 Subject: [PATCH 7/9] Update Report interface to use 'type' instead of 'id' and rename afterEach to experimental_afterEach --- src/story.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/story.ts b/src/story.ts index 5894edd..2596758 100644 --- a/src/story.ts +++ b/src/story.ts @@ -64,7 +64,7 @@ interface ControlBase { } interface Report { - id: string; + type: string; version?: number; result: unknown; status: 'failed' | 'passed' | 'warning'; @@ -407,7 +407,7 @@ export interface BaseAnnotations[] | AfterEach; + 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. From c6e6023e1a95a3cb36cef20a42b0c2b9a2d53f4a Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Fri, 29 Nov 2024 08:58:57 +0100 Subject: [PATCH 8/9] Rename afterEach to experimental_afterEach in story test cases --- src/story.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/story.test.ts b/src/story.test.ts index 8948e3c..f7c2de4 100644 --- a/src/story.test.ts +++ b/src/story.test.ts @@ -57,7 +57,7 @@ const simple: XMeta = { await doSomething(); return cleanup; }, - async afterEach() { + async experimental_afterEach() { await validateSomething(); }, args: { x: '1' }, @@ -76,7 +76,7 @@ const strict: XMeta = { await doSomething(); return cleanup; }, - async afterEach() { + async experimental_afterEach() { await validateSomething(); }, argTypes: { x: { type: { name: 'string' } } }, From 25603420db35514bee6612caeaba57bee0d55e79 Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Fri, 29 Nov 2024 14:03:54 +0100 Subject: [PATCH 9/9] Add storybook bot as author --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ba64d01..7c29eb7 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" }