creevey 0.10.0-beta.4 → 0.10.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -41
- package/dist/client/addon/components/Addon.js +17 -7
- package/dist/client/addon/components/Addon.js.map +1 -1
- package/dist/client/addon/components/Panel.js +2 -2
- package/dist/client/addon/components/Panel.js.map +1 -1
- package/dist/client/addon/components/Tools.js +17 -7
- package/dist/client/addon/components/Tools.js.map +1 -1
- package/dist/client/addon/withCreevey.d.ts +2 -1
- package/dist/client/addon/withCreevey.js +11 -1
- package/dist/client/addon/withCreevey.js.map +1 -1
- package/dist/client/shared/components/ImagesView/BlendView.d.ts +1 -1
- package/dist/client/shared/components/ImagesView/BlendView.js +17 -7
- package/dist/client/shared/components/ImagesView/BlendView.js.map +1 -1
- package/dist/client/shared/components/ImagesView/SideBySideView.d.ts +1 -1
- package/dist/client/shared/components/ImagesView/SideBySideView.js +17 -7
- package/dist/client/shared/components/ImagesView/SideBySideView.js.map +1 -1
- package/dist/client/shared/components/ImagesView/SlideView.d.ts +1 -1
- package/dist/client/shared/components/ImagesView/SlideView.js +17 -7
- package/dist/client/shared/components/ImagesView/SlideView.js.map +1 -1
- package/dist/client/shared/components/ImagesView/SwapView.d.ts +1 -1
- package/dist/client/shared/components/ImagesView/SwapView.js +29 -7
- package/dist/client/shared/components/ImagesView/SwapView.js.map +1 -1
- package/dist/client/shared/components/PageHeader/ImagePreview.d.ts +1 -1
- package/dist/client/shared/components/PageHeader/ImagePreview.js +1 -0
- package/dist/client/shared/components/PageHeader/ImagePreview.js.map +1 -1
- package/dist/client/shared/components/PageHeader/PageHeader.js +20 -8
- package/dist/client/shared/components/PageHeader/PageHeader.js.map +1 -1
- package/dist/client/shared/components/ResultsPage.d.ts +1 -1
- package/dist/client/shared/components/ResultsPage.js +43 -13
- package/dist/client/shared/components/ResultsPage.js.map +1 -1
- package/dist/client/shared/creeveyClientApi.js +8 -1
- package/dist/client/shared/creeveyClientApi.js.map +1 -1
- package/dist/client/shared/helpers.d.ts +1 -3
- package/dist/client/shared/helpers.js +4 -19
- package/dist/client/shared/helpers.js.map +1 -1
- package/dist/client/web/CreeveyApp.js +42 -14
- package/dist/client/web/CreeveyApp.js.map +1 -1
- package/dist/client/web/CreeveyContext.d.ts +5 -0
- package/dist/client/web/CreeveyContext.js +20 -7
- package/dist/client/web/CreeveyContext.js.map +1 -1
- package/dist/client/web/CreeveyLoader.js +2 -2
- package/dist/client/web/CreeveyLoader.js.map +1 -1
- package/dist/client/web/CreeveyView/SideBar/Search.js +19 -9
- package/dist/client/web/CreeveyView/SideBar/Search.js.map +1 -1
- package/dist/client/web/CreeveyView/SideBar/SideBar.js +18 -7
- package/dist/client/web/CreeveyView/SideBar/SideBar.js.map +1 -1
- package/dist/client/web/CreeveyView/SideBar/SideBarFooter.js +60 -7
- package/dist/client/web/CreeveyView/SideBar/SideBarFooter.js.map +1 -1
- package/dist/client/web/CreeveyView/SideBar/SideBarHeader.js +17 -7
- package/dist/client/web/CreeveyView/SideBar/SideBarHeader.js.map +1 -1
- package/dist/client/web/CreeveyView/SideBar/SuiteLink.d.ts +2 -2
- package/dist/client/web/CreeveyView/SideBar/SuiteLink.js +18 -10
- package/dist/client/web/CreeveyView/SideBar/SuiteLink.js.map +1 -1
- package/dist/client/web/CreeveyView/SideBar/TestLink.js +18 -10
- package/dist/client/web/CreeveyView/SideBar/TestLink.js.map +1 -1
- package/dist/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +1 -1
- package/dist/client/web/CreeveyView/SideBar/TestsStatus.d.ts +1 -1
- package/dist/client/web/KeyboardEventsContext.d.ts +1 -8
- package/dist/client/web/KeyboardEventsContext.js +79 -64
- package/dist/client/web/KeyboardEventsContext.js.map +1 -1
- package/dist/client/web/assets/index-C47njyZV.js +802 -0
- package/dist/client/web/index.html +1 -1
- package/dist/client/web/index.js +17 -7
- package/dist/client/web/index.js.map +1 -1
- package/dist/client/web/themes.d.ts +2 -0
- package/dist/client/web/themes.js +22 -0
- package/dist/client/web/themes.js.map +1 -0
- package/dist/creevey.js +16 -9
- package/dist/creevey.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/server/config.d.ts +1 -1
- package/dist/server/config.js +30 -7
- package/dist/server/config.js.map +1 -1
- package/dist/server/connection.d.ts +3 -0
- package/dist/server/connection.js +28 -0
- package/dist/server/connection.js.map +1 -0
- package/dist/server/docker.d.ts +1 -1
- package/dist/server/docker.js +56 -32
- package/dist/server/docker.js.map +1 -1
- package/dist/server/index.js +64 -11
- package/dist/server/index.js.map +1 -1
- package/dist/server/logger.d.ts +2 -1
- package/dist/server/logger.js +7 -3
- package/dist/server/logger.js.map +1 -1
- package/dist/server/master/api.js +1 -1
- package/dist/server/master/api.js.map +1 -1
- package/dist/server/master/pool.d.ts +4 -3
- package/dist/server/master/pool.js +13 -66
- package/dist/server/master/pool.js.map +1 -1
- package/dist/server/master/queue.d.ts +13 -0
- package/dist/server/master/queue.js +71 -0
- package/dist/server/master/queue.js.map +1 -0
- package/dist/server/master/runner.d.ts +3 -0
- package/dist/server/master/runner.js +78 -10
- package/dist/server/master/runner.js.map +1 -1
- package/dist/server/master/server.js +1 -1
- package/dist/server/master/server.js.map +1 -1
- package/dist/server/master/start.js +13 -11
- package/dist/server/master/start.js.map +1 -1
- package/dist/server/playwright/docker-file.d.ts +1 -1
- package/dist/server/playwright/docker-file.js +15 -6
- package/dist/server/playwright/docker-file.js.map +1 -1
- package/dist/server/playwright/docker.d.ts +2 -1
- package/dist/server/playwright/docker.js +10 -2
- package/dist/server/playwright/docker.js.map +1 -1
- package/dist/server/playwright/index-source.mjs +16 -0
- package/dist/server/playwright/internal.d.ts +6 -6
- package/dist/server/playwright/internal.js +143 -91
- package/dist/server/playwright/internal.js.map +1 -1
- package/dist/server/playwright/webdriver.d.ts +1 -1
- package/dist/server/playwright/webdriver.js +5 -8
- package/dist/server/playwright/webdriver.js.map +1 -1
- package/dist/server/providers/browser.js +6 -4
- package/dist/server/providers/browser.js.map +1 -1
- package/dist/server/providers/hybrid.js +1 -1
- package/dist/server/providers/hybrid.js.map +1 -1
- package/dist/server/reporters/creevey.d.ts +7 -0
- package/dist/server/reporters/creevey.js +63 -0
- package/dist/server/reporters/creevey.js.map +1 -0
- package/dist/server/reporters/index.d.ts +2 -0
- package/dist/server/reporters/index.js +16 -0
- package/dist/server/reporters/index.js.map +1 -0
- package/dist/server/reporters/junit.d.ts +16 -0
- package/dist/server/reporters/junit.js +165 -0
- package/dist/server/reporters/junit.js.map +1 -0
- package/dist/server/reporters/teamcity.d.ts +7 -0
- package/dist/server/reporters/teamcity.js +60 -0
- package/dist/server/reporters/teamcity.js.map +1 -0
- package/dist/server/selenium/internal.d.ts +3 -4
- package/dist/server/selenium/internal.js +127 -108
- package/dist/server/selenium/internal.js.map +1 -1
- package/dist/server/selenium/selenoid.js +8 -6
- package/dist/server/selenium/selenoid.js.map +1 -1
- package/dist/server/selenium/webdriver.d.ts +1 -1
- package/dist/server/selenium/webdriver.js +5 -9
- package/dist/server/selenium/webdriver.js.map +1 -1
- package/dist/server/telemetry.js +2 -2
- package/dist/server/testsFiles/parser.js +45 -5
- package/dist/server/testsFiles/parser.js.map +1 -1
- package/dist/server/utils.d.ts +19 -1
- package/dist/server/utils.js +87 -8
- package/dist/server/utils.js.map +1 -1
- package/dist/server/webdriver.d.ts +5 -4
- package/dist/server/webdriver.js +23 -10
- package/dist/server/webdriver.js.map +1 -1
- package/dist/server/worker/chai-image.d.ts +1 -2
- package/dist/server/worker/chai-image.js +4 -3
- package/dist/server/worker/chai-image.js.map +1 -1
- package/dist/server/worker/context.d.ts +3 -0
- package/dist/server/worker/context.js +15 -0
- package/dist/server/worker/context.js.map +1 -0
- package/dist/server/worker/match-image.d.ts +4 -4
- package/dist/server/worker/match-image.js +7 -4
- package/dist/server/worker/match-image.js.map +1 -1
- package/dist/server/worker/start.js +47 -73
- package/dist/server/worker/start.js.map +1 -1
- package/dist/shared/index.d.ts +1 -1
- package/dist/types.d.ts +46 -10
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/docs/cli.md +12 -0
- package/docs/config.md +179 -165
- package/docs/storybook.md +60 -0
- package/docs/tests.md +50 -45
- package/package.json +64 -63
- package/src/client/addon/components/Panel.tsx +2 -2
- package/src/client/addon/withCreevey.ts +10 -2
- package/src/client/shared/components/ImagesView/SwapView.tsx +18 -0
- package/src/client/shared/components/PageHeader/ImagePreview.tsx +1 -0
- package/src/client/shared/components/PageHeader/PageHeader.tsx +4 -2
- package/src/client/shared/components/ResultsPage.tsx +31 -8
- package/src/client/shared/creeveyClientApi.ts +9 -1
- package/src/client/shared/helpers.ts +4 -24
- package/src/client/web/CreeveyApp.tsx +27 -8
- package/src/client/web/CreeveyContext.tsx +9 -0
- package/src/client/web/CreeveyLoader.tsx +1 -1
- package/src/client/web/CreeveyView/SideBar/Search.tsx +3 -3
- package/src/client/web/CreeveyView/SideBar/SideBar.tsx +1 -0
- package/src/client/web/CreeveyView/SideBar/SideBarFooter.tsx +37 -6
- package/src/client/web/CreeveyView/SideBar/SuiteLink.tsx +3 -5
- package/src/client/web/CreeveyView/SideBar/TestLink.tsx +2 -4
- package/src/client/web/KeyboardEventsContext.tsx +61 -73
- package/src/client/web/themes.ts +24 -0
- package/src/creevey.ts +16 -10
- package/src/server/config.ts +30 -7
- package/src/server/connection.ts +26 -0
- package/src/server/docker.ts +63 -34
- package/src/server/index.ts +72 -14
- package/src/server/logger.ts +6 -2
- package/src/server/master/api.ts +1 -1
- package/src/server/master/pool.ts +23 -59
- package/src/server/master/queue.ts +77 -0
- package/src/server/master/runner.ts +96 -10
- package/src/server/master/server.ts +1 -1
- package/src/server/master/start.ts +16 -11
- package/src/server/playwright/docker-file.ts +18 -6
- package/src/server/playwright/docker.ts +16 -3
- package/src/server/playwright/index-source.mjs +16 -0
- package/src/server/playwright/internal.ts +182 -111
- package/src/server/playwright/webdriver.ts +6 -9
- package/src/server/providers/browser.ts +6 -4
- package/src/server/providers/hybrid.ts +1 -1
- package/src/server/reporters/creevey.ts +71 -0
- package/src/server/reporters/index.ts +11 -0
- package/src/server/reporters/junit.ts +205 -0
- package/src/server/reporters/teamcity.ts +74 -0
- package/src/server/selenium/internal.ts +131 -116
- package/src/server/selenium/selenoid.ts +8 -6
- package/src/server/selenium/webdriver.ts +6 -10
- package/src/server/telemetry.ts +2 -2
- package/src/server/testsFiles/parser.ts +52 -4
- package/src/server/utils.ts +97 -9
- package/src/server/webdriver.ts +24 -16
- package/src/server/worker/chai-image.ts +4 -4
- package/src/server/worker/context.ts +14 -0
- package/src/server/worker/match-image.ts +12 -8
- package/src/server/worker/start.ts +51 -86
- package/src/shared/index.ts +1 -1
- package/src/types.ts +50 -11
- package/types/global.d.ts +1 -0
- package/.yarnrc.yml +0 -1
- package/chromatic.config.json +0 -5
- package/dist/client/web/assets/index-DkmZfG9C.js +0 -591
- package/dist/server/reporter.d.ts +0 -26
- package/dist/server/reporter.js +0 -108
- package/dist/server/reporter.js.map +0 -1
- package/src/server/reporter.ts +0 -138
package/docs/config.md
CHANGED
@@ -1,212 +1,226 @@
|
|
1
|
-
|
1
|
+
# Creevey Configuration Examples
|
2
2
|
|
3
|
-
|
3
|
+
Creevey is highly configurable and can be tailored to your specific needs. Here are some examples of how to configure Creevey for your Storybook.
|
4
4
|
|
5
|
-
|
6
|
-
- `--ui` — Start runner web server
|
7
|
-
- `--update` — Approve all images from `report` directory
|
8
|
-
- `--port` — Specify port for web server. Default `3000`
|
9
|
-
- `--reportDir` — Path where reports will be stored
|
10
|
-
- `--screenDir` — Path where reference images are located
|
11
|
-
- `--debug` — Enable debug output
|
5
|
+
## Zero Configuration
|
12
6
|
|
13
|
-
|
7
|
+
The simplest way to get started with Creevey, just run it without any configuration:
|
14
8
|
|
15
|
-
|
9
|
+
```bash
|
10
|
+
yarn creevey -s
|
11
|
+
```
|
12
|
+
|
13
|
+
This will start Creevey with default settings, using Chrome as the browser and also start Storybook hosted at `http://localhost:6006`. Adding `--ui` flag will start the web server for the UI Runner.
|
14
|
+
|
15
|
+
**NOTE** By default, Creevey uses Selenium WebDriver, but it's done for backward compatibility and it's recommended to define webdriver explicitly in the configuration.
|
16
16
|
|
17
17
|
```ts
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
},
|
18
|
+
// creevey.config.ts
|
19
|
+
import { SeleniumWebdriver } from 'creevey/selenium';
|
20
|
+
|
21
|
+
const config = {
|
22
|
+
webdriver: SeleniumWebdriver,
|
23
|
+
};
|
24
|
+
|
25
|
+
// or use Playwright instead
|
26
|
+
|
27
|
+
import { PlaywrightWebdriver } from 'creevey/playwright';
|
28
|
+
|
29
|
+
const config = {
|
30
|
+
webdriver: PlaywrightWebdriver,
|
32
31
|
};
|
33
32
|
```
|
34
33
|
|
35
|
-
|
34
|
+
## Basic Configuration
|
36
35
|
|
37
|
-
|
36
|
+
The minimal configuration to test your stories might be:
|
38
37
|
|
39
38
|
```ts
|
40
|
-
|
39
|
+
// creevey.config.ts
|
40
|
+
import { CreeveyConfig } from 'creevey';
|
41
|
+
import { PlaywrightWebdriver } from 'creevey/playwright';
|
42
|
+
|
43
|
+
const config: CreeveyConfig = {
|
44
|
+
webdriver: PlaywrightWebdriver,
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
// The URL where your Storybook is hosted
|
47
|
+
storybookUrl: 'http://localhost:9000',
|
48
|
+
|
49
|
+
// Define which browsers to use for testing
|
50
|
+
browsers: {
|
51
|
+
chromium: {
|
52
|
+
// The browser type name which will be used by Playwright
|
53
|
+
browserName: 'chromium',
|
54
|
+
// Default viewport dimensions
|
55
|
+
viewport: { width: 1024, height: 768 },
|
56
|
+
// Limit of retries for failed tests
|
57
|
+
maxRetries: 2,
|
58
|
+
},
|
59
|
+
},
|
60
|
+
};
|
46
61
|
|
47
|
-
|
48
|
-
|
62
|
+
export default config;
|
63
|
+
```
|
49
64
|
|
50
|
-
|
51
|
-
screenDir: path.join(__dirname, '../images'),
|
65
|
+
## Multiple Browsers Configuration
|
52
66
|
|
53
|
-
|
54
|
-
reportDir: path.join(__dirname, '../report'),
|
67
|
+
It's possible to est your stories across different browsers:
|
55
68
|
|
56
|
-
|
57
|
-
|
69
|
+
```ts
|
70
|
+
// creevey.config.ts
|
71
|
+
import { CreeveyConfig } from 'creevey';
|
72
|
+
import { PlaywrightWebdriver } from 'creevey/playwright';
|
58
73
|
|
59
|
-
|
60
|
-
|
74
|
+
const config: CreeveyConfig = {
|
75
|
+
webdriver: PlaywrightWebdriver,
|
61
76
|
|
62
|
-
// Describe browsers and their options
|
63
77
|
browsers: {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
otherChrome: {
|
69
|
-
browserName: 'chrome',
|
70
|
-
// Define initial viewport size
|
71
|
-
viewport: { width: 1024, height: 720 },
|
72
|
-
// Increase parallel sessions
|
78
|
+
chromium: {
|
79
|
+
browserName: 'chromium',
|
80
|
+
// Amount of parallel browser sessions
|
73
81
|
limit: 2,
|
74
|
-
/* Also you can define any browser capabilities here */
|
75
|
-
version: '86.0',
|
76
|
-
// It's possible to set Storybook's globals
|
77
|
-
// https://github.com/storybookjs/storybook/blob/v6.0.0/docs/essentials/toolbars-and-globals.md
|
78
|
-
// NOTE: This is an experimental feature and will be replaced in future
|
79
|
-
_storybookGlobals: {
|
80
|
-
myTheme: 'dark',
|
81
|
-
},
|
82
82
|
},
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
browserName: 'internet explorer',
|
87
|
-
// Like user another Selenium Grid url
|
88
|
-
gridUrl: '<anotherGridUrl>/wd/hub',
|
89
|
-
// Or use different storybook instance
|
90
|
-
storybookUrl: 'http://mystoryhost:6007',
|
91
|
-
// And use you own docker image
|
92
|
-
// By default Creevey will use selenoid image according browser name and version:
|
93
|
-
// `selenoid/${browserName}:${version ?? 'latest'}` image
|
94
|
-
dockerImage: 'microsoft/ie:11.0',
|
83
|
+
firefox: {
|
84
|
+
browserName: 'firefox',
|
85
|
+
limit: 2,
|
95
86
|
},
|
96
87
|
},
|
88
|
+
};
|
89
|
+
|
90
|
+
export default config;
|
91
|
+
```
|
92
|
+
|
93
|
+
## Test stories with different themes
|
94
|
+
|
95
|
+
Test your components with different themes:
|
97
96
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
```ts
|
98
|
+
// creevey.config.ts
|
99
|
+
import { CreeveyConfig } from 'creevey';
|
100
|
+
import { PlaywrightWebdriver } from 'creevey/playwright';
|
101
|
+
|
102
|
+
const config: CreeveyConfig = {
|
103
|
+
webdriver: PlaywrightWebdriver,
|
104
|
+
browsers: {
|
105
|
+
dark: {
|
106
|
+
browserName: 'chromium',
|
107
|
+
// Define a storybook globals which will be applied to the stories
|
108
|
+
_storybookGlobals: {
|
109
|
+
theme: 'dark',
|
110
|
+
},
|
102
111
|
},
|
103
|
-
|
104
|
-
|
112
|
+
light: {
|
113
|
+
browserName: 'chromium',
|
114
|
+
_storybookGlobals: {
|
115
|
+
theme: 'light',
|
116
|
+
},
|
105
117
|
},
|
106
118
|
},
|
107
119
|
};
|
120
|
+
|
121
|
+
export default config;
|
108
122
|
```
|
109
123
|
|
110
|
-
|
124
|
+
## Using dedicated Selenium Grid server
|
111
125
|
|
112
|
-
|
126
|
+
Use Selenium Grid for distributed testing:
|
113
127
|
|
114
|
-
```
|
115
|
-
// .
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
128
|
+
```ts
|
129
|
+
// creevey.config.ts
|
130
|
+
import { CreeveyConfig } from 'creevey';
|
131
|
+
import { SeleniumWebdriver } from 'creevey/selenium';
|
132
|
+
|
133
|
+
const config: CreeveyConfig = {
|
134
|
+
webdriver: SeleniumWebdriver,
|
135
|
+
// Selenium Grid connection settings
|
136
|
+
gridUrl: 'http://selenium-hub:4444/wd/hub',
|
137
|
+
browsers: {
|
138
|
+
chrome: {
|
139
|
+
browserName: 'chrome',
|
140
|
+
// You can define any additional selenium capabilities here
|
141
|
+
// https://w3c.github.io/webdriver/#capabilities
|
142
|
+
seleniumCapabilities: {
|
143
|
+
browserVersion: '128.0',
|
144
|
+
platformName: 'linux',
|
145
|
+
},
|
121
146
|
},
|
122
147
|
},
|
123
148
|
};
|
149
|
+
|
150
|
+
export default config;
|
124
151
|
```
|
125
152
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
153
|
+
## Playwright configuration options
|
154
|
+
|
155
|
+
Leverage Playwright for testing:
|
156
|
+
|
157
|
+
```ts
|
158
|
+
// creevey.config.ts
|
159
|
+
import { CreeveyConfig } from 'creevey';
|
160
|
+
import { PlaywrightWebdriver } from 'creevey/playwright';
|
161
|
+
|
162
|
+
const config: CreeveyConfig = {
|
163
|
+
webdriver: PlaywrightWebdriver,
|
164
|
+
browsers: {
|
165
|
+
chromium: {
|
166
|
+
browserName: 'chromium',
|
167
|
+
// Playwright-specific options
|
168
|
+
// https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server
|
169
|
+
playwrightOptions: {
|
170
|
+
headless: false,
|
171
|
+
channel: 'chrome-canary',
|
172
|
+
slowMo: 50, // Slow down Playwright operations by 50ms
|
144
173
|
},
|
145
174
|
},
|
146
175
|
},
|
147
|
-
} as Meta & CreeveyMeta;
|
148
|
-
|
149
|
-
export const Basic: Story & CreeveyStory = () => <MyComponent />;
|
150
|
-
Basic.parameters = {
|
151
|
-
creevey: {
|
152
|
-
captureElement: '.container',
|
153
|
-
// elements to ignore in capturing screenshot
|
154
|
-
ignoreElements: ['button', '.local-time'],
|
155
|
-
// Delay before test starts in ms
|
156
|
-
delay: 1000,
|
157
|
-
tests: {
|
158
|
-
/* ... */
|
159
|
-
},
|
160
|
-
},
|
161
176
|
};
|
177
|
+
|
178
|
+
export default config;
|
162
179
|
```
|
163
180
|
|
164
|
-
|
181
|
+
## Advanced Configuration
|
182
|
+
|
183
|
+
Comprehensive example combining multiple features and additional options:
|
165
184
|
|
166
185
|
```ts
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
186
|
+
// creevey.config.ts
|
187
|
+
import path from 'path';
|
188
|
+
import MochaJUnitReporter from 'mocha-junit-reporter';
|
189
|
+
import { CreeveyConfig } from 'creevey';
|
190
|
+
import { PlaywrightWebdriver } from 'creevey/playwright';
|
191
|
+
|
192
|
+
const config: CreeveyConfig = {
|
193
|
+
webdriver: PlaywrightWebdriver,
|
194
|
+
|
195
|
+
// It's possible to resolve Storybook URL at the runtime
|
196
|
+
resolveStorybookUrl: () =>
|
197
|
+
fetch('https://example.com/resolve-ip')
|
198
|
+
.then((res) => res.text())
|
199
|
+
.then((data) => `http://${data}:6006`),
|
200
|
+
|
201
|
+
// Define custom reference screenshots directory
|
202
|
+
screenDir: path.join(process.cwd(), 'screenshots'),
|
203
|
+
|
204
|
+
// Define custom report directory
|
205
|
+
reportDir: path.join(process.cwd(), 'reports'),
|
206
|
+
|
207
|
+
// Define path where Creevey tests are located
|
208
|
+
testDir: path.join(process.cwd(), 'tests'),
|
209
|
+
|
210
|
+
// You can use any Mocha-like reporter
|
211
|
+
reporter: MochaJUnitReporter,
|
176
212
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
- `skip: { 'Skip reason message': { stories: ['simple', 'special'] } }`
|
192
|
-
- `skip: { 'Skip reason message': { stories: /.*large$/ } }`
|
193
|
-
- Skip specific tests:
|
194
|
-
- `skip: { 'Skip reason message': { tests: 'click' } }`
|
195
|
-
- `skip: { 'Skip reason message': { tests: ['hover', 'click'] } }`
|
196
|
-
- `skip: { 'Skip reason message': { tests: /^press.*$/ } }`
|
197
|
-
- Multiple skip options:
|
198
|
-
- for one reason
|
199
|
-
```
|
200
|
-
skip: {
|
201
|
-
"reason": [{ /* ... */ }, { /* ... */ }],
|
202
|
-
}
|
203
|
-
```
|
204
|
-
- for several reasons
|
205
|
-
```
|
206
|
-
skip: {
|
207
|
-
"reason 1": { /* ... */ },
|
208
|
-
"reason 2": { /* ... */ },
|
209
|
-
}
|
210
|
-
```
|
211
|
-
|
212
|
-
NOTE: If you try to skip stories by story name, the storybook name format will be used (For more info see [storybook-export-vs-name-handling](https://storybook.js.org/docs/formats/component-story-format/#storybook-export-vs-name-handling))
|
213
|
+
// Pixelmatch options
|
214
|
+
diffOptions: { threshold: 0.1 },
|
215
|
+
|
216
|
+
// Regex pattern to match test files
|
217
|
+
testsRegex: /\.creevey\.ts$/,
|
218
|
+
|
219
|
+
// Disable using docker, to start browsers locally, it's useful for CI
|
220
|
+
useDocker: process.env.CI,
|
221
|
+
|
222
|
+
browsers: {
|
223
|
+
/* ... */
|
224
|
+
},
|
225
|
+
};
|
226
|
+
```
|
@@ -0,0 +1,60 @@
|
|
1
|
+
## Creevey Storybook Parameters
|
2
|
+
|
3
|
+
Creevey allows you to customize how stories will be captured. You could define parameters on `global`, `kind` or `story` levels. All these parameters are deeply merged by Storybook for each story.
|
4
|
+
|
5
|
+
```ts
|
6
|
+
// .storybook/preview.tsx
|
7
|
+
export const parameters = {
|
8
|
+
creevey: {
|
9
|
+
// Global parameters are applied to all stories
|
10
|
+
captureElement: '#storybook-root',
|
11
|
+
},
|
12
|
+
};
|
13
|
+
```
|
14
|
+
|
15
|
+
```ts
|
16
|
+
// stories/MyModal.stories.tsx
|
17
|
+
import React from 'react';
|
18
|
+
import { Meta, StoryObj } from '@storybook/react';
|
19
|
+
import { CreeveyMeta, CreeveyStory } from 'creevey';
|
20
|
+
import MyModal from './src/components/MyModal';
|
21
|
+
|
22
|
+
const Kind: Meta<typeof MyModal> = {
|
23
|
+
title: 'MyModal',
|
24
|
+
component: MyModal,
|
25
|
+
parameters: {
|
26
|
+
creevey: {
|
27
|
+
// It's possible to add additional delay before capturing screenshot
|
28
|
+
delay: 1000,
|
29
|
+
|
30
|
+
// For capturing the whole browser viewport, you can define `null` instead of css selector.
|
31
|
+
captureElement: null,
|
32
|
+
|
33
|
+
// You can skip some stories from capturing, by defining `skip` option:
|
34
|
+
// skip: { "The reason why story is skipped": { in: 'chrome', stories: 'Loading' } }
|
35
|
+
// - `in` - browser name, regex or array of browser names, which are defined in the Creevey config
|
36
|
+
// - `stories` - story name, regex or array of story names
|
37
|
+
// - `tests` - test name, regex or array of test names
|
38
|
+
// NOTE: If you try to skip stories by story name, the storybook name format will be used
|
39
|
+
// For more info see [storybook-export-vs-name-handling](https://storybook.js.org/docs/formats/component-story-format/#storybook-export-vs-name-handling))
|
40
|
+
skip: {
|
41
|
+
"`MyModal` doesn't support ie11": { in: 'ie11' },
|
42
|
+
'Loading stories are flaky in firefox': { in: 'firefox', stories: 'Loading' },
|
43
|
+
"`MyModal` hovering doesn't work correctly": {
|
44
|
+
in: ['firefox', 'chrome'],
|
45
|
+
tests: /.*hover$/,
|
46
|
+
},
|
47
|
+
},
|
48
|
+
},
|
49
|
+
},
|
50
|
+
};
|
51
|
+
|
52
|
+
export default Kind;
|
53
|
+
|
54
|
+
export const Basic: StoryObj<typeof MyModal> = {
|
55
|
+
creevey: {
|
56
|
+
// Lastly some elements can be ignored in capturing screenshot
|
57
|
+
ignoreElements: ['button', '.local-time'],
|
58
|
+
},
|
59
|
+
};
|
60
|
+
```
|
package/docs/tests.md
CHANGED
@@ -1,63 +1,68 @@
|
|
1
|
-
## Write tests
|
1
|
+
## Write interactive screenshot tests
|
2
2
|
|
3
|
-
|
3
|
+
In most cases following Storybook's ideology of [writing stories](https://storybook.js.org/docs/get-started/whats-a-story) is enough to test your UI components. Where each component has a separate stories file with its different states. But sometimes you might have pretty complicated components with a lot of interactions and internal states. In this case, you can write tests for your stories.
|
4
4
|
|
5
|
-
|
6
|
-
import React from 'react';
|
7
|
-
import { Story } from '@storybook/react';
|
8
|
-
import { CreeveyStory } from 'creevey';
|
9
|
-
import MyComponent from './src/components/MyComponent';
|
5
|
+
There are two different ways how to write interactive tests with Creevey:
|
10
6
|
|
11
|
-
|
7
|
+
### Write tests in `*.creevey.ts` files
|
12
8
|
|
13
|
-
|
14
|
-
Basic.parameters = {
|
15
|
-
creevey: {
|
16
|
-
captureElement: '#storybook-root',
|
17
|
-
tests: {
|
18
|
-
async click() {
|
19
|
-
await this.browser.actions().click(this.captureElement).perform();
|
9
|
+
It's the recommended way to write tests. It allows you to run these tests by Creevey itself and utilize webdriver benefits. The crucial part of it is webdriver action calls are more close to real user interactions and mitigate flakiness and false-negative results. Here is a simple example of how to write tests in `*.creevey.ts` files
|
20
10
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
```ts
|
12
|
+
// stories/MyComponent.creevey.ts
|
13
|
+
import { kind, story, test } from 'creevey';
|
14
|
+
|
15
|
+
kind('MyComponent', () => {
|
16
|
+
story('Story', ({ setStoryParameters }) => {
|
17
|
+
// It's possible to pass Creevey parameters to story
|
18
|
+
setStoryParameters({
|
19
|
+
captureElement: 'span[data-test-id~="x"]',
|
20
|
+
ignoreElements: [],
|
21
|
+
});
|
22
|
+
|
23
|
+
test('idle', async (context) => {
|
24
|
+
await context.matchImage(await context.takeScreenshot());
|
25
|
+
});
|
26
|
+
|
27
|
+
test('input', async (context) => {
|
28
|
+
await context.webdriver.keyboard.press('Tab');
|
29
|
+
const focus = await context.takeScreenshot();
|
30
|
+
await context.webdriver.keyboard.type('Hello Creevey');
|
31
|
+
const input = await context.takeScreenshot();
|
32
|
+
await context.matchImages({ focus, input });
|
33
|
+
});
|
34
|
+
});
|
35
|
+
});
|
26
36
|
```
|
27
37
|
|
28
|
-
|
38
|
+
In the example above, we used Playwright API to interact with the story. But Creevey also supports Selenium webdriver. And in that case `context.webdriver` will be an instance of Selenium webdriver. Obviously Selenium API is different from Playwright.
|
29
39
|
|
30
|
-
|
40
|
+
### Using Storybook's `play` function
|
31
41
|
|
32
|
-
|
33
|
-
import React from 'react';
|
34
|
-
import { CSFStory } from 'creevey';
|
35
|
-
import MyForm from './src/components/MyForm';
|
42
|
+
Storybook allows you to write tests in the story file itself by using [`play` function](https://storybook.js.org/docs/writing-tests/component-testing). It's a good way to write simple tests. But there are couple drawbacks of this approach:
|
36
43
|
|
37
|
-
|
44
|
+
- You can have only one test per story. Which is not a big deal, but sometimes you might not want to have multiple stories with the same markup.
|
45
|
+
- Tests are running in browser environment and use https://testing-library.com API under the hood. It's good for unit tests, but might not be suitable for visual regression tests, because testing-library relies on DOM API and not even close to real user interactions. For example, you might have a button that could be visible for user, but it's covered by some other transparent element. With testing-library the button easily accessible and clickable, but the user can't interact with it.
|
38
46
|
|
39
|
-
|
40
|
-
Basic.story = {
|
41
|
-
parameters: {
|
42
|
-
creevey: {
|
43
|
-
captureElement: '#storybook-root',
|
44
|
-
delay: 1000,
|
45
|
-
tests: {
|
46
|
-
async submit() {
|
47
|
-
const input = await this.browser.findElement({ css: '.my-input' });
|
47
|
+
Here is an example of how to write tests using Storybook's `play` function:
|
48
48
|
|
49
|
-
|
49
|
+
```tsx
|
50
|
+
// stories/MyComponent.stories.tsx
|
51
|
+
import React from 'react';
|
52
|
+
import { Meta, StoryObj } from '@storybook/react';
|
53
|
+
import { fireEvent, within } from '@storybook/test';
|
54
|
+
import MyComponent from './src/components/MyComponent';
|
50
55
|
|
51
|
-
|
56
|
+
export default {
|
57
|
+
title: 'MyComponent',
|
58
|
+
component: MyComponent,
|
59
|
+
};
|
52
60
|
|
53
|
-
|
61
|
+
export const Basic: StoryObj<typeof MyComponent> = {
|
62
|
+
play: async ({ canvasElement }) => {
|
63
|
+
const slider = await within(canvasElement).findByTestId('slider');
|
54
64
|
|
55
|
-
|
56
|
-
},
|
57
|
-
},
|
58
|
-
},
|
65
|
+
await fireEvent.change(slider, { target: { value: 50 } });
|
59
66
|
},
|
60
67
|
};
|
61
68
|
```
|
62
|
-
|
63
|
-
NOTE: In this example I fill some simple form and submit it. Also as you could see, I taking two different screenshots `empty` and `submitted` and assert these in the end.
|