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
@@ -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
@@ -0,0 +1,313 @@
1
+ import { Meta, Source } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="config/vis" />
4
+
5
+ # `vis`
6
+
7
+ `vis` from `vitest-plugin-vis/config` is the Vitest plugin of `vitest-plugin-vis`.
8
+
9
+ ```ts
10
+ // vitest.config.ts
11
+ import { vis } from 'vitest-plugin-vis/config'
12
+
13
+ export default defineConfig({
14
+ plugins: [vis()],
15
+ })
16
+ ```
17
+
18
+ It provides a lot of options to customize the behavior of the plugin.
19
+ (You can learn more about the default configuration [here](/docs/overview--docs#basic-configuration).)
20
+
21
+ ## `preset`
22
+
23
+ The `preset` option set up typical visual testing strategies.
24
+
25
+ ### `auto`
26
+
27
+ The `auto` preset is the default preset.
28
+ It will take a snapshot of the page at the end of each rendering test.
29
+
30
+ ```ts
31
+ // vitest.config.ts
32
+ import { vis } from 'vitest-plugin-vis/config'
33
+
34
+ export default defineConfig({
35
+ plugins: [vis({ preset: 'auto' })],
36
+ })
37
+ ```
38
+
39
+ ### `manual`
40
+
41
+ The `manual` preset is for manual testing.
42
+ It will not take any snapshot automatically.
43
+
44
+ ```ts
45
+ // vitest.config.ts
46
+ import { vis } from 'vitest-plugin-vis/config'
47
+
48
+ export default defineConfig({
49
+ plugins: [vis({ preset: 'manual' })],
50
+ })
51
+ ```
52
+
53
+ See [Manual Snapshot](/docs/expect-tomatchimagesnapshot--docs) section on how to take an image snapshot manually.
54
+
55
+ ### `custom`
56
+
57
+ The `custom` preset is for advanced users.
58
+ It will not take any snapshot automatically.
59
+ You need to set up your own visual testing strategy in `vitest.setup.ts`.
60
+
61
+ ```ts
62
+ // vitest.config.ts
63
+ import { vis } from 'vitest-plugin-vis/config'
64
+
65
+ export default defineConfig({
66
+ plugins: [vis({ preset: 'custom' })],
67
+ test: {
68
+ // Set up your own visual testing strategy in `vitest.setup.ts`.
69
+ setupFiles: ['./vitest.setup.ts'],
70
+ }
71
+ })
72
+ ```
73
+
74
+ When using the `custom` preset,
75
+ you need to set up your own visual testing strategy in `vitest.setup.ts` using the [vis](?path=/docs/setup-vis--docs) function from `vitest-plugin-vis/setup`.
76
+
77
+ ## `subject`
78
+
79
+ By default, the snapshot is taken from the `document.body` element.
80
+
81
+ If you establish a common pattern in your tests,
82
+ you can customize the subject to snapshot by setting the `subject` option.
83
+
84
+
85
+ For example, if you enforce a `data-testid` attribute on the element you want to snapshot,
86
+ you can use the `subject` option to specify the selector:
87
+
88
+ ```ts
89
+ // vitest.config.ts
90
+ import { vis } from 'vitest-plugin-vis/config'
91
+
92
+ export default defineConfig({
93
+ plugins: [vis({ subject: '[data-testid="subject"]' })]
94
+ })
95
+ ```
96
+
97
+ ## `snapshotRootDir`
98
+
99
+ By default, the snapshot is saved in the `__vis__` folder relative to the project root.
100
+
101
+ If you want to save the snapshot in a different folder,
102
+ you can set the `snapshotRootDir` option.
103
+
104
+ ```ts
105
+ // vitest.config.ts
106
+ import { vis } from 'vitest-plugin-vis/config'
107
+
108
+ export default defineConfig({
109
+ plugins: [
110
+ vis({
111
+ // save the snapshot in the `<projectRoot>/custom` folder
112
+ snapshotRootDir: 'custom'
113
+ })
114
+ ]
115
+ })
116
+ ```
117
+
118
+ Beside providing a static path,
119
+ you can also provide a function to dynamically determine the snapshot root directory based on the context.
120
+
121
+ The function receives the following context:
122
+
123
+ - `ci`: Whether the code is running in a CI environment
124
+ - `platform`: The platform string (e.g., 'linux', 'darwin', 'win32')
125
+ - `browserName`: The name of the browser (e.g., 'chromium', 'firefox', etc.)
126
+ - `providerName`: The name of the provider (e.g., 'playwright', 'webdriverio', etc.)
127
+ - `screenshotFailures`: Whether the screenshot failures are enabled
128
+ - `screenshotDirectory`: The directory to save the screenshot
129
+
130
+ By default, we provide this function:
131
+
132
+ ```ts
133
+ ({ ci, platform }) => `__vis__/${ci ? platform : 'local'}
134
+ ```
135
+
136
+ ## `snapshotSubpath`
137
+
138
+ Customize the snapshot subpath.
139
+
140
+ By default, we provide this function: `({ subpath }) => trimCommonFolder(subpath)`
141
+
142
+ The `trimCommonFolder` function is also provided if you want to use it in your own custom function.
143
+
144
+ ## `snapshotKey`
145
+
146
+ `snapshotKey` specifies the key of the snapshot.
147
+ In the context of `vis()`, `snapshotKey` is used to specify the key of the auto snapshot.
148
+
149
+ By default, the `snapshotKey` is `auto`.
150
+
151
+ [vitest-plugin-vis]: https://npmjs.org/package/vitest-plugin-vis
152
+
153
+ ## `comparisonMethod`
154
+
155
+ `comparisonMethod` specifies the method of the comparison.
156
+ By default, the `comparisonMethod` is `pixel`.
157
+
158
+ If you want to use the `ssim` method,
159
+ you can set the `comparisonMethod` option.
160
+
161
+ ```ts
162
+ // vitest.config.ts
163
+ import { vis } from 'vitest-plugin-vis/config'
164
+
165
+ export default defineConfig({
166
+ plugins: [vis({ comparisonMethod: 'ssim' })]
167
+ })
168
+ ```
169
+
170
+ ## `diffOptions`
171
+
172
+ `diffOptions` specifies the options of the comparison.
173
+ It accepts different options based on the `comparisonMethod`.
174
+
175
+ ### Pixel Comparison
176
+
177
+ For `pixel` comparison, it accepts the options of `pixelmatch`:
178
+
179
+ ```ts
180
+ // vitest.config.ts
181
+ import { vis } from 'vitest-plugin-vis/config'
182
+
183
+ export default defineConfig({
184
+ plugins: [vis({
185
+ comparisonMethod: 'pixelmatch',
186
+ diffOptions: {
187
+ threshold: 0.1, // Matching threshold (0-1), default: 0.1
188
+ includeAA: false, // Include anti-aliased pixels in comparison
189
+ alpha: 0.1, // Blending factor of unchanged pixels
190
+ aaColor: [255, 255, 0], // Color of anti-aliased pixels in diff
191
+ diffColor: [255, 0, 255] // Color of different pixels in diff
192
+ }
193
+ })],
194
+ })
195
+ ```
196
+
197
+ For option details, please refer to the [pixelmatch documentation](https://github.com/mapbox/pixelmatch?tab=readme-ov-file#pixelmatchimg1-img2-output-width-height-options).
198
+
199
+ ### SSIM Comparison
200
+
201
+ Sometimes pixel-perfect isn't what you need. If you're working with images that have gradients, shadows, or anti-aliasing, SSIM (Structural Similarity Index) might be a better fit.
202
+ It's designed to match how humans actually perceive image differences, which means fewer false positives when minor rendering differences don't actually matter.
203
+ For `ssim` comparison, it accepts the options of `ssim`:
204
+
205
+ ```ts
206
+ // vitest.config.ts
207
+ import { vis } from 'vitest-plugin-vis/config'
208
+
209
+ export default defineConfig({
210
+ plugins: [vis({
211
+ comparisonMethod: 'ssim',
212
+ diffOptions: {
213
+ ssim: 'bezkrovny', // 'bezkrovny' (fast, default) | 'fast' (accurate) | 'weber' | 'original'
214
+ windowSize: 11, // Window size for SSIM calculation (default: 11)
215
+ k1: 0.01, // First stability constant (default: 0.01)
216
+ k2: 0.03, // Second stability constant (default: 0.03)
217
+ bitDepth: 8, // Bits per channel (default: 8)
218
+ downsample: 'original' // 'original' | 'fast' | false
219
+ }
220
+ })],
221
+ })
222
+ ```
223
+
224
+ For option details, please refer to the [ssim documentation](https://github.com/obartra/ssim).
225
+ Note that `ssim.js` repository indicates it is archived.
226
+ If there is any issue with `ssim` comparison,
227
+ it may not be fixed.
228
+
229
+ ## Failure Thresholds
230
+
231
+ Sometimes you want a bit of flexibility in your tests. That's where failure thresholds come in! They let you decide how much difference is acceptable before a test fails.
232
+
233
+ ### Pixel-Based Threshold
234
+
235
+ If you know roughly how many pixels might differ (maybe due to font rendering differences across platforms), you can set a specific pixel count. This is great when you have a good sense of what "acceptable difference" means in pixels.
236
+
237
+ ```ts
238
+ // vitest.config.ts
239
+ import { vis } from 'vitest-plugin-vis/config'
240
+
241
+ export default defineConfig({
242
+ plugins: [vis({
243
+ failureThreshold: 100, // Allow 100 pixels to differ
244
+ failureThresholdType: 'pixel' // Default: 'pixel'
245
+ })],
246
+ })
247
+ ```
248
+
249
+ ### Percentage-Based Threshold
250
+
251
+ Percentage-based thresholds are often more intuitive, especially when you're working with different image sizes. Instead of thinking "100 pixels," you can think "2% of the image," which scales better across different screen sizes and resolutions.
252
+
253
+ ```ts
254
+ // vitest.config.ts
255
+ import { vis } from 'vitest-plugin-vis/config'
256
+
257
+ export default defineConfig({
258
+ plugins: [vis({
259
+ failureThreshold: 0.05, // Allow 5% of pixels to differ
260
+ failureThresholdType: 'percent'
261
+ })],
262
+ })
263
+ ```
264
+
265
+ ### Pixel-Perfect Comparison
266
+
267
+ When you need absolute precision—maybe you're testing critical UI components or want to catch the tiniest visual regressions—pixel-perfect comparison is your go-to. This is the default behavior and ensures that any pixel difference will be caught.
268
+
269
+ ```ts
270
+ // vitest.config.ts
271
+ import { vis } from 'vitest-plugin-vis/config'
272
+
273
+ export default defineConfig({
274
+ plugins: [vis({
275
+ failureThreshold: 0,
276
+ failureThresholdType: 'pixel'
277
+ })],
278
+ })
279
+ ```
280
+
281
+ ## Timeout Configuration
282
+
283
+ Sometimes your tests need a bit more time to render, especially if you're working with complex components or slower environments. You can adjust the timeout to give your tests the breathing room they need.
284
+
285
+ ### Custom Timeout
286
+
287
+ If you find your tests are timing out, or if you're working with particularly complex components that take longer to render, you can increase the timeout. The default is 30 seconds, but feel free to adjust it based on your needs.
288
+
289
+ ```ts
290
+ // vitest.config.ts
291
+ import { vis } from 'vitest-plugin-vis/config'
292
+
293
+ export default defineConfig({
294
+ plugins: [vis({
295
+ timeout: 60000 // 60 seconds (default: 30000ms)
296
+ })],
297
+ })
298
+ ```
299
+
300
+ ### Quick Timeout for Fast Tests
301
+
302
+ On the flip side, if you know your tests are quick and you want faster feedback, you can reduce the timeout. This helps catch issues faster and keeps your test suite snappy!
303
+
304
+ ```ts
305
+ // vitest.config.ts
306
+ import { vis } from 'vitest-plugin-vis/config'
307
+
308
+ export default defineConfig({
309
+ plugins: [vis({
310
+ timeout: 5000 // 5 seconds
311
+ })],
312
+ })
313
+ ```
package/src/index.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  import './client/expect/augment.ts'
3
3
  import './client/page/augment.ts'
4
4
 
5
- export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts'
5
+ export * from './auto_snapshots/auto_snapshot_options.ts'
6
6
  export type * from './shared/types.ts'
package/src/overview.mdx CHANGED
@@ -4,19 +4,28 @@ import { Meta, Markdown } from "@storybook/addon-docs/blocks";
4
4
 
5
5
  # Vitest Visual Testing Plugin
6
6
 
7
- [vitest-plugin-vis] provides visual testing for [Vitest] when running in [Browser Mode][browser-mode].
7
+ [vitest-plugin-vis] provides visual testing for tests running in [Vitest Browser Mode][vitest-browser-mode].
8
8
 
9
- It offers a new unique features:
9
+ Vitest 4 adds [Visual Regression Test][visual-regression-test] support natively.
10
+ You can choose which method to use based on your needs.
10
11
 
11
- - You can capture and compare image snapshot both automatically and manually.
12
- - You can take a snapshot of the whole page or a specific component.
13
- - You can take snapshots in different environments, platform, browser, screen size and themes.
14
- - The snapshots are stored locally in the `__vis__` directory.
15
- - You can enable, disable, and customize how the snapshots are taken and compared.
12
+ Here is a comparison of the features between [Vitest Visual Regression Test][visual-regression-test] and [vitest-plugin-vis].
13
+
14
+ | Feature | [Vitest Visual Regression Test][visual-regression-test] | [vitest-plugin-vis] |
15
+ | ------- | -------------------------------------------------- | ------------------- |
16
+ | Manual snapshot creation | ✅ | ✅ |
17
+ | Automatic snapshot creation | ❌ | ✅ |
18
+ | Multi-theme snapshots | ❌ | ✅ |
19
+ | Comparison methods | `pixel`, `ssim`, custom | `pixel`, `ssim` |
20
+ | Threshold customization | ✅ | ✅ |
21
+ | Fine-grained snapshot variations | ❌ | ✅ |
22
+ | Masking elements | ✅ | 🚧 |
16
23
 
17
24
  ## Install
18
25
 
19
- [vitest-plugin-vis] works with Vitest 2.0.0 or later.
26
+ [vitest-plugin-vis] works with Vitest 2 or later.
27
+
28
+ For Vitest 2 or 3, please use [vitest-plugin-vis] v3.
20
29
 
21
30
  ```sh
22
31
  npm install --save-dev vitest-plugin-vis
@@ -28,7 +37,15 @@ yarn add --save-dev vitest-plugin-vis
28
37
 
29
38
  ## Basic Configuration
30
39
 
31
- To use [vitest-plugin-vis], you need to add it to your Vitest configuration.
40
+ To use [vitest-plugin-vis], you need to:
41
+
42
+ - Add the `vis` plugin to your Vitest configuration.
43
+ - Update `.gitignore` for the snapshot directories.
44
+ - Update your TypeScript configuration to include the `vitest-plugin-vis` type.
45
+
46
+ ### Vitest Configuration
47
+
48
+ The [vitest-plugin-vis] plugin can be used without customization.
32
49
 
33
50
  ```ts
34
51
  // vitest.config.ts
@@ -38,40 +55,27 @@ import { vis } from 'vitest-plugin-vis/config'
38
55
  export default defineConfig({
39
56
  plugins: [vis()],
40
57
  test: {
41
- // vitest v2
42
- browser: {
43
- enabled: true,
44
- provider: 'playwright',
45
- name: 'chromium',
46
- },
47
- // vitest v3
48
- browser: {
49
- enabled: true,
50
- provider: 'playwright',
51
- instances: [
52
- { browser: 'chromium' }
53
- ]
54
- }
58
+ // ... your Vitest Browser Mode configuration ...
55
59
  }
56
60
  })
57
61
  ```
58
62
 
59
63
  This default configuration will:
60
64
 
61
- - Use the `auto` preset, taking image snapshot at the end on each rendering test.
65
+ - Use the [auto preset](?path=/docs/configuration--docs#auto-preset), taking image snapshot at the end on each rendering test.
62
66
  - Use `pixelmatch` as the image comparison method.
63
67
  - Set config to compare image snapshot with a failure threshold of `0 pixels`.
64
68
  - Timeout for image comparison is set to `30000 ms`.
65
69
  - Save image snapshots in the `<project-root>/__vis__` directory.
66
70
 
67
- ## Update .gitignore
71
+ ### Update .gitignore
68
72
 
69
73
  By default, [vitest-plugin-vis] will save image snapshots in the `<project-root>/__vis__` directory.
70
74
 
71
75
  Under this directory, you will find different set of snapshots for different environments:
72
76
 
73
77
  - `local`: For snapshots taken locally.
74
- - `<platform: ubuntu | darwin | win32>`: Fom snapshots taken in respective CI.
78
+ - `<platform: ubuntu | darwin | win32>`: For snapshots taken in respective CI.
75
79
 
76
80
  In each platform directory, there are 3 directories:
77
81
 
@@ -87,6 +91,40 @@ Because of that, you should add the following lines to your `.gitignore` file:
87
91
  **/__vis__/**/__results__
88
92
  ```
89
93
 
90
- [browser-mode]: https://vitest.dev/guide/browser
94
+ ### TypeScript Configuration
95
+
96
+ If you want to do manual snapshot testing, you need to tell TypeScript about the matcher.
97
+
98
+ Add the following to your `tsconfig.json`:
99
+
100
+ ```jsonc
101
+ {
102
+ "compilerOptions": {
103
+ "types": ["vitest-plugin-vis"]
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Advanced Configuration
109
+
110
+ [Vitest Browser Mode][vitest-browser-mode] is a mode that allows you to run tests in a browser environment.
111
+ It has two parts: the Node.js side and the browser side.
112
+
113
+ It runs a worker in Node.js environment and starts a browser instance using provider such as [Playwright][playwright] or [WebDriverIO][webdriverio].
114
+ It then runs the tests in the browser environment and controls the browser instance remotely through the provider.
115
+
116
+ For [vitest-plugin-vis], we run code on the Node.js side to load and save the image snapshots,
117
+ ask the provider to take screenshots,
118
+ and on the browser side we provides API to take snapshots.
119
+
120
+ The Node.js side is configured in your `vitest.config.ts` file,
121
+ while the browser side is configured in your `vitest.setup.ts` file.
122
+
123
+ Please check out the documentation for [Config](?path=/docs/config-vis--docs) and [Setup](?path=/docs/setup-vis--docs) for more details.
124
+
91
125
  [vitest]: https://vitest.dev
92
- [vitest-plugin-vis]: https://npmjs.org/package/vitest-plugin-vis
126
+ [vitest-browser-mode]: https://vitest.dev/guide/browser
127
+ [vitest-plugin-vis]: https://npmjs.org/package/vitest-plugin-vis
128
+ [playwright]: https://playwright.dev/
129
+ [webdriverio]: https://webdriver.io/
130
+ [visual-regression-test]: https://vitest.dev/guide/browser/visual-regression-testing.html
@@ -1,9 +1,11 @@
1
- import type { HasImageSnapshotCommand } from './has_image_snapshot.ts'
2
- import type { ImageSnapshotNextIndexCommand } from './image_snapshot_next_index.ts'
3
- import type { LoadImageSnapshotResultsCommand } from './load_image_snapshot_results.ts'
4
- import type { PrepareImageSnapshotComparisonCommand } from './prepare_image_snapshot_comparison.ts'
5
- import type { PreparePageImageSnapshotComparisonCommand } from './prepare_page_image_snapshot_comparison.ts'
6
- import type { SetupVisSuiteCommand } from './setup_vis_suite.ts'
1
+ import type {
2
+ HasImageSnapshotCommand,
3
+ ImageSnapshotNextIndexCommand,
4
+ LoadImageSnapshotResultsCommand,
5
+ PrepareImageSnapshotComparisonCommand,
6
+ PreparePageImageSnapshotComparisonCommand,
7
+ SetupVisSuiteCommand,
8
+ } from '../../shared/commands.types.ts'
7
9
 
8
10
  declare module 'vitest/browser' {
9
11
  interface BrowserCommands
@@ -1,11 +1,8 @@
1
+ import type { HasImageSnapshotCommand } from '../../shared/commands.types.ts'
1
2
  import { visServerContext } from '../vis_server_context.ts'
2
3
  import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
3
4
  import { assertTestPathDefined } from './_assertions.ts'
4
5
 
5
- export interface HasImageSnapshotCommand {
6
- hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
7
- }
8
-
9
6
  export const hasImageSnapshot: ExtendedBrowserCommand<Parameters<HasImageSnapshotCommand['hasImageSnapshot']>> = async (
10
7
  context,
11
8
  taskId,
@@ -1,14 +1,8 @@
1
+ import type { ImageSnapshotNextIndexCommand } from '../../shared/commands.types.ts'
1
2
  import { visServerContext } from '../vis_server_context.ts'
2
3
  import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
3
4
  import { assertTestPathDefined } from './_assertions.ts'
4
5
 
5
- export interface ImageSnapshotNextIndexCommand {
6
- /**
7
- * Get the index of the snapshot image to be created.
8
- */
9
- imageSnapshotNextIndex(taskId: string): Promise<number>
10
- }
11
-
12
6
  export const imageSnapshotNextIndex: ExtendedBrowserCommand<
13
7
  Parameters<ImageSnapshotNextIndexCommand['imageSnapshotNextIndex']>
14
8
  > = async (context, taskId) => {