vitest-plugin-vis 4.0.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 (285) 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-CaQCXDdi.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-CAD43Zkp.mjs → auto_snapshots/auto_snapshot_options.mjs} +6 -42
  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-p-zilA_M.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 -141
  90. package/dist/client-api.mjs +10 -13
  91. package/dist/{types-Do1N7g4c.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 -105
  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/shared/commands.types.d.mts +51 -0
  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-ModiubEJ.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-DFb23VE1.d.mts → shared/types.d.mts} +39 -20
  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/ctx.ts → auto_snapshots/_ctx.ts} +1 -3
  203. package/src/auto_snapshots/_extract_auto_snapshot_options.ts +26 -0
  204. package/src/{client → auto_snapshots}/auto_snapshot_options.mdx +1 -2
  205. package/src/{client → auto_snapshots}/auto_snapshot_options.ts +1 -23
  206. package/src/client/actions/has_image_snapshot_action.ts +1 -1
  207. package/src/client/actions/load_image_snapshot_results_action.ts +1 -1
  208. package/src/client/actions/match_image_snapshot_action.ts +6 -6
  209. package/src/client/actions/match_page_image_snapshot_action.ts +5 -3
  210. package/src/client/expect/_ctx.ts +10 -0
  211. package/src/client/expect/to_match_image_snapshot.ts +3 -4
  212. package/src/client/external/browser/has_render_content.ts +3 -0
  213. package/src/client/{image_resizer.ts → external/browser/image_resizer.ts} +1 -1
  214. package/src/client/{vitest_suite_proxy.ts → external/vitest/vitest_suite_proxy.ts} +1 -1
  215. package/src/client/{align_images.ts → image/align_images.ts} +3 -3
  216. package/src/client/page/_ctx.ts +12 -0
  217. package/src/client/page/has_image_snapshot.ts +4 -4
  218. package/src/client/page/to_match_image_snapshot.ts +3 -4
  219. package/src/client/{compare_image_snapshot.logic.ts → snapshot/compare_image_snapshot.logic.ts} +2 -2
  220. package/src/client/{compare_image_snapshot.ts → snapshot/compare_image_snapshot.ts} +23 -10
  221. package/src/client/snapshot/should_take_snapshot.ts +6 -0
  222. package/src/client/suite/_ctx.ts +8 -0
  223. package/src/client/suite/auto_snapshot_matcher.ts +67 -0
  224. package/src/client-api.ts +3 -2
  225. package/src/config/overview.mdx +145 -0
  226. package/src/{shared → config}/trim_common_folder.mdx +1 -1
  227. package/src/config/types.ts +5 -6
  228. package/src/config/vis.mdx +313 -0
  229. package/src/index.ts +1 -1
  230. package/src/overview.mdx +66 -28
  231. package/src/server/commands/augment.ts +8 -6
  232. package/src/server/commands/has_image_snapshot.ts +1 -4
  233. package/src/server/commands/image_snapshot_next_index.ts +1 -7
  234. package/src/server/commands/load_image_snapshot_results.ts +1 -20
  235. package/src/server/commands/prepare_image_snapshot_comparison.ts +10 -56
  236. package/src/server/commands/prepare_page_image_snapshot_comparison.ts +2 -49
  237. package/src/server/commands/setup_vis_suite.ts +0 -24
  238. package/src/server/snapshot_path.ts +3 -1
  239. package/src/server/vis_server_context.logic.ts +1 -1
  240. package/src/{setup.create_vis.mdx → setup/create_vis.mdx} +4 -5
  241. package/src/{client/setup → setup}/create_vis.ts +31 -83
  242. package/src/setup/overview.mdx +17 -0
  243. package/src/setup/readme.md +7 -0
  244. package/src/{setup.vis.mdx → setup/vis.mdx} +15 -18
  245. package/src/setup-api.ts +5 -0
  246. package/src/setup.ts +9 -5
  247. package/src/shared/commands.types.ts +71 -0
  248. package/src/shared/types.ts +54 -1
  249. package/dist/asserts--HSSlgPD.mjs.map +0 -1
  250. package/dist/augment-BJmy1S7i.d.mts +0 -31
  251. package/dist/augment-BJmy1S7i.d.mts.map +0 -1
  252. package/dist/auto_snapshot_options-CAD43Zkp.mjs.map +0 -1
  253. package/dist/auto_snapshot_options-CaQCXDdi.d.mts.map +0 -1
  254. package/dist/base64-CHSENEAO.mjs.map +0 -1
  255. package/dist/client-api.d.mts.map +0 -1
  256. package/dist/client-api.mjs.map +0 -1
  257. package/dist/config.d.mts.map +0 -1
  258. package/dist/config.mjs.map +0 -1
  259. package/dist/constants-CTBaz8Ml.mjs.map +0 -1
  260. package/dist/server-utils.d.mts.map +0 -1
  261. package/dist/setup-BWgIDtv-.mjs +0 -141
  262. package/dist/setup-BWgIDtv-.mjs.map +0 -1
  263. package/dist/setup_vis_suite-C6JGGT7B.d.mts +0 -17
  264. package/dist/setup_vis_suite-C6JGGT7B.d.mts.map +0 -1
  265. package/dist/snapshot_path-7GliOSH_.mjs.map +0 -1
  266. package/dist/src-CSQnlFa9.mjs +0 -1
  267. package/dist/task_id-DnS9_4Ub.mjs +0 -316
  268. package/dist/task_id-DnS9_4Ub.mjs.map +0 -1
  269. package/dist/testing.d.mts.map +0 -1
  270. package/dist/to_match_image_snapshot.types-p-zilA_M.d.mts.map +0 -1
  271. package/dist/trim_common_folder-ModiubEJ.d.mts.map +0 -1
  272. package/dist/types-DFb23VE1.d.mts.map +0 -1
  273. package/dist/types-Do1N7g4c.d.mts.map +0 -1
  274. package/dist/vis_server_context.types-Ce1f9vOO.d.mts +0 -1
  275. package/src/client/image_snapshot_options.ts +0 -6
  276. package/src/client/setup/vis.ctx.ts +0 -34
  277. package/src/client/should_take_snapshot.ts +0 -5
  278. package/src/config.vis.mdx +0 -76
  279. package/src/server/commands/types.ts +0 -9
  280. /package/src/{client → auto_snapshots}/snapshot_meta.ts +0 -0
  281. /package/src/client/{image_data.ts → external/browser/image_data.ts} +0 -0
  282. /package/src/client/{selector.ts → external/browser/selector.ts} +0 -0
  283. /package/src/client/{vitest_browser_context_proxy.ts → external/vitest/vitest_browser_context_proxy.ts} +0 -0
  284. /package/src/client/{task_id.ts → task/task_id.ts} +0 -0
  285. /package/src/{client/setup → setup}/vis.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "4.0.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.1.2",
88
- "@storybook/addon-vitest": "^10.1.2",
89
- "@storybook/react-vite": "^10.1.2",
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.1.2",
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,12 +1,10 @@
1
- import { getCurrentSuite, getCurrentTest } from './vitest_suite_proxy.ts'
1
+ import { getCurrentSuite, getCurrentTest } from '../client/external/vitest/vitest_suite_proxy.ts'
2
2
 
3
3
  export const ctx = {
4
- autoEnabled: undefined as boolean | undefined,
5
4
  getCurrentTest,
6
5
  getCurrentSuite,
7
6
  __test__reset() {
8
7
  ctx.getCurrentTest = getCurrentTest
9
8
  ctx.getCurrentSuite = getCurrentSuite
10
- ctx.autoEnabled = undefined
11
9
  },
12
10
  }
@@ -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,7 +1,7 @@
1
1
  import { assertSnapshotKeyWithoutDash } from '../shared/asserts.ts'
2
2
  import { NAME } from '../shared/constants.ts'
3
3
  import type { ComparisonMethod } from '../shared/types.ts'
4
- import { ctx } from './ctx.ts'
4
+ import { ctx } from './_ctx.ts'
5
5
  import type { SnapshotMeta } from './snapshot_meta.ts'
6
6
 
7
7
  type Suite = { meta: Record<string, any>; suite?: Suite | undefined }
@@ -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 { HasImageSnapshotCommand, ImageSnapshotNextIndexCommand } from '../../commands.ts'
1
+ import type { HasImageSnapshotCommand, ImageSnapshotNextIndexCommand } from '../../shared/commands.types.ts'
2
2
  import type { ImageSnapshotKeyOptions } from '../../shared/types.ts'
3
3
 
4
4
  export function hasImageSnapshotAction(
@@ -1,4 +1,4 @@
1
- import type { LoadImageSnapshotResultsCommand } from '../../server/commands/load_image_snapshot_results.ts'
1
+ import type { LoadImageSnapshotResultsCommand } from '../../shared/commands.types.ts'
2
2
 
3
3
  export function loadImageSnapshotResultsAction(commands: LoadImageSnapshotResultsCommand, taskId: string) {
4
4
  return commands.loadImageSnapshotResults(taskId)
@@ -1,11 +1,13 @@
1
1
  import type { BrowserCommands } from 'vitest/browser'
2
- import type { ImageSnapshotNextIndexCommand } from '../../commands.ts'
3
- import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts'
4
2
  import { assertSnapshotKeyWithoutDash } from '../../shared/asserts.ts'
5
3
  import { isBase64String } from '../../shared/base64.ts'
4
+ import type {
5
+ ImageSnapshotNextIndexCommand,
6
+ PrepareImageSnapshotComparisonCommand,
7
+ } from '../../shared/commands.types.ts'
6
8
  import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'
7
- import { compareImageSnapshot } from '../compare_image_snapshot.ts'
8
- import { convertElementToCssSelector } from '../selector.ts'
9
+ import { convertElementToCssSelector } from '../external/browser/selector.ts'
10
+ import { compareImageSnapshot } from '../snapshot/compare_image_snapshot.ts'
9
11
 
10
12
  export async function matchImageSnapshotAction(
11
13
  commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
@@ -17,8 +19,6 @@ export async function matchImageSnapshotAction(
17
19
 
18
20
  const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options)
19
21
 
20
- if (!info) return
21
-
22
22
  return compareImageSnapshot(commands, taskId, info, options)
23
23
  }
24
24
 
@@ -1,9 +1,11 @@
1
1
  import type { BrowserCommands } from 'vitest/browser'
2
- import type { ImageSnapshotNextIndexCommand } from '../../commands.ts'
3
- import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts'
4
2
  import { assertSnapshotKeyWithoutDash } from '../../shared/asserts.ts'
3
+ import type {
4
+ ImageSnapshotNextIndexCommand,
5
+ PrepareImageSnapshotComparisonCommand,
6
+ } from '../../shared/commands.types.ts'
5
7
  import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'
6
- import { compareImageSnapshot } from '../compare_image_snapshot.ts'
8
+ import { compareImageSnapshot } from '../snapshot/compare_image_snapshot.ts'
7
9
 
8
10
  export async function matchPageImageSnapshotAction(
9
11
  commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
@@ -0,0 +1,10 @@
1
+ import { commands } from 'vitest/browser'
2
+ import { getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
3
+
4
+ export const ctx = {
5
+ commands,
6
+ getCurrentTest,
7
+ __test__reset() {
8
+ ctx.getCurrentTest = getCurrentTest
9
+ },
10
+ }
@@ -1,9 +1,8 @@
1
- import { commands } from 'vitest/browser'
2
1
  import type { AsyncExpectationResult } from '@vitest/expect'
3
2
  import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'
4
3
  import { matchImageSnapshotAction } from '../actions/match_image_snapshot_action.ts'
5
- import { ctx } from '../ctx.ts'
6
- import { toTaskId } from '../task_id.ts'
4
+ import { toTaskId } from '../task/task_id.ts'
5
+ import { ctx } from './_ctx.ts'
7
6
  import { success } from './expectation_result.ts'
8
7
 
9
8
  export function toMatchImageSnapshot(
@@ -26,5 +25,5 @@ export function toMatchImageSnapshot(
26
25
  )
27
26
  }
28
27
 
29
- return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)
28
+ return matchImageSnapshotAction(ctx.commands, toTaskId(test), subject, options).then(() => success)
30
29
  }
@@ -0,0 +1,3 @@
1
+ export function hasRenderContent() {
2
+ return document.body.childElementCount > 0
3
+ }
@@ -1,4 +1,4 @@
1
- import { isSameSize } from '../shared/is_same_size.ts'
1
+ import { isSameSize } from '../../../shared/is_same_size.ts'
2
2
 
3
3
  export const createImageResizer =
4
4
  ({ width, height }: { width: number; height: number }) =>
@@ -1,4 +1,4 @@
1
- import type { SnapshotTestMeta } from '../shared/types.ts'
1
+ import type { SnapshotTestMeta } from '../../../shared/types.ts'
2
2
 
3
3
  let vitestSuite: Awaited<typeof import('vitest/suite')>
4
4
 
@@ -1,6 +1,6 @@
1
- import { getMaxSize } from '../shared/get_max_size.ts'
2
- import { isSameSize } from '../shared/is_same_size.ts'
3
- import { createImageResizer } from './image_resizer.ts'
1
+ import { getMaxSize } from '../../shared/get_max_size.ts'
2
+ import { isSameSize } from '../../shared/is_same_size.ts'
3
+ import { createImageResizer } from '../external/browser/image_resizer.ts'
4
4
 
5
5
  export function alignImagesToSameSize(image1: ImageData, image2: ImageData): [image1: ImageData, image2: ImageData] {
6
6
  if (isSameSize(image1, image2)) return [image1, image2] as const
@@ -0,0 +1,12 @@
1
+ import { type BrowserPage, commands } from 'vitest/browser'
2
+ import { getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
3
+
4
+ export type { BrowserPage }
5
+
6
+ export const ctx = {
7
+ commands,
8
+ getCurrentTest,
9
+ __test__reset() {
10
+ ctx.getCurrentTest = getCurrentTest
11
+ },
12
+ }
@@ -1,8 +1,8 @@
1
- import { type BrowserPage, commands } from 'vitest/browser'
2
1
  import type { ImageSnapshotKeyOptions } from '../../shared/types.ts'
3
2
  import { hasImageSnapshotAction } from '../actions/has_image_snapshot_action.ts'
4
- import { ctx } from '../ctx.ts'
5
- import { toTaskId } from '../task_id.ts'
3
+ import { toTaskId } from '../task/task_id.ts'
4
+ import type { BrowserPage } from './_ctx.ts'
5
+ import { ctx } from './_ctx.ts'
6
6
 
7
7
  export interface HasImageSnapshotAction {
8
8
  /**
@@ -23,5 +23,5 @@ export function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOp
23
23
  "concurrent tests run at the same time in the same iframe and affect each other's environment. ",
24
24
  )
25
25
  }
26
- return hasImageSnapshotAction(commands, toTaskId(test), options)
26
+ return hasImageSnapshotAction(ctx.commands, toTaskId(test), options)
27
27
  }
@@ -1,8 +1,7 @@
1
- import { commands } from 'vitest/browser'
2
1
  import type { ComparisonMethod, ToMatchPageImageSnapshotOptions } from '../../shared/types.ts'
3
2
  import { matchPageImageSnapshotAction } from '../actions/match_page_image_snapshot_action.ts'
4
- import { ctx } from '../ctx.ts'
5
- import { toTaskId } from '../task_id.ts'
3
+ import { toTaskId } from '../task/task_id.ts'
4
+ import { ctx } from './_ctx.ts'
6
5
 
7
6
  export interface ToMatchImageSnapshotAction {
8
7
  toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(
@@ -25,5 +24,5 @@ export function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(
25
24
  )
26
25
  }
27
26
 
28
- return matchPageImageSnapshotAction(commands, toTaskId(test), options)
27
+ return matchPageImageSnapshotAction(ctx.commands, toTaskId(test), options)
29
28
  }
@@ -1,4 +1,4 @@
1
- import type { ToMatchImageSnapshotOptions } from '../shared/types.ts'
1
+ import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'
2
2
 
3
3
  export function prettifyOptions(options: ToMatchImageSnapshotOptions<any> | undefined) {
4
4
  if (!options) return 'none'
@@ -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
  }
@@ -1,17 +1,16 @@
1
- import type { BrowserCommands } from 'vitest/browser'
2
1
  import dedent from 'dedent'
3
2
  import { resolve } from 'pathe'
4
- import type { ImageSnapshotNextIndexCommand } from '../commands.ts'
3
+ import type { BrowserCommands } from 'vitest/browser'
5
4
  import type {
6
- ImageSnapshotComparisonInfo,
5
+ ImageSnapshotNextIndexCommand,
7
6
  PrepareImageSnapshotComparisonCommand,
8
- } from '../server/commands/prepare_image_snapshot_comparison.ts'
9
- import { compareImage } from '../shared/compare_image.ts'
10
- import type { ToMatchImageSnapshotOptions } from '../shared/types.ts'
11
- import { alignImagesToSameSize } from './align_images.ts'
7
+ } from '../../shared/commands.types.ts'
8
+ import { compareImage } from '../../shared/compare_image.ts'
9
+ import type { ImageSnapshotComparisonInfo, ToMatchImageSnapshotOptions } from '../../shared/types.ts'
10
+ import { toDataURL, toImageData } from '../external/browser/image_data.ts'
11
+ import { server } from '../external/vitest/vitest_browser_context_proxy.ts'
12
+ import { alignImagesToSameSize } from '../image/align_images.ts'
12
13
  import { prettifyOptions } from './compare_image_snapshot.logic.ts'
13
- import { toDataURL, toImageData } from './image_data.ts'
14
- import { server } from './vitest_browser_context_proxy.ts'
15
14
 
16
15
  export async function compareImageSnapshot(
17
16
  commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
@@ -21,8 +20,22 @@ export async function compareImageSnapshot(
21
20
  ) {
22
21
  options = { ...info, ...options } as any
23
22
 
24
- const baselineImage = await toImageData(info.baseline)
25
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)
26
39
  const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage)
27
40
  const { width, height } = baselineAlignedImage
28
41
  const diffImage = new ImageData(width, height)
@@ -0,0 +1,6 @@
1
+ import type { SnapshotMeta } from '../../auto_snapshots/snapshot_meta.ts'
2
+ import { hasRenderContent } from '../external/browser/has_render_content.ts'
3
+
4
+ export function shouldTakeSnapshot(meta: SnapshotMeta<any> | undefined) {
5
+ return hasRenderContent() && meta?.enable
6
+ }
@@ -0,0 +1,8 @@
1
+ import { getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
2
+
3
+ export const ctx = {
4
+ getCurrentTest,
5
+ __test__reset() {
6
+ ctx.getCurrentTest = getCurrentTest
7
+ },
8
+ }
@@ -0,0 +1,67 @@
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'
4
+ import type { SetupVisSuiteCommand } from '../../shared/commands.types.ts'
5
+ import type { ComparisonMethod } from '../../shared/types.ts'
6
+ import { shouldTakeSnapshot } from '../snapshot/should_take_snapshot.ts'
7
+ import { toTaskId } from '../task/task_id.ts'
8
+ import { ctx } from './_ctx.ts'
9
+
10
+ export function autoSnapshotMatcher<GM extends Record<string, any> | unknown = unknown>(
11
+ commands: SetupVisSuiteCommand,
12
+ expect: any,
13
+ ) {
14
+ let subject: string | undefined
15
+
16
+ return {
17
+ async setup() {
18
+ subject = (await commands.setupVisSuite()).subject
19
+ },
20
+ createMatcher<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
21
+ themes: Record<
22
+ string,
23
+ boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)
24
+ >,
25
+ ) {
26
+ return async function matchImageSnapshot() {
27
+ const test = ctx.getCurrentTest()
28
+
29
+ const meta = extractAutoSnapshotOptions(test)
30
+ if (!shouldTakeSnapshot(meta)) return
31
+ const errors: Array<[string, Error]> = []
32
+ for (const themeId in themes) {
33
+ try {
34
+ await new Promise((a) => setTimeout(a, 10))
35
+ const theme = themes[themeId]
36
+ const r = typeof theme === 'function' ? await theme(meta! as any) : theme
37
+ if (r === false) continue
38
+ await expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
39
+ ...meta,
40
+ snapshotKey: meta?.snapshotKey ?? themeId,
41
+ })
42
+ } catch (error) {
43
+ errors.push([themeId, error as Error])
44
+ }
45
+ }
46
+ if (errors.length > 0) {
47
+ if (errors.length === 1) throw errors[0]![1]
48
+ const taskId = toTaskId(test!)
49
+ throw new AggregateError(
50
+ errors,
51
+ dedent`Snapshot \`${taskId}\` mismatched
52
+
53
+ ${errors
54
+ .map(([themeId, error]) => {
55
+ return `Theme \`${themeId}\` failed: ${error.message}`
56
+ })
57
+ .join('\n\n')}`,
58
+ )
59
+ }
60
+ }
61
+ },
62
+ }
63
+ }
64
+
65
+ function getSubject(selectors: string | undefined) {
66
+ return selectors ? (document.querySelector(selectors) ?? document.body) : document.body
67
+ }
package/src/client-api.ts CHANGED
@@ -1,12 +1,13 @@
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'
6
7
  export * from './client/actions/match_page_image_snapshot_action.ts'
7
- export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts'
8
8
  export * from './client/expect/expectation_result.ts'
9
9
  export type * from './client/expect/to_match_image_snapshot.types.ts'
10
- export * from './client/task_id.ts'
10
+ export * from './client/suite/auto_snapshot_matcher.ts'
11
+ export * from './client/task/task_id.ts'
11
12
  export * from './shared/constants.ts'
12
13
  export type * from './shared/types.ts'