Skip to content

Commit 986b2bb

Browse files
Merge pull request #31 from gemini-testing/TRIVIAL.docs.migrate
docs: migrate docs
2 parents e992ef4 + 36f1644 commit 986b2bb

File tree

1 file changed

+3
-157
lines changed

1 file changed

+3
-157
lines changed

README.md

Lines changed: 3 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -4,160 +4,6 @@ A Testplane plugin that makes it easy to write [Testplane](https://github.com/ge
44
- Adds automatic screenshot tests for storybook stories;
55
- Adds an ability to write Testplane tests for storybook stories right inside of the stories.
66

7-
## Installation
8-
9-
```bash
10-
npm install @testplane/storybook --save-dev
11-
```
12-
13-
## Usage
14-
15-
> ⚠️ Storybook 6.4+ is required to use this plugin.
16-
17-
### Storybook
18-
19-
If you use storybook@6, you will need to enable [buildStoriesJson](https://storybook.js.org/docs/6.4/configure/overview#feature-flags) feature in your `storybook` config:
20-
21-
```ts
22-
// .storybook/main.js
23-
export default {
24-
// ...
25-
features: {
26-
// ...
27-
buildStoriesJson: true
28-
}
29-
}
30-
```
31-
32-
You don't need to do this with storybook@7 or storybook@8.
33-
34-
### Testplane
35-
36-
Add `@testplane/storybook` plugin into your Testplane config:
37-
38-
```ts
39-
// .testplane.conf.ts
40-
export default {
41-
plugins: {
42-
'@testplane/storybook': {},
43-
44-
// other Testplane plugins...
45-
},
46-
47-
// other Testplane settings...
48-
}
49-
```
50-
51-
With this minimal config, you will be able to run `npx testplane --storybook` to autotest each storybook story with [Testplane assertView](https://github.com/gemini-testing/testplane#assertview) command. Testplane will open each story, wait for play function to finish (if defined), and then call `assertView` command. These tests would be generated in runtime.
52-
53-
Full plugin config:
54-
55-
| **Parameter** | **Type** | **Default value** | **Description** |
56-
| ---------------------------------- | --------------------------------------- | ---------------------- | --------------------------------------------------------------------------- |
57-
| enabled | Boolean | true | Enable / disable the plugin |
58-
| storybookConfigDir | String | ".storybook" | Path to the storybook configuration directory |
59-
| autoScreenshots | Boolean | true | Enable / disable auto-screenshot tests |
60-
| autoScreenshotStorybookGlobals | Record<string, Record<string, unknown>> | {} | Run multiple auto-screenshot tests with different [storybook globals](https://storybook.js.org/docs/7/essentials/toolbars-and-globals#globals). Only works with storybook >= 8 |
61-
| localport | Number | 6006 | Port to launch storybook dev server on |
62-
| remoteStorybookUrl | String | "" | URL of the remote Storybook. If specified, local storybook dev sever would not be launched |
63-
| browserIds | Array<String \| RegExp> | [] | Array of `browserId` to run storybook tests on. By default, all of browsers, specified in Testplane config would be used |
64-
65-
> ⚠️ *Storybook tests performance greatly depends on [Testplane testsPerSession](https://github.com/gemini-testing/testplane#testspersession) parameter, as these tests speeds up on reusing existing sessions, so setting values around 20+ is preferred*
66-
67-
> ⚠️ *These tests ignore [Testplane isolation](https://github.com/gemini-testing/testplane#isolation). It would be turned off unconditionally*
68-
69-
#### autoScreenshotStorybookGlobals
70-
71-
For example, with `autoScreenshotStorybookGlobals` set to:
72-
73-
```json
74-
{
75-
"default": {},
76-
"light theme": {
77-
"theme": "light"
78-
},
79-
"dark theme": {
80-
"theme": "dark"
81-
}
82-
}
83-
```
84-
85-
3 autoscreenshot tests will be generated for each story, each test having its corresponding storybook globals value:
86-
- `... Autoscreenshot default`
87-
- `... Autoscreenshot light theme`
88-
- `... Autoscreenshot dark theme`
89-
90-
## Advanced usage
91-
92-
If you have `ts-node` in your project, you can write your Testplane tests right inside of storybook story files:
93-
94-
```ts
95-
import type { StoryObj } from "@storybook/react";
96-
import type { WithTestplane } from "@testplane/storybook"
97-
98-
export const Primary: WithTestplane<StoryObj> = {
99-
args: {
100-
primary: true,
101-
label: "Button",
102-
},
103-
testplane: {
104-
"my test": async ({browser, expect}) => {
105-
const element = await browser.$(".storybook-button");
106-
107-
await expect(element).toHaveText("Button");
108-
}
109-
}
110-
};
111-
```
112-
113-
You can also specify extra options in story default config:
114-
115-
```ts
116-
import type { WithTestplane } from "@testplane/storybook"
117-
import type { Meta, StoryObj } from "@storybook/react";
118-
119-
const meta: WithTestplane<Meta<typeof Button>> = {
120-
title: "Example/Button",
121-
component: Button,
122-
testplane: {
123-
skip: false, // if true, skips all Testplane tests from this story file
124-
autoscreenshotSelector: ".my-selector", // Custom selector to auto-screenshot elements
125-
browserIds: ["chrome"], // Testplane browsers to run tests from this story file
126-
autoScreenshotStorybookGlobals: { // overlay plugin config's autoScreenshotStorybookGlobals options
127-
"es locale": { locale: "es" },
128-
"fr locale": { locale: "fr" }
129-
},
130-
assertViewOpts: { // override default assertView options for tests from this file
131-
ignoreDiffPixelCount: 5
132-
}
133-
}
134-
};
135-
136-
export default meta;
137-
```
138-
139-
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:
140-
141-
```bash
142-
npx testplane --storybook -c .testplane.storybook.conf.ts
143-
```
144-
145-
This allows you to store references next to your story files:
146-
147-
```ts
148-
// .testplane.conf.ts
149-
import path from "path";
150-
import { getStoryFile } from "@testplane/storybook";
151-
152-
export default {
153-
screenshotsDir: (test) => {
154-
const relativeStoryFilePath = getStoryFile(test);
155-
const relativeStoryFileDirPath = path.dirname(relativeStoryFilePath);
156-
157-
return path.join(relativeStoryFileDirPath, "screens", test.id, test.browserId);
158-
},
159-
// other Testplane settings...
160-
}
161-
```
162-
163-
In this example, screenshot references would be stored in `screens/<testId>/<browserId>` folder, next to each of your story files.
7+
See full documentation in various languages:
8+
* [English](https://testplane.io/docs/v8/plugins/testplane-storybook/)
9+
* [Русский](https://testplane.io/ru/docs/v8/plugins/testplane-storybook/)

0 commit comments

Comments
 (0)