You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/storybook-story-modes.mdx
+31-29Lines changed: 31 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ A mode is a preset that configures various Storybook globals. For instance, you
25
25
26
26
## Setting up globals & addons
27
27
28
-
Before you define any modes, make sure you’ve configured the relevant Storybook addons in your .storybook/preview.js (or .storybook/preview.ts) file. Examples include:
28
+
Before you define any modes, make sure you’ve configured the relevant Storybook addons in your `.storybook/preview.ts` (or `.js`) file. Examples include:
29
29
30
30
-[`@storybook/addon-viewport`](https://www.npmjs.com/package/@storybook/addon-viewport) for screen sizes
31
31
-[`@storybook/addon-themes`](https://www.npmjs.com/package/@storybook/addon-themes) for light/dark themes
@@ -34,8 +34,7 @@ Before you define any modes, make sure you’ve configured the relevant Storyboo
34
34
35
35
These addons utilize Storybook “globals” and “decorators” under the hood. Argos modes simply manipulate those globals at test time to generate multiple snapshots of the same story.
Create a `.storybook/modes.js` (or `.ts`) file that exports an object where each key is a mode name and each value is a set of overrides for the Storybook globals. For example:
80
-
81
-
```ts
82
-
// .storybook/modes.js
78
+
Create a `.storybook/modes.ts` (or `.js`) file that exports an object where each key is a mode name and each value is a set of overrides for the Storybook globals. For example:
83
79
80
+
```ts title=".storybook/modes.ts"
84
81
exportconst allModes = {
85
82
dark: {
86
83
backgrounds: { value: "#1A1A1A" },
@@ -106,17 +103,18 @@ Each object can include as many or as few globals as you need. If a mode doesn
106
103
107
104
## Applying modes
108
105
109
-
Attach modes to any level of your Storybook: globally in `.storybook/preview.js`, at the component (default export) level, or in an individual story’s parameters. Argos merges all modes defined up the chain.
106
+
Attach modes to any level of your Storybook: globally in `.storybook/preview.ts` (or `.js`), at the component (default export) level, or in an individual story’s parameters. Argos merges all modes defined up the chain.
@@ -152,12 +151,11 @@ In this example, Argos will generate two snapshots for each story (DefaultView a
152
151
153
152
## Combining modes from multiple levels
154
153
155
-
You can add modes in your .storybook/preview.js at the project level, then define additional modes in a story file. Argos “stacks” these modes, creating a snapshot for every combination.
154
+
You can add modes in your `.storybook/preview.ts` (or `.js`) at the project level, then define additional modes in a story file. Argos “stacks” these modes, creating a snapshot for every combination.
156
155
157
156
### Project-level modes
158
157
159
-
```ts
160
-
// .storybook/preview.js
158
+
```ts title=".storybook/modes.ts"
161
159
import { allModes } from"./modes";
162
160
163
161
const preview = {
@@ -175,12 +173,13 @@ export default preview;
175
173
176
174
### Component-level modes
177
175
178
-
```ts
179
-
// ProductCard.stories.js
176
+
```ts title="ProductCard.stories.ts"
177
+
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, nextjs-vite, etc.
When Argos runs, it will generate snapshots for each mode defined at the project level and the component level. So for Basic, you get “light mobile” (from `preview.js`) plus “dark widescreen” (from the component’s parameter).
204
+
When Argos runs, it will generate snapshots for each mode defined at the project level and the component level. So for Basic, you get “light mobile” (from `preview.ts`) plus “dark widescreen” (from the component’s parameter).
204
205
205
206
## Excluding or disabling modes
206
207
207
208
Sometimes you want to turn off a certain higher-level mode for a specific story. You can do this by passing a disable property:
Copy file name to clipboardExpand all lines: docs/guides/viewports.mdx
+50-8Lines changed: 50 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,30 +5,36 @@ title: Responsive Viewports
5
5
6
6
# Configuring Responsive Viewports
7
7
8
-
Master responsive testing with Argos: Easily configure viewports for Playwright, Cypress, and Puppeteer, ensuring your app looks great on any device.
8
+
Argos lets you capture the same page at multiple breakpoints with a single test. Configure viewports once and get consistent responsive coverage across Playwright, Cypress and Puppeteer.
9
9
10
10
## Prerequisites
11
11
12
12
This advanced feature integrates smoothly with [Playwright](/playwright), [Cypress](/cypress), and [Puppeteer](/puppeteer) to enhance your testing capabilities.
13
13
14
+
This feature works seamlessly with [Playwright](/playwright), [Cypress](/cypress) and [Puppeteer](/puppeteer).
15
+
16
+
:::note
17
+
18
+
If you use Storybook, see the dedicated guide on [Storybook modes](/storybook-story-modes).
19
+
20
+
:::
21
+
14
22
## Viewport Configuration
15
23
16
-
Adjust the `argosScreenshot()`command in your test scripts to capture responsive screenshots. You can specify exact dimensions or use device presets to mimic real-world scenarios:
24
+
Pass a viewports array to `argosScreenshot()`to generate screenshots for each dimension or preset you define. You can mix explicit sizes and device presets.
{ preset:"ipad-2", orientation:"landscape" },// Device preset with orientation
29
+
"iphone-4",
30
+
{ width:800, height:600 },
31
+
{ preset:"ipad-2", orientation:"landscape" },
24
32
],
25
33
});
26
34
```
27
35
28
36
## Available Presets
29
37
30
-
List of available device presets with their respective dimensions:
31
-
32
38
| Preset | Width (px) | Height (px) |
33
39
| ------------- | ---------- | ----------- |
34
40
| macbook-16 | 1536 | 960 |
@@ -52,4 +58,40 @@ List of available device presets with their respective dimensions:
52
58
53
59
## Troubleshooting and Best Practices
54
60
55
-
To ensure accurate rendering, always set the viewport size with `page.setViewportSize()` before navigating to the target page, as many sites do not dynamically adapt to changes in viewport size after the page has loaded. For comprehensive testing, consider running your tests across all intended viewports to validate responsive behavior across the board.
61
+
Many sites compute layout at load time and will not adapt cleanly if the viewport changes later. If you notice issues, you may want to run your test suite entirely for each viewport instead of changing the viewport before taking each screenshot.
62
+
63
+
For example, in Playwright you can create a separate browser context for each viewport size.
0 commit comments