Skip to content

Commit 434d909

Browse files
docs: describe testplane-storybook story overriding
1 parent 44f6b01 commit 434d909

File tree

2 files changed

+140
-11
lines changed

2 files changed

+140
-11
lines changed

docs/plugins/testplane-storybook.mdx

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ For example, with `autoScreenshotStorybookGlobals` set to:
151151

152152
If you have `ts-node` in your project, you can write your Testplane tests right inside of storybook story files:
153153

154-
<Admonition type="info">
155-
Storybook story files must have `.js` or `.ts` extension for this to work. Formats `jsx/tsx` are
156-
not supported yet.
157-
</Admonition>
158-
159154
```typescript title="stories/Primary.stories.ts"
160155
import type { StoryObj } from "@storybook/react";
161156
import type { WithTestplane } from "@testplane/storybook";
@@ -184,12 +179,14 @@ import type { Meta, StoryObj } from "@storybook/react";
184179
const meta: WithTestplane<Meta<typeof Button>> = {
185180
title: "Example/Button",
186181
component: Button,
187-
testplane: {
182+
testplaneConfig: {
188183
// If true, skips all Testplane tests from this story file
189184
skip: false,
190-
// Overrides default autoscreenshotSelector from plugin config
185+
// Overrides default "autoScreenshots" value from plugin config
186+
autoScreenshots: true,
187+
// Overrides default "autoscreenshotSelector" value from plugin config
191188
autoscreenshotSelector: ".my-selector",
192-
// Extends default autoScreenshotStorybookGlobals from plugin config
189+
// Extends default "autoScreenshotStorybookGlobals" value from plugin config
193190
autoScreenshotStorybookGlobals: { "dark theme": { theme: "dark" } },
194191
// Testplane browsers to run tests from this story file
195192
browserIds: ["chrome"],
@@ -203,6 +200,71 @@ const meta: WithTestplane<Meta<typeof Button>> = {
203200
export default meta;
204201
```
205202

203+
And then override these options for specific exports:
204+
205+
```typescript
206+
import type { StoryObj } from "@storybook/react";
207+
import type { WithTestplane } from "@testplane/storybook";
208+
209+
export const Primary: WithTestplane<StoryObj> = {
210+
args: {
211+
primary: true,
212+
label: "Button",
213+
},
214+
testplaneConfig: {
215+
// Overrides testplaneConfig.skip from default export
216+
skip: true,
217+
// Extends testplaneConfig.assertViewOpts from default export
218+
assertViewOpts: {
219+
// "ignoreDiffPixelCount: 5" config value will be inherited from default export
220+
ignoreElements: [".some-selector"],
221+
},
222+
// Add extra globals set
223+
autoScreenshotStorybookGlobals: { "eng locale": { locale: "en" } },
224+
},
225+
};
226+
```
227+
228+
You can also disable specific sets for the whole story-file (in default export) and for the single story (in named export) by setting null value to the set:
229+
230+
```typescript
231+
import type { WithTestplane } from "@testplane/storybook";
232+
import type { Meta, StoryObj } from "@storybook/react";
233+
234+
const meta: WithTestplane<Meta<typeof Button>> = {
235+
title: "Example/Button",
236+
component: Button,
237+
testplaneConfig: {
238+
autoScreenshotStorybookGlobals: { "dark theme": { theme: "dark" } },
239+
},
240+
};
241+
242+
export default meta;
243+
244+
export const Primary: WithTestplane<StoryObj> = {
245+
// ...other Storybook properties
246+
testplaneConfig: {
247+
// Don't test this story in dark theme
248+
autoScreenshotStorybookGlobals: { "dark theme": null },
249+
},
250+
};
251+
```
252+
253+
Besides extending and disabling, you also can overwrite "autoScreenshotStorybookGlobals", providing the value as a function:
254+
255+
```typescript
256+
import type { StoryObj } from "@storybook/react";
257+
import type { WithTestplane } from "@testplane/storybook";
258+
259+
export const Primary: WithTestplane<StoryObj> = {
260+
// ...other Storybook properties
261+
testplaneConfig: {
262+
// Replaces all global sets with this one
263+
autoScreenshotStorybookGlobals: () => ({ "eng locale": { locale: "en" } }),
264+
},
265+
};
266+
```
267+
206268
If you decide to create separate config for storybook auto-tests (which is suggested), you need to specify config path via CLI option. For example:
207269

208270
```bash

i18n/ru/docusaurus-plugin-content-docs/current/plugins/testplane-storybook.mdx

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,14 @@ import type { Meta, StoryObj } from "@storybook/react";
185185
const meta: WithTestplane<Meta<typeof Button>> = {
186186
title: "Example/Button",
187187
component: Button,
188-
testplane: {
188+
testplaneConfig: {
189189
// Если true, все testplane-тесты этого файла будут отключены
190190
skip: false,
191-
// Переопределяет autoscreenshotSelector, описанный в конфиге плагина
191+
// Переопределяет опцию "autoScreenshots", описанную в конфиге плагина
192+
autoScreenshots: true,
193+
// Переопределяет "autoscreenshotSelector", описанный в конфиге плагина
192194
autoscreenshotSelector: ".my-selector",
193-
// Расширяет autoScreenshotStorybookGlobals, описанные в конфиге плагина
195+
// Расширяет "autoScreenshotStorybookGlobals", описанные в конфиге плагина
194196
autoScreenshotStorybookGlobals: { "dark theme": { theme: "dark" } },
195197
// Список Testplane браузеров, в которых нужно запустить тест
196198
browserIds: ["chrome"],
@@ -204,6 +206,71 @@ const meta: WithTestplane<Meta<typeof Button>> = {
204206
export default meta;
205207
```
206208

209+
И затем переопределить эти опции для конкретных экспортов:
210+
211+
```typescript
212+
import type { StoryObj } from "@storybook/react";
213+
import type { WithTestplane } from "@testplane/storybook";
214+
215+
export const Primary: WithTestplane<StoryObj> = {
216+
args: {
217+
primary: true,
218+
label: "Button",
219+
},
220+
testplaneConfig: {
221+
// Переопределяет testplaneConfig.skip из экспорта по умолчанию
222+
skip: true,
223+
// Расширяет testplaneConfig.assertViewOpts из экспорта по умолчанию
224+
assertViewOpts: {
225+
// Значение "ignoreDiffPixelCount: 5" будет унаследовано из default export
226+
ignoreElements: [".some-selector"],
227+
},
228+
// Добавляет дополнительные наборы глобальных значений Storybook
229+
autoScreenshotStorybookGlobals: { "ru locale": { locale: "ru" } },
230+
},
231+
};
232+
```
233+
234+
Вы также можете отключить конкретные наборы для всего файла историй (в экспорте по умолчанию) и для отдельной истории (в именованном экспорте), установив значение null:
235+
236+
```typescript
237+
import type { WithTestplane } from "@testplane/storybook";
238+
import type { Meta, StoryObj } from "@storybook/react";
239+
240+
const meta: WithTestplane<Meta<typeof Button>> = {
241+
title: "Example/Button",
242+
component: Button,
243+
testplaneConfig: {
244+
autoScreenshotStorybookGlobals: { "dark theme": { theme: "dark" } },
245+
},
246+
};
247+
248+
export default meta;
249+
250+
export const Primary: WithTestplane<StoryObj> = {
251+
// ...другие свойства Storybook
252+
testplaneConfig: {
253+
// Не тестировать эту story в темной теме
254+
autoScreenshotStorybookGlobals: { "dark theme": null },
255+
},
256+
};
257+
```
258+
259+
Помимо расширения и отключения, Вы также можете полностью перезаписать "autoScreenshotStorybookGlobals", передав значение как функцию:
260+
261+
```typescript
262+
import type { StoryObj } from "@storybook/react";
263+
import type { WithTestplane } from "@testplane/storybook";
264+
265+
export const Primary: WithTestplane<StoryObj> = {
266+
// ...другие свойства Storybook
267+
testplaneConfig: {
268+
// Заменяет все глобальные наборы Storybook значений для этой story
269+
autoScreenshotStorybookGlobals: () => ({ "ru locale": { locale: "ru" } }),
270+
},
271+
};
272+
```
273+
207274
В Вашем проекте уже могут быть настроены другие типы тестирования, запускающиеся с помощью `testplane`. Чтобы не смешивать сущности, мы рекомендуем для storybook описать отдельный конфиг, а при запуске указывать путь к нему с помощью CLI-опции. Например:
208275

209276
```bash

0 commit comments

Comments
 (0)