vitest-plugin-vis 3.2.0 → 3.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.
@@ -6,6 +6,7 @@ export * from './client/actions/match_page_image_snapshot_action.ts';
6
6
  export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts';
7
7
  export * from './client/expect/expectation_result.ts';
8
8
  export type * from './client/expect/to_match_image_snapshot.types.ts';
9
+ export * from './client/setup/create_vis.ts';
9
10
  export * from './client/task_id.ts';
10
11
  export * from './shared/constants.ts';
11
12
  export type * from './shared/types.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"client-api.d.ts","sourceRoot":"","sources":["../src/client-api.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,cAAc,+CAA+C,CAAA;AAC7D,cAAc,wDAAwD,CAAA;AACtE,cAAc,iDAAiD,CAAA;AAC/D,cAAc,sDAAsD,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,KAAK,QAAQ,EAAE,MAAM,mCAAmC,CAAA;AACzF,cAAc,uCAAuC,CAAA;AACrD,mBAAmB,kDAAkD,CAAA;AACrE,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,mBAAmB,mBAAmB,CAAA"}
1
+ {"version":3,"file":"client-api.d.ts","sourceRoot":"","sources":["../src/client-api.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,cAAc,+CAA+C,CAAA;AAC7D,cAAc,wDAAwD,CAAA;AACtE,cAAc,iDAAiD,CAAA;AAC/D,cAAc,sDAAsD,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,KAAK,QAAQ,EAAE,MAAM,mCAAmC,CAAA;AACzF,cAAc,uCAAuC,CAAA;AACrD,mBAAmB,kDAAkD,CAAA;AACrE,cAAc,8BAA8B,CAAA;AAC5C,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,mBAAmB,mBAAmB,CAAA"}
package/esm/client-api.js CHANGED
@@ -5,5 +5,6 @@ export * from "./client/actions/match_image_snapshot_action.js";
5
5
  export * from "./client/actions/match_page_image_snapshot_action.js";
6
6
  export { setAutoSnapshotOptions } from "./client/auto_snapshot_options.js";
7
7
  export * from "./client/expect/expectation_result.js";
8
+ export * from "./client/setup/create_vis.js";
8
9
  export * from "./client/task_id.js";
9
10
  export * from "./shared/constants.js";
@@ -16,12 +16,14 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim'
16
16
  /**
17
17
  * Loads the `test.setupFiles` of the specified preset.
18
18
  *
19
- * Note: 'enable` is deprecated. Use `manual` for the same effect.
19
+ * Note:
20
+ * - 'enable` is deprecated. Use `manual` for the same effect.
21
+ * - 'none` is deprecated. Use `custom` for the same effect.
20
22
  *
21
23
  * @default 'auto'
22
24
  *
23
25
  */
24
- preset?: 'enable' | 'manual' | 'auto' | 'none' | undefined;
26
+ preset?: 'enable' | 'manual' | 'auto' | 'custom' | 'none' | undefined;
25
27
  /**
26
28
  * The snapshot folder relative to the root of the project.
27
29
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,sBAAsB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,eAAe,EAAE,CAAA;AAElH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,CAAC,CAAC,SAAS,MAAM,GAC7E;IACA,gBAAgB,EAAE,CAAC,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,CAAA;CAClD,GACA;IACA,gBAAgB,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;CAC1C,CAAC,GACH,uBAAuB,GACvB,2BAA2B,GAC3B,uBAAuB,GACvB,2BAA2B,GAAG;IAC7B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC1D;;;;OAIG;IACH,eAAe,CAAC,EACb,MAAM,GACN,CAAC,CAAC,OAAO,EAAE;QACX,EAAE,EAAE,OAAO,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAChC,YAAY,EAAE,MAAM,CAAA;QACpB,QAAQ,EAAE,MAAM,CAAA;QAChB,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACxC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KACvC,KAAK,MAAM,CAAC,GACb,SAAS,CAAA;IACZ;;;;;;;;;;;;;;;OAeG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACxE,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,sBAAsB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,eAAe,EAAE,CAAA;AAElH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,CAAC,CAAC,SAAS,MAAM,GAC7E;IACA,gBAAgB,EAAE,CAAC,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,CAAA;CAClD,GACA;IACA,gBAAgB,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;CAC1C,CAAC,GACH,uBAAuB,GACvB,2BAA2B,GAC3B,uBAAuB,GACvB,2BAA2B,GAAG;IAC7B;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAA;IACrE;;;;OAIG;IACH,eAAe,CAAC,EACb,MAAM,GACN,CAAC,CAAC,OAAO,EAAE;QACX,EAAE,EAAE,OAAO,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAChC,YAAY,EAAE,MAAM,CAAA;QACpB,QAAQ,EAAE,MAAM,CAAA;QAChB,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACxC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KACvC,KAAK,MAAM,CAAC,GACb,SAAS,CAAA;IACZ;;;;;;;;;;;;;;;OAeG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACxE,CAAA"}
package/esm/config/vis.js CHANGED
@@ -19,7 +19,7 @@ export function vis(options = { preset: 'auto' }) {
19
19
  name: undefined,
20
20
  commands,
21
21
  },
22
- setupFiles: preset && preset !== 'none' ? [`vitest-plugin-vis/presets/${preset}`] : [],
22
+ setupFiles: preset && preset !== 'none' && preset !== 'custom' ? [`vitest-plugin-vis/presets/${preset}`] : [],
23
23
  },
24
24
  };
25
25
  },
@@ -1,6 +1,14 @@
1
1
  import type { VisOptions } from '../config/types.ts';
2
2
  import type { PartialBrowserCommandContext } from './vis_server_context.types.ts';
3
3
  export declare function resolveSnapshotRootDir(browserCommandContext: PartialBrowserCommandContext, options: VisOptions): string;
4
- export declare function getSnapshotRootDir(snapshotRootDir: string): string;
4
+ /**
5
+ * Gets the root directory for storing snapshots.
6
+ *
7
+ * @param snapshotRootDir - Base directory for snapshots. Defaults to `__vis__`.
8
+ * @returns The full snapshot root directory path, which includes a platform-specific subdirectory:
9
+ * - When running in CI: `<snapshotRootDir>/<platform>` (e.g. `__vis__/linux`)
10
+ * - When running locally: `<snapshotRootDir>/local`
11
+ */
12
+ export declare function getSnapshotRootDir(snapshotRootDir?: string): string;
5
13
  export declare function getSnapshotSubpath(suiteName: string, options: Pick<VisOptions, 'snapshotSubpath'>): string;
6
14
  //# sourceMappingURL=snapshot_path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot_path.d.ts","sourceRoot":"","sources":["../../src/server/snapshot_path.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAEjF,wBAAgB,sBAAsB,CAAC,qBAAqB,EAAE,4BAA4B,EAAE,OAAO,EAAE,UAAU,UAY9G;AAED,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,UAEzD;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,UAGjG"}
1
+ {"version":3,"file":"snapshot_path.d.ts","sourceRoot":"","sources":["../../src/server/snapshot_path.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAEjF,wBAAgB,sBAAsB,CAAC,qBAAqB,EAAE,4BAA4B,EAAE,OAAO,EAAE,UAAU,UAY9G;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,eAAe,SAAoB,UAErE;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,UAGjG"}
@@ -17,7 +17,15 @@ export function resolveSnapshotRootDir(browserCommandContext, options) {
17
17
  screenshotDirectory: browserCommandContext.provider.options?.screenshotDirectory,
18
18
  });
19
19
  }
20
- export function getSnapshotRootDir(snapshotRootDir) {
20
+ /**
21
+ * Gets the root directory for storing snapshots.
22
+ *
23
+ * @param snapshotRootDir - Base directory for snapshots. Defaults to `__vis__`.
24
+ * @returns The full snapshot root directory path, which includes a platform-specific subdirectory:
25
+ * - When running in CI: `<snapshotRootDir>/<platform>` (e.g. `__vis__/linux`)
26
+ * - When running locally: `<snapshotRootDir>/local`
27
+ */
28
+ export function getSnapshotRootDir(snapshotRootDir = SNAPSHOT_ROOT_DIR) {
21
29
  return `${snapshotRootDir}/${ci ? platform : 'local'}`;
22
30
  }
23
31
  export function getSnapshotSubpath(suiteName, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAA;AAClC,OAAO,yBAAyB,CAAA;AAEhC,cAAc,uBAAuB,CAAA;AAIrC,cAAc,8BAA8B,CAAA"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAA;AAClC,OAAO,yBAAyB,CAAA;AAEhC,cAAc,uBAAuB,CAAA;AAGrC,cAAc,8BAA8B,CAAA"}
package/esm/setup.js CHANGED
@@ -2,6 +2,5 @@
2
2
  import "./client/expect/extend.js";
3
3
  import "./client/page/extend.js";
4
4
  export * from "./client/setup/vis.js";
5
- // This is exported for main/app boundary separation
6
- // They can co-exist in the same export file thanks to ESM.
5
+ // This is deprecated and moved to `/client-api`.
7
6
  export * from "./client/setup/create_vis.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -80,22 +80,31 @@
80
80
  "type-plus": "8.0.0-beta.7"
81
81
  },
82
82
  "devDependencies": {
83
+ "@repobuddy/storybook": "^1.0.0",
83
84
  "@repobuddy/typescript": "^2.1.0",
85
+ "@storybook/addon-docs": "^9.0.4",
86
+ "@storybook/addon-vitest": "^9.0.4",
87
+ "@storybook/react-vite": "^9.0.4",
88
+ "@tailwindcss/vite": "^4.1.7",
84
89
  "@types/is-ci": "^3.0.4",
85
90
  "@types/pngjs": "^6.0.5",
86
91
  "@types/react": "^18.2.65",
87
- "@vitest/browser": "^3.0.9",
88
- "@vitest/coverage-istanbul": "^3.0.9",
89
- "@vitest/coverage-v8": "^3.0.9",
90
- "@vitest/expect": "^3.0.9",
92
+ "@vitest/browser": "^3.1.4",
93
+ "@vitest/coverage-istanbul": "^3.1.4",
94
+ "@vitest/coverage-v8": "^3.1.4",
95
+ "@vitest/expect": "^3.1.4",
91
96
  "cross-env": "^7.0.3",
92
97
  "never-fail": "^1.1.4",
93
98
  "npm-run-all2": "^8.0.0",
94
99
  "react": "^18.2.0",
95
100
  "react-dom": "^18.2.0",
101
+ "storybook": "^9.0.4",
102
+ "storybook-addon-tag-badges": "^2.0.0",
103
+ "storybook-dark-mode2": "^5.0.2",
104
+ "tailwindcss": "^4.1.7",
96
105
  "typescript": "^5.7.2",
97
106
  "vite": "^6.2.3",
98
- "vitest": "^3.0.9",
107
+ "vitest": "^3.1.4",
99
108
  "vitest-browser-react": "^0.2.0"
100
109
  },
101
110
  "peerDependencies": {
@@ -114,6 +123,7 @@
114
123
  "coverage": "cross-env COVERAGE=true vitest run --coverage",
115
124
  "dev": "run-p build:watch w",
116
125
  "nuke": "rimraf node_modules",
126
+ "sb": "storybook dev -p 6007",
117
127
  "t:node": "vitest --project=vpv:node",
118
128
  "t:pw": "vitest run --project=\"vpv:pw (*)\"",
119
129
  "t:wd": "vitest run --project=\"vpv:wd (*)\"",
@@ -0,0 +1,6 @@
1
+ import { Meta, Markdown } from "@storybook/addon-docs/blocks";
2
+ import changelog from "../CHANGELOG.md?raw";
3
+
4
+ <Meta title="Changelog" />
5
+
6
+ <Markdown>{changelog}</Markdown>
@@ -0,0 +1,255 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+ import { setAutoSnapshotOptions } from '../index'
3
+
4
+ <Meta title="vitest-plugin-vis/setAutoSnapshotOptions" />
5
+
6
+ # setAutoSnapshotOptions
7
+
8
+ A function to configure visual snapshot testing options for the current test or test suite.
9
+
10
+ ## Usage
11
+
12
+ You can use `setAutoSnapshotOptions` in `beforeAll`, `beforeEach`, or individual test cases to control snapshot behavior:
13
+
14
+ ```ts
15
+ import { setAutoSnapshotOptions } from 'vitest-plugin-vis'
16
+
17
+ beforeAll(() => {
18
+ setAutoSnapshotOptions(...)
19
+ })
20
+
21
+ beforeEach(() => {
22
+ setAutoSnapshotOptions(...)
23
+ })
24
+
25
+ // Set options for a specific test
26
+ it('...', () => {
27
+ setAutoSnapshotOptions(...)
28
+ })
29
+ ```
30
+
31
+ ## Options
32
+
33
+ The function accepts either a boolean value or an options object with the following properties:
34
+
35
+ ### Basic Control
36
+
37
+ #### `enable` (boolean)
38
+ Controls whether auto snapshots are enabled for the test.
39
+
40
+ ```ts
41
+ // Enable auto snapshots
42
+ setAutoSnapshotOptions({ enable: true })
43
+
44
+ // Disable auto snapshots
45
+ setAutoSnapshotOptions({ enable: false })
46
+
47
+ // Shorthand for enable: true
48
+ setAutoSnapshotOptions(true)
49
+
50
+ // Shorthand for enable: false
51
+ setAutoSnapshotOptions(false)
52
+ ```
53
+
54
+ ### Subject Selection
55
+
56
+ #### `subject` (string)
57
+ Specifies the CSS selector for the element to snapshot. If not provided or element not found, defaults to `document.body`.
58
+
59
+ ```ts
60
+ // Snapshot a specific element
61
+ setAutoSnapshotOptions({
62
+ subject: '[data-testid="main-content"]'
63
+ })
64
+
65
+ // Snapshot by class name
66
+ setAutoSnapshotOptions({
67
+ subject: '.my-component'
68
+ })
69
+
70
+ // Snapshot by ID
71
+ setAutoSnapshotOptions({
72
+ subject: '#app-container'
73
+ })
74
+ ```
75
+
76
+ ### Snapshot Identification
77
+
78
+ #### `snapshotKey` (string)
79
+ Customizes the snapshot key/name for the test.
80
+
81
+ ```ts
82
+ // Custom snapshot key
83
+ setAutoSnapshotOptions({
84
+ snapshotKey: 'my-custom-snapshot'
85
+ })
86
+
87
+ // Dynamic snapshot key based on test data
88
+ setAutoSnapshotOptions({
89
+ snapshotKey: `user-profile-${userId}`
90
+ })
91
+ ```
92
+
93
+ ### Timing Options
94
+
95
+ #### `timeout` (number)
96
+ Sets the timeout for taking the snapshot in milliseconds. Default is 30000ms (30 seconds).
97
+
98
+ ```ts
99
+ // Set custom timeout
100
+ setAutoSnapshotOptions({
101
+ timeout: 60000 // 60 seconds
102
+ })
103
+
104
+ // Quick timeout for fast tests
105
+ setAutoSnapshotOptions({
106
+ timeout: 5000 // 5 seconds
107
+ })
108
+ ```
109
+
110
+ ### Comparison Methods
111
+
112
+ #### `comparisonMethod` ('pixel' | 'ssim')
113
+ Specifies the algorithm used for image comparison.
114
+
115
+ ```ts
116
+ // Use pixel-based comparison (default)
117
+ setAutoSnapshotOptions({
118
+ comparisonMethod: 'pixel'
119
+ })
120
+
121
+ // Use SSIM (Structural Similarity Index) comparison
122
+ setAutoSnapshotOptions({
123
+ comparisonMethod: 'ssim'
124
+ })
125
+ ```
126
+
127
+ ### Failure Thresholds
128
+
129
+ #### `failureThreshold` (number)
130
+ Sets the tolerance level for differences before considering a test failed.
131
+
132
+ ```ts
133
+ // Allow 5% difference
134
+ setAutoSnapshotOptions({
135
+ failureThreshold: 0.05,
136
+ failureThresholdType: 'percent'
137
+ })
138
+
139
+ // Allow 100 different pixels
140
+ setAutoSnapshotOptions({
141
+ failureThreshold: 100,
142
+ failureThresholdType: 'pixel'
143
+ })
144
+ ```
145
+
146
+ #### `failureThresholdType` ('pixel' | 'percent')
147
+ Specifies whether the failure threshold is measured in pixels or percentage. Default is 'pixel'.
148
+
149
+ ```ts
150
+ // Threshold as percentage
151
+ setAutoSnapshotOptions({
152
+ failureThreshold: 2.5,
153
+ failureThresholdType: 'percent'
154
+ })
155
+
156
+ // Threshold as pixel count (default)
157
+ setAutoSnapshotOptions({
158
+ failureThreshold: 50,
159
+ failureThresholdType: 'pixel'
160
+ })
161
+ ```
162
+
163
+ ### Diff Options
164
+
165
+ #### `diffOptions` (object)
166
+ Provides custom options for the comparison algorithm.
167
+
168
+ For pixel comparison (using pixelmatch):
169
+ ```ts
170
+ setAutoSnapshotOptions({
171
+ comparisonMethod: 'pixel',
172
+ diffOptions: {
173
+ threshold: 0.1, // Matching threshold (0-1)
174
+ includeAA: false, // Include anti-aliased pixels
175
+ alpha: 0.1, // Blending factor of unchanged pixels
176
+ aaColor: [255, 255, 0], // Color of anti-aliased pixels
177
+ diffColor: [255, 0, 255] // Color of different pixels
178
+ }
179
+ })
180
+ ```
181
+
182
+ For SSIM comparison:
183
+ ```ts
184
+ setAutoSnapshotOptions({
185
+ comparisonMethod: 'ssim',
186
+ diffOptions: {
187
+ ssim: 'fast', // 'fast', 'original', or 'bezkrovny'
188
+ windowSize: 11, // Window size for SSIM calculation
189
+ k1: 0.01, // Algorithm parameter
190
+ k2: 0.03 // Algorithm parameter
191
+ }
192
+ })
193
+ ```
194
+
195
+ ### Testing Options
196
+
197
+ #### `expectToFail` (boolean)
198
+ Expects the snapshot comparison to fail. Useful for testing error conditions.
199
+
200
+ ```ts
201
+ // Expect this snapshot to fail
202
+ setAutoSnapshotOptions({
203
+ expectToFail: true
204
+ })
205
+ ```
206
+
207
+ ## Complete Examples
208
+
209
+ ### Basic Setup
210
+ ```ts
211
+ beforeEach(() => {
212
+ setAutoSnapshotOptions({
213
+ enable: true,
214
+ subject: '[data-testid="app"]',
215
+ timeout: 10000
216
+ })
217
+ })
218
+ ```
219
+
220
+ ### High-Precision SSIM Comparison
221
+ ```ts
222
+ it('should match with high precision', () => {
223
+ setAutoSnapshotOptions({
224
+ comparisonMethod: 'ssim',
225
+ diffOptions: { ssim: 'bezkrovny' },
226
+ failureThreshold: 0.01,
227
+ failureThresholdType: 'percent'
228
+ })
229
+ })
230
+ ```
231
+
232
+ ### Pixel-Perfect Comparison
233
+ ```ts
234
+ it('should be pixel perfect', () => {
235
+ setAutoSnapshotOptions({
236
+ comparisonMethod: 'pixel',
237
+ diffOptions: { threshold: 0 },
238
+ failureThreshold: 0,
239
+ failureThresholdType: 'pixel'
240
+ })
241
+ })
242
+ ```
243
+
244
+ ### Custom Subject with Tolerance
245
+ ```ts
246
+ it('should snapshot modal with tolerance', () => {
247
+ setAutoSnapshotOptions({
248
+ subject: '[data-testid="modal"]',
249
+ failureThreshold: 5,
250
+ failureThresholdType: 'percent',
251
+ snapshotKey: 'modal-open'
252
+ })
253
+ })
254
+ ```
255
+