vitest-plugin-vis 4.1.0 → 4.2.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.
Files changed (255) hide show
  1. package/dist/auto_snapshots/_ctx.mjs +15 -0
  2. package/dist/auto_snapshots/_ctx.mjs.map +1 -0
  3. package/dist/auto_snapshots/_extract_auto_snapshot_options.mjs +23 -0
  4. package/dist/auto_snapshots/_extract_auto_snapshot_options.mjs.map +1 -0
  5. package/dist/{auto_snapshot_options-BMRtKmod.d.mts → auto_snapshots/auto_snapshot_options.d.mts} +5 -4
  6. package/dist/auto_snapshots/auto_snapshot_options.d.mts.map +1 -0
  7. package/dist/{auto_snapshot_options-DUOTpF2N.mjs → auto_snapshots/auto_snapshot_options.mjs} +6 -40
  8. package/dist/auto_snapshots/auto_snapshot_options.mjs.map +1 -0
  9. package/dist/auto_snapshots/snapshot_meta.d.mts +15 -0
  10. package/dist/auto_snapshots/snapshot_meta.d.mts.map +1 -0
  11. package/dist/client/actions/has_image_snapshot_action.d.mts +8 -0
  12. package/dist/client/actions/has_image_snapshot_action.d.mts.map +1 -0
  13. package/dist/client/actions/has_image_snapshot_action.mjs +9 -0
  14. package/dist/client/actions/has_image_snapshot_action.mjs.map +1 -0
  15. package/dist/client/actions/load_image_snapshot_results_action.d.mts +7 -0
  16. package/dist/client/actions/load_image_snapshot_results_action.d.mts.map +1 -0
  17. package/dist/client/actions/load_image_snapshot_results_action.mjs +8 -0
  18. package/dist/client/actions/load_image_snapshot_results_action.mjs.map +1 -0
  19. package/dist/client/actions/match_image_snapshot_action.d.mts +9 -0
  20. package/dist/client/actions/match_image_snapshot_action.d.mts.map +1 -0
  21. package/dist/client/actions/match_image_snapshot_action.mjs +20 -0
  22. package/dist/client/actions/match_image_snapshot_action.mjs.map +1 -0
  23. package/dist/client/actions/match_page_image_snapshot_action.d.mts +9 -0
  24. package/dist/client/actions/match_page_image_snapshot_action.d.mts.map +1 -0
  25. package/dist/client/actions/match_page_image_snapshot_action.mjs +14 -0
  26. package/dist/client/actions/match_page_image_snapshot_action.mjs.map +1 -0
  27. package/dist/client/expect/_ctx.mjs +15 -0
  28. package/dist/client/expect/_ctx.mjs.map +1 -0
  29. package/dist/client/expect/augment.d.mts +10 -0
  30. package/dist/client/expect/augment.d.mts.map +1 -0
  31. package/dist/client/expect/expectation_result.d.mts +7 -0
  32. package/dist/client/expect/expectation_result.d.mts.map +1 -0
  33. package/dist/client/expect/expectation_result.mjs +9 -0
  34. package/dist/client/expect/expectation_result.mjs.map +1 -0
  35. package/dist/client/expect/extend.d.mts +1 -0
  36. package/dist/client/expect/extend.mjs +9 -0
  37. package/dist/client/expect/extend.mjs.map +1 -0
  38. package/dist/client/expect/to_match_image_snapshot.mjs +16 -0
  39. package/dist/client/expect/to_match_image_snapshot.mjs.map +1 -0
  40. package/dist/{to_match_image_snapshot.types--tTmHoRA.d.mts → client/expect/to_match_image_snapshot.types.d.mts} +3 -3
  41. package/dist/client/expect/to_match_image_snapshot.types.d.mts.map +1 -0
  42. package/dist/client/external/browser/has_render_content.mjs +8 -0
  43. package/dist/client/external/browser/has_render_content.mjs.map +1 -0
  44. package/dist/client/external/browser/image_data.mjs +37 -0
  45. package/dist/client/external/browser/image_data.mjs.map +1 -0
  46. package/dist/client/external/browser/image_resizer.mjs +32 -0
  47. package/dist/client/external/browser/image_resizer.mjs.map +1 -0
  48. package/dist/client/external/browser/selector.mjs +57 -0
  49. package/dist/client/external/browser/selector.mjs.map +1 -0
  50. package/dist/client/external/vitest/vitest_browser_context_proxy.mjs +12 -0
  51. package/dist/client/external/vitest/vitest_browser_context_proxy.mjs.map +1 -0
  52. package/dist/client/external/vitest/vitest_suite_proxy.d.mts +3 -0
  53. package/dist/client/external/vitest/vitest_suite_proxy.mjs +11 -0
  54. package/dist/client/external/vitest/vitest_suite_proxy.mjs.map +1 -0
  55. package/dist/client/image/align_images.mjs +14 -0
  56. package/dist/client/image/align_images.mjs.map +1 -0
  57. package/dist/client/page/_ctx.d.mts +3 -0
  58. package/dist/client/page/_ctx.mjs +15 -0
  59. package/dist/client/page/_ctx.mjs.map +1 -0
  60. package/dist/client/page/augment.d.mts +9 -0
  61. package/dist/client/page/augment.d.mts.map +1 -0
  62. package/dist/client/page/extend.d.mts +1 -0
  63. package/dist/client/page/extend.mjs +13 -0
  64. package/dist/client/page/extend.mjs.map +1 -0
  65. package/dist/client/page/has_image_snapshot.d.mts +13 -0
  66. package/dist/client/page/has_image_snapshot.d.mts.map +1 -0
  67. package/dist/client/page/has_image_snapshot.mjs +15 -0
  68. package/dist/client/page/has_image_snapshot.mjs.map +1 -0
  69. package/dist/client/page/to_match_image_snapshot.d.mts +9 -0
  70. package/dist/client/page/to_match_image_snapshot.d.mts.map +1 -0
  71. package/dist/client/page/to_match_image_snapshot.mjs +15 -0
  72. package/dist/client/page/to_match_image_snapshot.mjs.map +1 -0
  73. package/dist/client/snapshot/compare_image_snapshot.logic.mjs +14 -0
  74. package/dist/client/snapshot/compare_image_snapshot.logic.mjs.map +1 -0
  75. package/dist/client/snapshot/compare_image_snapshot.mjs +63 -0
  76. package/dist/client/snapshot/compare_image_snapshot.mjs.map +1 -0
  77. package/dist/client/snapshot/should_take_snapshot.mjs +10 -0
  78. package/dist/client/snapshot/should_take_snapshot.mjs.map +1 -0
  79. package/dist/client/suite/_ctx.mjs +13 -0
  80. package/dist/client/suite/_ctx.mjs.map +1 -0
  81. package/dist/client/suite/auto_snapshot_matcher.d.mts +12 -0
  82. package/dist/client/suite/auto_snapshot_matcher.d.mts.map +1 -0
  83. package/dist/client/suite/auto_snapshot_matcher.mjs +50 -0
  84. package/dist/client/suite/auto_snapshot_matcher.mjs.map +1 -0
  85. package/dist/client/task/task_id.d.mts +9 -0
  86. package/dist/client/task/task_id.d.mts.map +1 -0
  87. package/dist/client/task/task_id.mjs +15 -0
  88. package/dist/client/task/task_id.mjs.map +1 -0
  89. package/dist/client-api.d.mts +13 -44
  90. package/dist/client-api.mjs +10 -13
  91. package/dist/{types-DJYCbyT8.d.mts → config/types.d.mts} +8 -9
  92. package/dist/config/types.d.mts.map +1 -0
  93. package/dist/config/vis.d.mts +27 -0
  94. package/dist/config/vis.d.mts.map +1 -0
  95. package/dist/config/vis.mjs +31 -0
  96. package/dist/config/vis.mjs.map +1 -0
  97. package/dist/config.d.mts +5 -28
  98. package/dist/config.mjs +3 -411
  99. package/dist/index.d.mts +5 -5
  100. package/dist/index.mjs +1 -4
  101. package/dist/presets/auto.mjs +4 -7
  102. package/dist/presets/auto.mjs.map +1 -1
  103. package/dist/presets/enable.mjs +2 -6
  104. package/dist/presets/enable.mjs.map +1 -1
  105. package/dist/presets/manual.mjs +2 -6
  106. package/dist/presets/manual.mjs.map +1 -1
  107. package/dist/server/browser_provider/browser_api.mjs +13 -0
  108. package/dist/server/browser_provider/browser_api.mjs.map +1 -0
  109. package/dist/server/browser_provider/playwright.mjs +24 -0
  110. package/dist/server/browser_provider/playwright.mjs.map +1 -0
  111. package/dist/server/browser_provider/webdriverio.mjs +16 -0
  112. package/dist/server/browser_provider/webdriverio.mjs.map +1 -0
  113. package/dist/server/commands/_assertions.mjs +10 -0
  114. package/dist/server/commands/_assertions.mjs.map +1 -0
  115. package/dist/server/commands/augment.d.mts +8 -0
  116. package/dist/server/commands/augment.d.mts.map +1 -0
  117. package/dist/server/commands/commands.mjs +20 -0
  118. package/dist/server/commands/commands.mjs.map +1 -0
  119. package/dist/server/commands/has_image_snapshot.mjs +12 -0
  120. package/dist/server/commands/has_image_snapshot.mjs.map +1 -0
  121. package/dist/server/commands/image_snapshot_next_index.mjs +12 -0
  122. package/dist/server/commands/image_snapshot_next_index.mjs.map +1 -0
  123. package/dist/server/commands/load_image_snapshot_results.mjs +12 -0
  124. package/dist/server/commands/load_image_snapshot_results.mjs.map +1 -0
  125. package/dist/server/commands/prepare_image_snapshot_comparison.mjs +37 -0
  126. package/dist/server/commands/prepare_image_snapshot_comparison.mjs.map +1 -0
  127. package/dist/server/commands/prepare_page_image_snapshot_comparison.mjs +27 -0
  128. package/dist/server/commands/prepare_page_image_snapshot_comparison.mjs.map +1 -0
  129. package/dist/server/commands/setup_vis_suite.mjs +12 -0
  130. package/dist/server/commands/setup_vis_suite.mjs.map +1 -0
  131. package/dist/server/externals/file.mjs +23 -0
  132. package/dist/server/externals/file.mjs.map +1 -0
  133. package/dist/server/project.mjs +13 -0
  134. package/dist/server/project.mjs.map +1 -0
  135. package/dist/server/snapshot.mjs +29 -0
  136. package/dist/server/snapshot.mjs.map +1 -0
  137. package/dist/server/snapshot_path.d.mts +17 -0
  138. package/dist/server/snapshot_path.d.mts.map +1 -0
  139. package/dist/{snapshot_path-7GliOSH_.mjs → server/snapshot_path.mjs} +7 -25
  140. package/dist/server/snapshot_path.mjs.map +1 -0
  141. package/dist/server/snapshot_writer.mjs +21 -0
  142. package/dist/server/snapshot_writer.mjs.map +1 -0
  143. package/dist/server/suite.mjs +82 -0
  144. package/dist/server/suite.mjs.map +1 -0
  145. package/dist/server/vis_options.mjs +19 -0
  146. package/dist/server/vis_options.mjs.map +1 -0
  147. package/dist/server/vis_server_context.deps.mjs +16 -0
  148. package/dist/server/vis_server_context.deps.mjs.map +1 -0
  149. package/dist/server/vis_server_context.logic.mjs +82 -0
  150. package/dist/server/vis_server_context.logic.mjs.map +1 -0
  151. package/dist/server/vis_server_context.mjs +8 -0
  152. package/dist/server/vis_server_context.mjs.map +1 -0
  153. package/dist/server/vis_server_context.types.d.mts +2 -0
  154. package/dist/server-utils.d.mts +4 -19
  155. package/dist/server-utils.mjs +3 -2
  156. package/dist/setup/create_vis.d.mts +108 -0
  157. package/dist/setup/create_vis.d.mts.map +1 -0
  158. package/dist/setup/create_vis.mjs +58 -0
  159. package/dist/setup/create_vis.mjs.map +1 -0
  160. package/dist/setup/vis.d.mts +10 -0
  161. package/dist/setup/vis.d.mts.map +1 -0
  162. package/dist/setup/vis.mjs +12 -0
  163. package/dist/setup/vis.mjs.map +1 -0
  164. package/dist/setup-api.d.mts +4 -0
  165. package/dist/setup-api.mjs +5 -0
  166. package/dist/setup.d.mts +8 -101
  167. package/dist/setup.d.mts.map +1 -1
  168. package/dist/setup.mjs +12 -7
  169. package/dist/setup.mjs.map +1 -0
  170. package/dist/{asserts--HSSlgPD.mjs → shared/asserts.mjs} +2 -2
  171. package/dist/shared/asserts.mjs.map +1 -0
  172. package/dist/{base64-CHSENEAO.mjs → shared/base64.mjs} +2 -2
  173. package/dist/shared/base64.mjs.map +1 -0
  174. package/dist/{commands.types-BVhcnnHw.d.mts → shared/commands.types.d.mts} +6 -6
  175. package/dist/shared/commands.types.d.mts.map +1 -0
  176. package/dist/shared/compare_image.mjs +46 -0
  177. package/dist/shared/compare_image.mjs.map +1 -0
  178. package/dist/shared/constants.d.mts +9 -0
  179. package/dist/shared/constants.d.mts.map +1 -0
  180. package/dist/{constants-CTBaz8Ml.mjs → shared/constants.mjs} +2 -2
  181. package/dist/shared/constants.mjs.map +1 -0
  182. package/dist/shared/convert_threshold_unit.mjs +12 -0
  183. package/dist/shared/convert_threshold_unit.mjs.map +1 -0
  184. package/dist/shared/get_max_size.mjs +11 -0
  185. package/dist/shared/get_max_size.mjs.map +1 -0
  186. package/dist/shared/is_same_size.mjs +8 -0
  187. package/dist/shared/is_same_size.mjs.map +1 -0
  188. package/dist/{trim_common_folder-DBThLerp.d.mts → shared/trim_common_folder.d.mts} +2 -2
  189. package/dist/shared/trim_common_folder.d.mts.map +1 -0
  190. package/dist/shared/trim_common_folder.mjs +23 -0
  191. package/dist/shared/trim_common_folder.mjs.map +1 -0
  192. package/dist/{types-CEmjj-A9.d.mts → shared/types.d.mts} +6 -21
  193. package/dist/shared/types.d.mts.map +1 -0
  194. package/dist/testing/constants.d.mts +12 -0
  195. package/dist/testing/constants.d.mts.map +1 -0
  196. package/dist/testing/constants.mjs +65550 -0
  197. package/dist/{testing.mjs.map → testing/constants.mjs.map} +1 -1
  198. package/dist/testing.d.mts +2 -12
  199. package/dist/testing.mjs +2 -65549
  200. package/package.json +24 -17
  201. package/readme.md +48 -3
  202. package/src/{client/task → auto_snapshots}/_ctx.ts +1 -1
  203. package/src/auto_snapshots/_extract_auto_snapshot_options.ts +26 -0
  204. package/src/{client/task → auto_snapshots}/auto_snapshot_options.mdx +1 -2
  205. package/src/{client/task → auto_snapshots}/auto_snapshot_options.ts +3 -25
  206. package/src/{client/task → auto_snapshots}/snapshot_meta.ts +1 -1
  207. package/src/client/actions/match_image_snapshot_action.ts +0 -2
  208. package/src/client/snapshot/compare_image_snapshot.logic.ts +1 -1
  209. package/src/client/snapshot/compare_image_snapshot.ts +15 -1
  210. package/src/client/snapshot/should_take_snapshot.ts +1 -1
  211. package/src/client/suite/auto_snapshot_matcher.ts +2 -3
  212. package/src/client-api.ts +1 -1
  213. package/src/config/overview.mdx +145 -0
  214. package/src/{shared → config}/trim_common_folder.mdx +1 -1
  215. package/src/config/types.ts +5 -6
  216. package/src/config/vis.mdx +313 -0
  217. package/src/index.ts +1 -1
  218. package/src/overview.mdx +66 -28
  219. package/src/server/commands/prepare_image_snapshot_comparison.ts +8 -8
  220. package/src/server/commands/prepare_page_image_snapshot_comparison.ts +1 -6
  221. package/src/server/snapshot_path.ts +3 -1
  222. package/src/{setup.create_vis.mdx → setup/create_vis.mdx} +4 -5
  223. package/src/setup/create_vis.ts +12 -7
  224. package/src/setup/overview.mdx +17 -0
  225. package/src/setup/readme.md +3 -1
  226. package/src/{setup.vis.mdx → setup/vis.mdx} +15 -18
  227. package/src/setup-api.ts +5 -0
  228. package/src/setup.ts +8 -4
  229. package/src/shared/commands.types.ts +2 -2
  230. package/src/shared/types.ts +3 -2
  231. package/dist/asserts--HSSlgPD.mjs.map +0 -1
  232. package/dist/augment-C1tjdh5B.d.mts +0 -33
  233. package/dist/augment-C1tjdh5B.d.mts.map +0 -1
  234. package/dist/auto_snapshot_matcher-C0y6mAeS.mjs +0 -381
  235. package/dist/auto_snapshot_matcher-C0y6mAeS.mjs.map +0 -1
  236. package/dist/auto_snapshot_options-BMRtKmod.d.mts.map +0 -1
  237. package/dist/auto_snapshot_options-DUOTpF2N.mjs.map +0 -1
  238. package/dist/base64-CHSENEAO.mjs.map +0 -1
  239. package/dist/client-api.d.mts.map +0 -1
  240. package/dist/client-api.mjs.map +0 -1
  241. package/dist/commands.types-BVhcnnHw.d.mts.map +0 -1
  242. package/dist/config.d.mts.map +0 -1
  243. package/dist/config.mjs.map +0 -1
  244. package/dist/constants-CTBaz8Ml.mjs.map +0 -1
  245. package/dist/server-utils.d.mts.map +0 -1
  246. package/dist/setup-DCytWz48.mjs +0 -124
  247. package/dist/setup-DCytWz48.mjs.map +0 -1
  248. package/dist/snapshot_path-7GliOSH_.mjs.map +0 -1
  249. package/dist/src-CSQnlFa9.mjs +0 -1
  250. package/dist/testing.d.mts.map +0 -1
  251. package/dist/to_match_image_snapshot.types--tTmHoRA.d.mts.map +0 -1
  252. package/dist/trim_common_folder-DBThLerp.d.mts.map +0 -1
  253. package/dist/types-CEmjj-A9.d.mts.map +0 -1
  254. package/dist/types-DJYCbyT8.d.mts.map +0 -1
  255. package/src/config.vis.mdx +0 -76
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -20,6 +20,8 @@
20
20
  },
21
21
  "type": "module",
22
22
  "imports": {
23
+ "#vitest-plugin-vis": "./src/index.ts",
24
+ "#vitest-plugin-vis/client-api": "./src/client-api.ts",
23
25
  "#vitest-plugin-vis/config": "./src/config.ts",
24
26
  "#vitest-plugin-vis/setup": "./src/setup.ts"
25
27
  },
@@ -56,6 +58,10 @@
56
58
  "types": "./dist/setup.d.mts",
57
59
  "default": "./dist/setup.mjs"
58
60
  },
61
+ "./setup-api": {
62
+ "types": "./dist/setup-api.d.mts",
63
+ "default": "./dist/setup-api.mjs"
64
+ },
59
65
  "./testing": {
60
66
  "types": "./dist/testing.d.mts",
61
67
  "default": "./dist/testing.mjs"
@@ -78,38 +84,39 @@
78
84
  "pngjs": "^7.0.0",
79
85
  "rimraf": "^6.0.1",
80
86
  "ssim.js": "^3.5.0",
81
- "type-plus": "8.0.0-beta.7"
87
+ "type-plus": "8.0.0-beta.8"
82
88
  },
83
89
  "devDependencies": {
84
90
  "@repobuddy/storybook": "^2.1.2",
85
91
  "@repobuddy/typescript": "^2.1.0",
86
- "@storybook-community/storybook-dark-mode": "^7.0.3",
87
- "@storybook/addon-docs": "^10.2.0-alpha.1",
88
- "@storybook/addon-vitest": "^10.2.0-alpha.1",
89
- "@storybook/react-vite": "^10.2.0-alpha.1",
92
+ "@storybook-community/storybook-dark-mode": "^7.1.0",
93
+ "@storybook/addon-docs": "^10.1.10",
94
+ "@storybook/addon-mdx-gfm": "^8.6.14",
95
+ "@storybook/addon-vitest": "^10.1.10",
96
+ "@storybook/react-vite": "^10.1.10",
90
97
  "@tailwindcss/vite": "^4.1.14",
91
98
  "@types/is-ci": "^3.0.4",
92
99
  "@types/pngjs": "^6.0.5",
93
100
  "@types/react": "^19.2.2",
94
- "@vitest/browser": "^4.0.9",
95
- "@vitest/browser-playwright": "^4.0.9",
96
- "@vitest/browser-webdriverio": "^4.0.9",
97
- "@vitest/coverage-istanbul": "^4.0.9",
98
- "@vitest/coverage-v8": "^4.0.9",
99
- "@vitest/expect": "^4.0.9",
100
- "@vitest/ui": "4.0.9",
101
+ "@vitest/browser": "^4.0.16",
102
+ "@vitest/browser-playwright": "^4.0.16",
103
+ "@vitest/browser-webdriverio": "^4.0.16",
104
+ "@vitest/coverage-istanbul": "^4.0.16",
105
+ "@vitest/coverage-v8": "^4.0.16",
106
+ "@vitest/expect": "^4.0.16",
107
+ "@vitest/ui": "^4.0.16",
101
108
  "cross-env": "^10.0.0",
102
109
  "never-fail": "^1.1.4",
103
110
  "npm-run-all2": "^8.0.0",
104
111
  "react": "^19.0.0",
105
112
  "react-dom": "^19.0.0",
106
- "storybook": "^10.2.0-alpha.1",
113
+ "storybook": "^10.1.10",
107
114
  "storybook-addon-tag-badges": "^3.0.2",
108
115
  "tailwindcss": "^4.1.14",
109
- "tsdown": "^0.16.6",
116
+ "tsdown": "^0.19.0",
110
117
  "typescript": "^5.9.3",
111
- "vite": "^7.1.12",
112
- "vitest": "^4.0.9",
118
+ "vite": "^7.3.0",
119
+ "vitest": "^4.0.16",
113
120
  "vitest-browser-react": "^2.0.2"
114
121
  },
115
122
  "peerDependencies": {
package/readme.md CHANGED
@@ -179,12 +179,12 @@ you can use `snapshotSubpath` to customize the snapshot sub-path to avoid confli
179
179
 
180
180
  ```ts
181
181
  // vitest.config.ts
182
- import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
182
+ import { vis } from 'vitest-plugin-vis/config'
183
183
  import { defineConfig } from 'vitest/config'
184
184
 
185
185
  export default defineConfig({
186
186
  plugins: [
187
- storybookVis({
187
+ vis({
188
188
  // keep the folder structure
189
189
  snapshotSubpath: (subpath) => subpath
190
190
  })
@@ -245,12 +245,14 @@ export default defineConfig({
245
245
  vis({
246
246
  snapshotRootDir: ({
247
247
  ci, // true if running on CI
248
+ rootDir, // base directory for snapshots (default: '__vis__')
248
249
  platform, // process.platform
249
250
  providerName, // 'playwright' or 'webdriverio'
250
251
  browserName, // 'chromium', 'firefox', etc.
252
+ projectName, // instance name when using multiple browser instances
251
253
  screenshotFailures, // from `browser` config
252
254
  screenshotDirectory, // from `browser` config
253
- }) => `__vis__/${ci ? platform : 'local'}`,
255
+ }) => `${rootDir}/${ci ? platform : 'local'}`,
254
256
  snapshotSubpath: ({ subpath }) => trimCommonFolder(subpath),
255
257
  // Alphanumeric characters, and underscore are allowed. Dash is not allowed.
256
258
  snapshotKey: 'auto',
@@ -259,6 +261,49 @@ export default defineConfig({
259
261
  })
260
262
  ```
261
263
 
264
+ #### Multiple browser instances
265
+
266
+ When using multiple browser instances (e.g., different viewports or browsers),
267
+ each instance runs the same tests and would overwrite snapshots if they shared the same directory.
268
+ Use `projectName` in `snapshotRootDir` to separate snapshots per instance:
269
+
270
+ ```ts
271
+ // vitest.config.ts
272
+ import { defineConfig } from 'vitest/config'
273
+ import { playwright } from '@vitest/browser-playwright'
274
+ import { vis } from 'vitest-plugin-vis/config'
275
+
276
+ export default defineConfig({
277
+ plugins: [
278
+ vis({
279
+ snapshotRootDir({ ci, rootDir, projectName, platform }) {
280
+ return `${rootDir}/${ci ? platform : 'local'}/${projectName}`
281
+ },
282
+ }),
283
+ ],
284
+ test: {
285
+ browser: {
286
+ enabled: true,
287
+ provider: playwright(),
288
+ instances: [
289
+ { browser: 'chromium', name: 'HD', viewport: { width: 1280, height: 720 } },
290
+ { browser: 'chromium', name: 'SVGA', viewport: { width: 800, height: 600 } },
291
+ ],
292
+ },
293
+ },
294
+ })
295
+ ```
296
+
297
+ With this configuration, snapshots are stored in separate directories per instance:
298
+
299
+ ```sh
300
+ __vis__/local/HD/__baselines__/...
301
+ __vis__/local/SVGA/__baselines__/...
302
+ ```
303
+
304
+ On CI, the `projectName` corresponds to the `name` of each instance.
305
+ See [vitest.config.playwright.ts](vitest.config.playwright.ts) for a full example.
306
+
262
307
  ### Customizing auto snapshot subject
263
308
 
264
309
  By default, auto snapshots are taken from the `document.body` element.
@@ -1,4 +1,4 @@
1
- import { getCurrentSuite, getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
1
+ import { getCurrentSuite, getCurrentTest } from '../client/external/vitest/vitest_suite_proxy.ts'
2
2
 
3
3
  export const ctx = {
4
4
  getCurrentTest,
@@ -0,0 +1,26 @@
1
+ import { NAME } from '../client-api.ts'
2
+ import type { MetaTask } from './auto_snapshot_options.ts'
3
+ import type { SnapshotMeta } from './snapshot_meta.ts'
4
+
5
+ export function extractAutoSnapshotOptions<M extends SnapshotMeta<any> = SnapshotMeta<any>>(
6
+ task: MetaTask,
7
+ ): M | undefined {
8
+ if (!task) return
9
+
10
+ const list: any[] = []
11
+ let current = task
12
+ while (current?.suite) {
13
+ list.unshift(current.suite.meta)
14
+ current = current.suite
15
+ }
16
+ list.unshift(task.file?.meta)
17
+ list.push(task.meta)
18
+ return list.reduce(
19
+ (acc, cur) => {
20
+ const meta = cur?.[NAME]
21
+ // biome-ignore lint/performance/noAccumulatingSpread: I think this is needed
22
+ return meta ? Object.assign({}, acc, meta) : acc
23
+ },
24
+ { enable: false },
25
+ )
26
+ }
@@ -1,7 +1,6 @@
1
1
  import { Meta } from "@storybook/addon-docs/blocks";
2
- import { setAutoSnapshotOptions } from '../index'
3
2
 
4
- <Meta title="vitest-plugin-vis/setAutoSnapshotOptions" />
3
+ <Meta title="auto snapshots/setAutoSnapshotOptions" />
5
4
 
6
5
  # setAutoSnapshotOptions
7
6
 
@@ -1,6 +1,6 @@
1
- import { assertSnapshotKeyWithoutDash } from '../../shared/asserts.ts'
2
- import { NAME } from '../../shared/constants.ts'
3
- import type { ComparisonMethod } from '../../shared/types.ts'
1
+ import { assertSnapshotKeyWithoutDash } from '../shared/asserts.ts'
2
+ import { NAME } from '../shared/constants.ts'
3
+ import type { ComparisonMethod } from '../shared/types.ts'
4
4
  import { ctx } from './_ctx.ts'
5
5
  import type { SnapshotMeta } from './snapshot_meta.ts'
6
6
 
@@ -62,25 +62,3 @@ function getTask(): MetaTask | undefined {
62
62
  function parseMeta<M extends ComparisonMethod>(meta: boolean | SnapshotMeta<M>): SnapshotMeta<M> {
63
63
  return typeof meta === 'boolean' ? ({ enable: meta } as any) : { enable: true, ...meta }
64
64
  }
65
-
66
- export function extractAutoSnapshotOptions<M extends SnapshotMeta<any> = SnapshotMeta<any>>(
67
- task: MetaTask,
68
- ): M | undefined {
69
- if (!task) return
70
-
71
- const list: any[] = []
72
- let current = task
73
- while (current?.suite) {
74
- list.unshift(current.suite.meta)
75
- current = current.suite
76
- }
77
- list.unshift(task.file?.meta)
78
- list.push(task.meta)
79
- return list.reduce(
80
- (acc, cur) => {
81
- const meta = cur?.[NAME]
82
- return meta ? Object.assign({}, acc, meta) : acc
83
- },
84
- { enable: false },
85
- )
86
- }
@@ -1,4 +1,4 @@
1
- import type { ComparisonMethod, ImageSnapshotSubjectOptions, ToMatchImageSnapshotOptions } from '../../shared/types.ts'
1
+ import type { ComparisonMethod, ImageSnapshotSubjectOptions, ToMatchImageSnapshotOptions } from '../shared/types.ts'
2
2
 
3
3
  export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> &
4
4
  ImageSnapshotSubjectOptions & {
@@ -19,8 +19,6 @@ export async function matchImageSnapshotAction(
19
19
 
20
20
  const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options)
21
21
 
22
- if (!info) return
23
-
24
22
  return compareImageSnapshot(commands, taskId, info, options)
25
23
  }
26
24
 
@@ -10,5 +10,5 @@ export function prettifyOptions(options: ToMatchImageSnapshotOptions<any> | unde
10
10
  options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
11
11
  ]
12
12
  .filter(Boolean)
13
- .join('\n ')
13
+ .join('\n ')
14
14
  }
@@ -20,8 +20,22 @@ export async function compareImageSnapshot(
20
20
  ) {
21
21
  options = { ...info, ...options } as any
22
22
 
23
- const baselineImage = await toImageData(info.baseline)
24
23
  const resultImage = await toImageData(info.result)
24
+
25
+ if (!info.baseline) {
26
+ if (server.config.snapshotOptions.updateSnapshot === 'all') {
27
+ await writeSnapshot(commands, resolve(info.projectRoot, info.baselinePath), resultImage)
28
+ return
29
+ }
30
+ throw new Error(
31
+ dedent`Snapshot \`${taskId}\` has no baseline image. Please review the new snapshot and update the baseline image.
32
+
33
+ Options: ${prettifyOptions(options)}
34
+ Actual: ${resolve(info.projectRoot, info.resultPath)}`,
35
+ )
36
+ }
37
+
38
+ const baselineImage = await toImageData(info.baseline)
25
39
  const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage)
26
40
  const { width, height } = baselineAlignedImage
27
41
  const diffImage = new ImageData(width, height)
@@ -1,5 +1,5 @@
1
+ import type { SnapshotMeta } from '../../auto_snapshots/snapshot_meta.ts'
1
2
  import { hasRenderContent } from '../external/browser/has_render_content.ts'
2
- import type { SnapshotMeta } from '../task/snapshot_meta.ts'
3
3
 
4
4
  export function shouldTakeSnapshot(meta: SnapshotMeta<any> | undefined) {
5
5
  return hasRenderContent() && meta?.enable
@@ -1,9 +1,9 @@
1
1
  import dedent from 'dedent'
2
+ import { extractAutoSnapshotOptions } from '../../auto_snapshots/_extract_auto_snapshot_options.ts'
3
+ import type { SnapshotMeta } from '../../auto_snapshots/snapshot_meta.ts'
2
4
  import type { SetupVisSuiteCommand } from '../../shared/commands.types.ts'
3
5
  import type { ComparisonMethod } from '../../shared/types.ts'
4
6
  import { shouldTakeSnapshot } from '../snapshot/should_take_snapshot.ts'
5
- import { extractAutoSnapshotOptions } from '../task/auto_snapshot_options.ts'
6
- import type { SnapshotMeta } from '../task/snapshot_meta.ts'
7
7
  import { toTaskId } from '../task/task_id.ts'
8
8
  import { ctx } from './_ctx.ts'
9
9
 
@@ -25,7 +25,6 @@ export function autoSnapshotMatcher<GM extends Record<string, any> | unknown = u
25
25
  ) {
26
26
  return async function matchImageSnapshot() {
27
27
  const test = ctx.getCurrentTest()
28
- if ((test?.result?.errors?.length ?? 0) > 0) return
29
28
 
30
29
  const meta = extractAutoSnapshotOptions(test)
31
30
  if (!shouldTakeSnapshot(meta)) return
package/src/client-api.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import './server/commands/augment.ts'
2
2
 
3
+ export * from './auto_snapshots/auto_snapshot_options.ts'
3
4
  export * from './client/actions/has_image_snapshot_action.ts'
4
5
  export * from './client/actions/load_image_snapshot_results_action.ts'
5
6
  export * from './client/actions/match_image_snapshot_action.ts'
@@ -7,7 +8,6 @@ export * from './client/actions/match_page_image_snapshot_action.ts'
7
8
  export * from './client/expect/expectation_result.ts'
8
9
  export type * from './client/expect/to_match_image_snapshot.types.ts'
9
10
  export * from './client/suite/auto_snapshot_matcher.ts'
10
- export { setAutoSnapshotOptions, type MetaTask } from './client/task/auto_snapshot_options.ts'
11
11
  export * from './client/task/task_id.ts'
12
12
  export * from './shared/constants.ts'
13
13
  export type * from './shared/types.ts'
@@ -0,0 +1,145 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="config" />
4
+
5
+ # Overview
6
+
7
+ Configuration refers to configuring the plugin in your `vitest.config.ts` file.
8
+
9
+ You can configure the plugin by passing options to the `vis` function from `vitest-plugin-vis/config`.
10
+
11
+ ```ts
12
+ // vitest.config.ts
13
+ import { vis } from 'vitest-plugin-vis/config'
14
+
15
+ export default defineConfig({
16
+ plugins: [vis()],
17
+ })
18
+ ```
19
+
20
+ ## Customizing snapshot path
21
+
22
+ Let's say you have this test:
23
+
24
+ ```ts
25
+ // src/components/MyComponent.spec.tsx
26
+
27
+ describe('MyComponent', () => {
28
+ describe('className', () => {
29
+ it('can customize className', () => {
30
+ // ...
31
+ })
32
+ })
33
+ })
34
+ ```
35
+
36
+ By default, when you run the test locally,the image snapshot will be saved in the following path:
37
+
38
+ ```sh
39
+ __vis__/local/__baselines__/components/MyComponent.spec.tsx/MyComponent/className/can-customize-className-auto.png
40
+ ```
41
+
42
+ This path can be broken down into a few parts:
43
+
44
+ > `__vis__/local`: `snapshotRootDir`
45
+
46
+ This is the `snapshotRootDir` where the image snapshots folders are placed.
47
+ When running on CI, the `snapshotRootDir` is default to `__vis__/<process.platform>`.
48
+
49
+ > `__baselines__`: baseline folder
50
+
51
+ This is the folder where the baseline images are saved and used for comparison.
52
+ There is also a `__results__` folder where the current test run images are saved,
53
+ and a `__diffs__` folder where the diff images are saved if the comparison fails.
54
+
55
+ > `components/MyComponent.spec.tsx`: `snapshotSubpath`
56
+
57
+ This is part of the path based on the path of the test file relative to the project root.
58
+ By default, the plugin will trim the common folder such as `src` or `test` from the path to reduce the path length.
59
+
60
+ If you place your test files in multiple folders,
61
+ such as in both `tests` and `src` folders,
62
+ and they might have files with the same name and create conflicting snapshots,
63
+ you can use `snapshotSubpath` to customize the snapshot sub-path to avoid conflicts.
64
+
65
+ ```ts
66
+ // vitest.config.ts
67
+ import { vis } from 'vitest-plugin-vis/config'
68
+ import { defineConfig } from 'vitest/config'
69
+
70
+ export default defineConfig({
71
+ plugins: [
72
+ vis({
73
+ // keep the folder structure
74
+ snapshotSubpath: (subpath) => subpath
75
+ })
76
+ ],
77
+ // ...
78
+ })
79
+ ```
80
+
81
+ With the above configuration, the snapshot folder structure will look like this:
82
+
83
+ ```ini
84
+ v __vis__
85
+ > # ...
86
+ v local # snapshot generated on local machine
87
+ > __baselines__
88
+ v examples
89
+ v button.stories.tsx
90
+ snapshot-1.png
91
+ snapshot-2.png
92
+ v src
93
+ v button.stories.tsx
94
+ snapshot-1.png
95
+ snapshot-2.png
96
+ v tests
97
+ v button.stories.tsx
98
+ snapshot-1.png
99
+ snapshot-2.png
100
+ v examples
101
+ button.stories.tsx
102
+ v src
103
+ button.stories.tsx
104
+ v tests
105
+ button.stories.tsx
106
+ ```
107
+
108
+ > `MyComponent/className/can-customize-className`: `snapshotId`
109
+
110
+ This is the ID of the snapshot based on the test name and scope.
111
+ This is not customizable.
112
+
113
+ > `auto`: `snapshotKey`
114
+
115
+ This is the key of the snapshot.
116
+ In this case, it is `auto` because the snapshot is taken automatically at the end of the test.
117
+ If you take a manual snapshot, the key will be `0`, `1`, etc.
118
+ If you customize it when taking the snapshot,
119
+ the global customization will not be used.
120
+
121
+ You can customize the `snapshotRootDir`, `snapshotSubpath`, and `snapshotKey` with corresponding options:
122
+
123
+ ```ts
124
+ // vitest.config.ts
125
+ import { defineConfig } from 'vitest/config'
126
+ import { vis, trimCommonFolder } from 'vitest-plugin-vis/config'
127
+
128
+ export default defineConfig({
129
+ plugins: [
130
+ vis({
131
+ snapshotRootDir: ({
132
+ ci, // true if running on CI
133
+ platform, // process.platform
134
+ providerName, // 'playwright' or 'webdriverio'
135
+ browserName, // 'chromium', 'firefox', etc.
136
+ screenshotFailures, // from `browser` config
137
+ screenshotDirectory, // from `browser` config
138
+ }) => `__vis__/${ci ? platform : 'local'}`,
139
+ snapshotSubpath: ({ subpath }) => trimCommonFolder(subpath),
140
+ // Alphanumeric characters, and underscore are allowed. Dash is not allowed.
141
+ snapshotKey: 'auto',
142
+ })
143
+ ]
144
+ })
145
+ ```
@@ -1,6 +1,6 @@
1
1
  import { Meta, Source } from "@storybook/addon-docs/blocks";
2
2
 
3
- <Meta title="vitest-plugin-vis/config/trimCommonFolder" />
3
+ <Meta title="config/trimCommonFolder" />
4
4
 
5
5
  # trimCommonFolder
6
6
 
@@ -34,23 +34,22 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim'
34
34
  /**
35
35
  * Loads the `test.setupFiles` of the specified preset.
36
36
  *
37
- * Note:
38
- * - 'enable` is deprecated. Use `manual` for the same effect.
39
- * - 'none` is deprecated. Use `custom` for the same effect.
40
- *
41
37
  * @default 'auto'
42
- *
38
+ * @deprecated 'enable' is deprecated. Use `manual` for the same effect.
39
+ * @deprecated 'none' is deprecated. Use `custom` for the same effect.
43
40
  */
44
41
  preset?: 'enable' | 'manual' | 'auto' | 'custom' | 'none' | undefined
45
42
  /**
46
43
  * The snapshot folder relative to the root of the project.
47
44
  *
48
- * Default: `{projectRoot}/__vis__/{platform}`
45
+ * @default "({ ci, platform }) => `__vis__/${ci ? platform : 'local'}`"
49
46
  */
50
47
  snapshotRootDir?:
51
48
  | string
52
49
  | ((context: {
53
50
  ci: boolean
51
+ rootDir: string
52
+ projectName?: string | undefined
54
53
  browserName?: string | undefined
55
54
  providerName: string
56
55
  platform: string