@storysnap/cli 1.2.1 → 1.3.0

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.
@@ -57,6 +57,8 @@ export declare const configSchema: z.ZodEffects<z.ZodObject<{
57
57
  waitForSelector: z.ZodDefault<z.ZodString>;
58
58
  waitTimeout: z.ZodDefault<z.ZodNumber>;
59
59
  concurrency: z.ZodDefault<z.ZodNumber>;
60
+ ignoreSelectors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
61
+ ignoreColor: z.ZodOptional<z.ZodString>;
60
62
  apiUrl: z.ZodOptional<z.ZodString>;
61
63
  apiToken: z.ZodOptional<z.ZodString>;
62
64
  }, "strip", z.ZodTypeAny, {
@@ -87,6 +89,8 @@ export declare const configSchema: z.ZodEffects<z.ZodObject<{
87
89
  localSnapshotsDir?: string | undefined;
88
90
  include?: string[] | undefined;
89
91
  exclude?: string[] | undefined;
92
+ ignoreSelectors?: string[] | undefined;
93
+ ignoreColor?: string | undefined;
90
94
  apiUrl?: string | undefined;
91
95
  apiToken?: string | undefined;
92
96
  }, {
@@ -117,6 +121,8 @@ export declare const configSchema: z.ZodEffects<z.ZodObject<{
117
121
  waitForSelector?: string | undefined;
118
122
  waitTimeout?: number | undefined;
119
123
  concurrency?: number | undefined;
124
+ ignoreSelectors?: string[] | undefined;
125
+ ignoreColor?: string | undefined;
120
126
  apiUrl?: string | undefined;
121
127
  apiToken?: string | undefined;
122
128
  }>, {
@@ -147,6 +153,8 @@ export declare const configSchema: z.ZodEffects<z.ZodObject<{
147
153
  localSnapshotsDir?: string | undefined;
148
154
  include?: string[] | undefined;
149
155
  exclude?: string[] | undefined;
156
+ ignoreSelectors?: string[] | undefined;
157
+ ignoreColor?: string | undefined;
150
158
  apiUrl?: string | undefined;
151
159
  apiToken?: string | undefined;
152
160
  }, {
@@ -177,6 +185,8 @@ export declare const configSchema: z.ZodEffects<z.ZodObject<{
177
185
  waitForSelector?: string | undefined;
178
186
  waitTimeout?: number | undefined;
179
187
  concurrency?: number | undefined;
188
+ ignoreSelectors?: string[] | undefined;
189
+ ignoreColor?: string | undefined;
180
190
  apiUrl?: string | undefined;
181
191
  apiToken?: string | undefined;
182
192
  }>;
@@ -53,6 +53,13 @@ export const configSchema = z.object({
53
53
  // page settling, so a few in parallel cut the run time almost linearly; the
54
54
  // ceiling is the machine running the browsers and the Storybook serving them.
55
55
  concurrency: z.number().int().min(1).default(4),
56
+ // Elements matching these are painted over in every capture, as is anything
57
+ // marked data-storysnap-ignore, so dynamic content - dates, avatars, ads -
58
+ // cannot fail a run. Handy for markup written for another tool, such as
59
+ // Chromatic's [data-chromatic="ignore"] and .chromatic-ignore.
60
+ ignoreSelectors: z.array(z.string().min(1)).optional(),
61
+ // The colour of that paint. Any CSS colour.
62
+ ignoreColor: z.string().min(1).optional(),
56
63
  // API configuration (optional - can also use ~/.storysnap/credentials)
57
64
  apiUrl: z.string().url().optional(),
58
65
  apiToken: z.string().optional(),
@@ -15,6 +15,11 @@ export declare class ScreenshotEngine {
15
15
  * to its messages, which buries the actual reason when printed per story.
16
16
  */
17
17
  export declare function describeCaptureError(error: unknown): string;
18
+ /** Marks an element whose contents are left out of the comparison. */
19
+ export declare const IGNORE_ATTRIBUTE = "data-storysnap-ignore";
20
+ export declare const DEFAULT_IGNORE_COLOR = "#808080";
21
+ /** The built-in attribute plus any selectors the config adds, as one selector list. */
22
+ export declare function getIgnoreSelector(extraSelectors?: readonly string[]): string;
18
23
  export declare function getScreenshotKey(storyId: string, browser: Browser): string;
19
24
  export declare function parseScreenshotKey(key: string): {
20
25
  storyId: string;
@@ -52,9 +52,14 @@ export class ScreenshotEngine {
52
52
  });
53
53
  // Additional wait for any animations or lazy loading
54
54
  await this.waitForStability(page);
55
+ // Ignored elements are painted over in every capture, baseline and
56
+ // current alike, so their contents never register as a diff. The box
57
+ // still follows the element, so moving or resizing it does.
55
58
  const buffer = await page.screenshot({
56
59
  fullPage: false,
57
60
  type: 'png',
61
+ mask: [page.locator(getIgnoreSelector(this.config.ignoreSelectors))],
62
+ maskColor: this.config.ignoreColor ?? DEFAULT_IGNORE_COLOR,
58
63
  });
59
64
  return {
60
65
  storyId: story.id,
@@ -115,6 +120,13 @@ export function describeCaptureError(error) {
115
120
  const message = error instanceof Error ? error.message : String(error);
116
121
  return message.split('\n')[0].trim() || 'Unknown capture error';
117
122
  }
123
+ /** Marks an element whose contents are left out of the comparison. */
124
+ export const IGNORE_ATTRIBUTE = 'data-storysnap-ignore';
125
+ export const DEFAULT_IGNORE_COLOR = '#808080';
126
+ /** The built-in attribute plus any selectors the config adds, as one selector list. */
127
+ export function getIgnoreSelector(extraSelectors = []) {
128
+ return [`[${IGNORE_ATTRIBUTE}]`, ...extraSelectors].join(', ');
129
+ }
118
130
  export function getScreenshotKey(storyId, browser) {
119
131
  return `${storyId}::${browser}`;
120
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storysnap/cli",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Visual regression testing for Storybook - capture screenshots, detect changes, and maintain baselines",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",