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
@@ -1,27 +1,8 @@
1
+ import type { ImageSnapshotResult } 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 ImageSnapshotResult {
6
- filename: string
7
- /**
8
- * The base64 encoded image of the baseline snapshot.
9
- */
10
- baseline?: string | undefined
11
- /**
12
- * The base64 encoded image of the result snapshot.
13
- */
14
- result?: string | undefined
15
- /**
16
- * The base64 encoded image of the diff snapshot.
17
- */
18
- diff?: string | undefined
19
- }
20
-
21
- export interface LoadImageSnapshotResultsCommand {
22
- loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
23
- }
24
-
25
6
  export const loadImageSnapshotResults: ExtendedBrowserCommand<[taskId: string]> = async (
26
7
  context,
27
8
  taskId,
@@ -1,60 +1,14 @@
1
1
  import { resolve } from 'pathe'
2
2
  import { isBase64String } from '../../shared/base64.ts'
3
- import type {
4
- FailureThresholdOptions,
5
- ImageSnapshotTimeoutOptions,
6
- PixelComparisonOptions,
7
- SsimComparisonOptions,
8
- } from '../../shared/types.ts'
3
+ import type { PrepareImageSnapshotComparisonCommand } from '../../shared/commands.types.ts'
4
+ import type { ImageSnapshotComparisonInfo } from '../../shared/types.ts'
9
5
  import { file } from '../externals/file.ts'
10
6
  import { getProjectRoot } from '../project.ts'
11
- import { takeSnapshot, takeSnapshotByBrowser } from '../snapshot.ts'
7
+ import { takeSnapshot } from '../snapshot.ts'
12
8
  import { snapshotWriter } from '../snapshot_writer.ts'
13
9
  import { visServerContext } from '../vis_server_context.ts'
14
10
  import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
15
11
  import { assertTestPathDefined } from './_assertions.ts'
16
- import type { MatchImageSnapshotOptions } from './types.ts'
17
-
18
- export type ImageSnapshotComparisonInfo = {
19
- /**
20
- * Path to the project root.
21
- */
22
- projectRoot: string
23
- /**
24
- * Path to the baseline image relative to the project root.
25
- */
26
- baselinePath: string
27
- /**
28
- * Path to the result image relative to the project root.
29
- */
30
- resultPath: string
31
- /**
32
- * Path to the diff image relative to the project root.
33
- */
34
- diffPath: string
35
- /**
36
- * Base64 encoded baseline image.
37
- */
38
- baseline: string
39
- /**
40
- * Base64 encoded result image.
41
- */
42
- result: string
43
- /**
44
- * Base64 encoded diff image.
45
- */
46
- diff?: string | undefined
47
- } & ImageSnapshotTimeoutOptions &
48
- FailureThresholdOptions &
49
- (SsimComparisonOptions | PixelComparisonOptions)
50
-
51
- export interface PrepareImageSnapshotComparisonCommand {
52
- prepareImageSnapshotComparison: (
53
- taskId: string,
54
- subject: string,
55
- options?: MatchImageSnapshotOptions | undefined,
56
- ) => Promise<ImageSnapshotComparisonInfo | undefined>
57
- }
58
12
 
59
13
  export const prepareImageSnapshotComparison: ExtendedBrowserCommand<
60
14
  Parameters<PrepareImageSnapshotComparisonCommand['prepareImageSnapshotComparison']>
@@ -68,20 +22,20 @@ export const prepareImageSnapshotComparison: ExtendedBrowserCommand<
68
22
  const info = await visServerContext.getSnapshotInfo(context, taskId, options)
69
23
 
70
24
  const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))
71
- if (!baselineBuffer) {
72
- if (isBase64String(subject)) {
73
- await snapshotWriter.writeBase64(resolve(projectRoot, info.baselinePath), subject)
74
- } else {
75
- await takeSnapshotByBrowser(context, projectRoot, info.baselinePath, subject, options)
25
+ if (!baselineBuffer && isBase64String(subject)) {
26
+ await snapshotWriter.writeBase64(resolve(projectRoot, info.resultPath), subject)
27
+ return {
28
+ ...info,
29
+ projectRoot,
30
+ result: subject,
76
31
  }
77
- return
78
32
  }
79
33
 
80
34
  const resultBuffer = await takeSnapshot(context, projectRoot, info.resultPath, subject, options)
81
35
  return {
82
36
  ...info,
83
37
  projectRoot,
84
- baseline: baselineBuffer.toString('base64'),
38
+ baseline: baselineBuffer?.toString('base64'),
85
39
  result: resultBuffer.toString('base64'),
86
40
  }
87
41
  }
@@ -1,53 +1,11 @@
1
1
  import { resolve } from 'pathe'
2
- import type {
3
- FailureThresholdOptions,
4
- ImageSnapshotTimeoutOptions,
5
- PixelComparisonOptions,
6
- SsimComparisonOptions,
7
- } from '../../shared/types.ts'
2
+ import type { PreparePageImageSnapshotComparisonCommand } from '../../shared/commands.types.ts'
8
3
  import { file } from '../externals/file.ts'
9
4
  import { getProjectRoot } from '../project.ts'
10
5
  import { takePageSnapshot } from '../snapshot.ts'
11
6
  import { visServerContext } from '../vis_server_context.ts'
12
7
  import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
13
8
  import { assertTestPathDefined } from './_assertions.ts'
14
- import type { MatchImageSnapshotOptions } from './types.ts'
15
-
16
- type ImageSnapshotComparisonInfo = {
17
- /**
18
- * Path to the project root.
19
- */
20
- projectRoot: string
21
- /**
22
- * Path to the baseline image relative to the project root.
23
- */
24
- baselinePath: string
25
- /**
26
- * Path to the result image relative to the project root.
27
- */
28
- resultPath: string
29
- /**
30
- * Path to the diff image relative to the project root.
31
- */
32
- diffPath: string
33
- /**
34
- * Base64 encoded baseline image.
35
- */
36
- baseline: string
37
- /**
38
- * Base64 encoded result image.
39
- */
40
- result: string
41
- } & ImageSnapshotTimeoutOptions &
42
- FailureThresholdOptions &
43
- (SsimComparisonOptions | PixelComparisonOptions)
44
-
45
- export interface PreparePageImageSnapshotComparisonCommand {
46
- preparePageImageSnapshotComparison: (
47
- taskId: string,
48
- options?: MatchImageSnapshotOptions | undefined,
49
- ) => Promise<ImageSnapshotComparisonInfo | undefined>
50
- }
51
9
 
52
10
  export const preparePageImageSnapshotComparison: ExtendedBrowserCommand<
53
11
  Parameters<PreparePageImageSnapshotComparisonCommand['preparePageImageSnapshotComparison']>
@@ -60,16 +18,11 @@ export const preparePageImageSnapshotComparison: ExtendedBrowserCommand<
60
18
  const projectRoot = getProjectRoot(context)
61
19
  const info = await visServerContext.getSnapshotInfo(context, taskId, options)
62
20
  const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))
63
- if (!baselineBuffer) {
64
- await takePageSnapshot(context, projectRoot, info.baselinePath, options)
65
- return
66
- }
67
-
68
21
  const resultBuffer = await takePageSnapshot(context, projectRoot, info.resultPath, options)
69
22
  return {
70
23
  ...info,
71
24
  projectRoot,
72
- baseline: baselineBuffer.toString('base64'),
25
+ baseline: baselineBuffer?.toString('base64'),
73
26
  result: resultBuffer.toString('base64'),
74
27
  }
75
28
  }
@@ -1,31 +1,7 @@
1
- import type { Pick } from 'type-plus'
2
- import type { VisOptions } from '../../config/types.ts'
3
1
  import { setupSuite } from '../suite.ts'
4
2
  import type { ExtendedBrowserCommand, ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
5
3
  import { assertTestPathDefined } from './_assertions.ts'
6
4
 
7
- export interface SetupVisSuiteCommand {
8
- /**
9
- * Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
10
- * When this command is run for the first time,
11
- * it will remove the results and diffs directory of all suites.
12
- *
13
- * In subsequent runs, it will only remove the results and diffs directory of the current suite.
14
- */
15
- setupVisSuite: () => Promise<
16
- Pick<
17
- VisOptions,
18
- | 'comparisonMethod'
19
- | 'diffOptions'
20
- | 'failureThreshold'
21
- | 'failureThresholdType'
22
- | 'snapshotKey'
23
- | 'subject'
24
- | 'timeout'
25
- >
26
- >
27
- }
28
-
29
5
  export const setupVisSuite: ExtendedBrowserCommand<[]> = async (context): Promise<{ subject: string | undefined }> => {
30
6
  assertTestPathDefined(context, 'setupVisSuite')
31
7
  return setupSuite(context as unknown as ExtendedBrowserCommandContext)
@@ -6,12 +6,14 @@ import { trimCommonFolder } from '../shared/trim_common_folder.ts'
6
6
  import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
7
7
 
8
8
  export function resolveSnapshotRootDir(browserCommandContext: ExtendedBrowserCommandContext, options: VisOptions) {
9
- if (!options.snapshotRootDir) return getSnapshotRootDir(SNAPSHOT_ROOT_DIR)
9
+ if (!options.snapshotRootDir) return getSnapshotRootDir()
10
10
  const snapshotRootDir = options.snapshotRootDir
11
11
  if (typeof snapshotRootDir === 'string') return getSnapshotRootDir(snapshotRootDir)
12
12
  const { config } = browserCommandContext.project.browser
13
13
  return snapshotRootDir({
14
14
  ci,
15
+ rootDir: SNAPSHOT_ROOT_DIR,
16
+ projectName: browserCommandContext.project.name,
15
17
  browserName: config.browser.name,
16
18
  providerName: browserCommandContext.provider.name,
17
19
  platform,
@@ -1,7 +1,7 @@
1
1
  import { basename, join, resolve } from 'pathe'
2
2
  import { pick } from 'type-plus'
3
3
  import type { ImageSnapshotKeyOptions } from '../client-api.ts'
4
- import type { ImageSnapshotResult } from './commands/load_image_snapshot_results.ts'
4
+ import type { ImageSnapshotResult } from '../shared/commands.types.ts'
5
5
  import { file } from './externals/file.ts'
6
6
  import { getSuite, getTaskSubpath } from './suite.ts'
7
7
  import { getVisOption } from './vis_options.ts'
@@ -1,12 +1,11 @@
1
1
  import { Meta, Markdown ,Canvas} from "@storybook/addon-docs/blocks";
2
2
 
3
- <Meta
4
- tags={['deprecated']}
5
- title="vitest-plugin-vis/setup/createVis"
6
- />
3
+ <Meta title="setup/createVis" tags={['deprecated']} />
4
+
5
+ # `createVis`
7
6
 
8
7
  🪦 Deprecated
9
8
 
10
9
  `createVis` in `vitest-plugin-vis/setup` is deprecated.
11
10
 
12
- It is moved to `/client-api`.
11
+ It is moved to `vitest-plugin-vis/setup-api`.
@@ -1,27 +1,9 @@
1
- import dedent from 'dedent'
2
- import { afterEach, beforeAll } from 'vitest'
3
- import type { SetupVisSuiteCommand } from '../../server/commands/setup_vis_suite.ts'
4
- import type { ComparisonMethod } from '../../shared/types.ts'
5
- import { extractAutoSnapshotOptions, setAutoSnapshotOptions } from '../auto_snapshot_options.ts'
6
- import { ctx } from '../ctx.ts'
7
- import { shouldTakeSnapshot } from '../should_take_snapshot.ts'
8
- import type { SnapshotMeta } from '../snapshot_meta.ts'
9
- import { toTaskId } from '../task_id.ts'
10
-
11
- export type SetupVisOptions<GM extends Record<string, any> | unknown = unknown> = {
12
- auto?:
13
- | boolean
14
- | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
15
- options: SnapshotMeta<C> & M & GM,
16
- ) => Promise<boolean> | Promise<void> | boolean | void)
17
- | Record<
18
- string,
19
- | boolean
20
- | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
21
- options: SnapshotMeta<C> & M & GM,
22
- ) => Promise<boolean> | Promise<void> | boolean | void)
23
- >
24
- }
1
+ import { afterEach, beforeAll, expect } from 'vitest'
2
+ import { setAutoSnapshotOptions } from '../auto_snapshots/auto_snapshot_options.ts'
3
+ import type { SnapshotMeta } from '../auto_snapshots/snapshot_meta.ts'
4
+ import { autoSnapshotMatcher } from '../client/suite/auto_snapshot_matcher.ts'
5
+ import type { SetupVisSuiteCommand } from '../shared/commands.types.ts'
6
+ import type { ComparisonMethod, SetupVisOptions } from '../shared/types.ts'
25
7
 
26
8
  /**
27
9
  * Visual test configuration on the client side.
@@ -110,10 +92,19 @@ export type VisClientConfigurator<GM extends Record<string, any> | unknown = unk
110
92
  ): void
111
93
  }
112
94
  beforeAll: {
95
+ /**
96
+ * @deprecated No known use case.
97
+ */
113
98
  setup(): Promise<void>
114
99
  }
115
100
  afterEach: {
101
+ /**
102
+ * @deprecated No known use case.
103
+ */
116
104
  matchImageSnapshot(): Promise<void>
105
+ /**
106
+ * @deprecated No known use case.
107
+ */
117
108
  matchPerTheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
118
109
  themes: Record<
119
110
  string,
@@ -124,106 +115,63 @@ export type VisClientConfigurator<GM extends Record<string, any> | unknown = unk
124
115
  }
125
116
 
126
117
  export function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand) {
127
- let subject: string | undefined
118
+ const matcher = autoSnapshotMatcher(commands, expect)
128
119
 
129
120
  const vis: VisClientConfigurator<GM> = {
130
121
  setup(options) {
131
122
  if (!options || options.auto === false) {
132
- beforeAll(vis.beforeAll.setup)
123
+ beforeAll(matcher.setup)
133
124
  } else {
134
125
  beforeAll(async () => {
135
- await vis.beforeAll.setup()
126
+ await matcher.setup()
136
127
  setAutoSnapshotOptions(true)
137
128
  })
138
129
  }
139
130
 
140
131
  if (typeof options?.auto === 'function') {
141
- afterEach(
142
- vis.afterEach.matchPerTheme({
143
- auto: options.auto,
144
- }),
145
- )
132
+ afterEach(matcher.createMatcher({ auto: options.auto }))
146
133
  } else if (typeof options?.auto === 'object') {
147
- afterEach(vis.afterEach.matchPerTheme(options.auto))
134
+ afterEach(matcher.createMatcher(options.auto))
148
135
  } else {
149
- afterEach(vis.afterEach.matchImageSnapshot)
136
+ afterEach(matcher.createMatcher({ async auto() {} }))
150
137
  }
151
138
  },
152
139
  presets: {
153
140
  enable() {
154
- beforeAll(vis.beforeAll.setup)
155
- afterEach(vis.afterEach.matchImageSnapshot)
141
+ beforeAll(matcher.setup)
142
+ afterEach(matcher.createMatcher({ async auto() {} }))
156
143
  },
157
144
  manual() {
158
- beforeAll(vis.beforeAll.setup)
145
+ beforeAll(matcher.setup)
159
146
  },
160
147
  auto() {
161
148
  beforeAll(async () => {
162
- await vis.beforeAll.setup()
149
+ await matcher.setup()
163
150
  setAutoSnapshotOptions(true)
164
151
  })
165
- afterEach(vis.afterEach.matchImageSnapshot)
152
+ afterEach(matcher.createMatcher({ async auto() {} }))
166
153
  },
167
154
  theme(themes) {
168
155
  beforeAll(async () => {
169
- await vis.beforeAll.setup()
156
+ await matcher.setup()
170
157
  setAutoSnapshotOptions(true)
171
158
  })
172
- afterEach(vis.afterEach.matchPerTheme(themes))
159
+ afterEach(matcher.createMatcher(themes))
173
160
  },
174
161
  },
175
162
  beforeAll: {
176
163
  async setup() {
177
- subject = (await commands.setupVisSuite()).subject
164
+ await matcher.setup()
178
165
  },
179
166
  },
180
167
  afterEach: {
181
168
  async matchImageSnapshot() {
182
- return vis.afterEach.matchPerTheme({ async auto() {} })()
169
+ return matcher.createMatcher({ async auto() {} })()
183
170
  },
184
171
  matchPerTheme(themes) {
185
- return async function matchImageSnapshot() {
186
- const test = ctx.getCurrentTest()
187
- if ((test?.result?.errors?.length ?? 0) > 0) return
188
-
189
- const meta = extractAutoSnapshotOptions(test)
190
- if (!shouldTakeSnapshot(meta)) return
191
- const errors: Array<[string, Error]> = []
192
- for (const themeId in themes) {
193
- try {
194
- await new Promise((a) => setTimeout(a, 10))
195
- const theme = themes[themeId]
196
- const r = typeof theme === 'function' ? await theme(meta! as any) : theme
197
- if (r === false) continue
198
- await test!.context.expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
199
- ...meta,
200
- snapshotKey: meta?.snapshotKey ?? themeId,
201
- })
202
- } catch (error) {
203
- errors.push([themeId, error as Error])
204
- }
205
- }
206
- if (errors.length > 0) {
207
- if (errors.length === 1) throw errors[0]![1]
208
- const taskId = toTaskId(test!)
209
- throw new AggregateError(
210
- errors,
211
- dedent`Snapshot \`${taskId}\` mismatched
212
-
213
- ${errors
214
- .map(([themeId, error]) => {
215
- return `Theme \`${themeId}\` failed: ${error.message}`
216
- })
217
- .join('\n\n')}`,
218
- )
219
- }
220
- }
172
+ return matcher.createMatcher(themes)
221
173
  },
222
174
  },
223
175
  }
224
176
  return vis
225
177
  }
226
-
227
- function getSubject(selectors: string | undefined) {
228
- return selectors ? (document.querySelector(selectors) ?? document.body) : document.body
229
- }
@@ -0,0 +1,17 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="setup" />
4
+
5
+ # Overview
6
+
7
+ `vitest-plugin-vis/setup` provides the API to setup the plugin on the client side.
8
+
9
+ It provides the API you needed in `vitest.setup.ts`.
10
+
11
+ ## Augmentation
12
+
13
+ When you import `vitest-plugin-vis/setup`, it will augment `expect` and `page` to provide methods for visual testing.
14
+
15
+ - `expect().toMatchImageSnapshot()`: Match the image snapshot.
16
+ - `page.toMatchImageSnapshot()`: Match the image snapshot.
17
+ - `page.hasImageSnapshot()`: Check if the image snapshot exists.
@@ -0,0 +1,7 @@
1
+ # setup
2
+
3
+ Code in this directory is used to setup the plugin in `vitest.setup.ts`.
4
+
5
+ The code is executed in Vitest browser runner worker.
6
+
7
+ This worker is running on a headless chrome with `window.name` set to `vitest-iframe`.
@@ -1,15 +1,10 @@
1
- import { Meta, Source } from "@storybook/addon-docs/blocks";
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
2
 
3
- <Meta title="vitest-plugin-vis/setup/vis" />
3
+ <Meta title="setup/vis" />
4
4
 
5
- `vis` from `vitest-plugin-vis/setup` is the main mechanism to setup the plugin on the client side.
5
+ # `vis`
6
6
 
7
- ```ts
8
- // vitest.setup.ts
9
- import { vis } from 'vitest-plugin-vis/setup'
10
-
11
- vis.setup()
12
- ```
7
+ `vis` object from `vitest-plugin-vis/setup` provides the API to setup the plugin on the client side.
13
8
 
14
9
  ## Basic Setup
15
10
 
@@ -23,7 +18,7 @@ vis.setup()
23
18
  // Enable auto snapshots for all tests
24
19
  vis.setup({ auto: true })
25
20
 
26
- // Disable auto snapshots (same as vis.setup())
21
+ // Disable auto snapshots (same as `vis.setup()`)
27
22
  vis.setup({ auto: false })
28
23
  ```
29
24
 
@@ -46,6 +41,8 @@ vis.setup({
46
41
  })
47
42
  ```
48
43
 
44
+ The function will be called during the `afterEach()` phase of the test.
45
+
49
46
  ## Multi-Theme Setup
50
47
 
51
48
  Set up automatic snapshots for multiple themes (e.g., light and dark mode):
@@ -56,11 +53,11 @@ import { vis } from 'vitest-plugin-vis/setup'
56
53
 
57
54
  vis.setup({
58
55
  auto: {
59
- async light() {
56
+ light: async () => {
60
57
  document.body.classList.remove('dark')
61
58
  document.body.classList.add('light')
62
59
  },
63
- async dark() {
60
+ dark: async () => {
64
61
  document.body.classList.add('dark')
65
62
  document.body.classList.remove('light')
66
63
  }
@@ -78,11 +75,11 @@ import { vis } from 'vitest-plugin-vis/setup'
78
75
 
79
76
  vis.setup({
80
77
  auto: {
81
- async light({ meta }) {
78
+ light: async ({ meta }) => {
82
79
  if (meta['skipLight']) return false
83
80
  document.body.classList.remove('dark')
84
81
  },
85
- async dark({ meta }) {
82
+ dark: async ({ meta }) => {
86
83
  if (meta['skipDark']) return false
87
84
  document.body.classList.add('dark')
88
85
  }
@@ -100,19 +97,19 @@ import { vis } from 'vitest-plugin-vis/setup'
100
97
 
101
98
  vis.setup({
102
99
  auto: {
103
- async desktop() {
100
+ desktop: async () => {
104
101
  document.body.style.width = '1200px'
105
102
  document.body.classList.add('desktop')
106
103
  },
107
- async tablet() {
104
+ tablet: async () => {
108
105
  document.body.style.width = '768px'
109
106
  document.body.classList.add('tablet')
110
107
  },
111
- async mobile() {
108
+ mobile: async () => {
112
109
  document.body.style.width = '375px'
113
110
  document.body.classList.add('mobile')
114
111
  },
115
- async 'dark-desktop'({ meta }) {
112
+ 'dark-desktop': async ({ meta }) => {
116
113
  if (meta['skipDark']) return false
117
114
  document.body.style.width = '1200px'
118
115
  document.body.classList.add('desktop', 'dark')
@@ -0,0 +1,5 @@
1
+ // `vitest-plugin-vis/setup` provides code needed in `vitest.setup.ts`.
2
+ import './client/expect/extend.ts'
3
+ import './client/page/extend.ts'
4
+
5
+ export * from './setup/create_vis.ts'
package/src/setup.ts CHANGED
@@ -1,6 +1,10 @@
1
- // `vitest-plugin-vis/setup` provides code needed in `vitest.setup.ts`.
2
- import './client/expect/extend.ts'
3
- import './client/page/extend.ts'
1
+ import './setup-api.ts'
4
2
 
5
- export * from './client/setup/create_vis.ts'
6
- export * from './client/setup/vis.ts'
3
+ export * from './setup/vis.ts'
4
+
5
+ import { createVis as createVisDeprecated } from './setup/create_vis.ts'
6
+
7
+ /**
8
+ * @deprecated Use `createVis` from `vitest-plugin-vis/setup-api` instead.
9
+ */
10
+ export const createVis = createVisDeprecated
@@ -0,0 +1,71 @@
1
+ import type { Pick } from 'type-plus'
2
+ import type { VisOptions } from '../config/types.ts'
3
+ import type { ImageSnapshotComparisonInfo, MatchImageSnapshotOptions } from './types.ts'
4
+
5
+ export interface PrepareImageSnapshotComparisonCommand {
6
+ prepareImageSnapshotComparison: (
7
+ taskId: string,
8
+ subject: string,
9
+ options?: MatchImageSnapshotOptions | undefined,
10
+ ) => Promise<ImageSnapshotComparisonInfo>
11
+ }
12
+
13
+ export interface PreparePageImageSnapshotComparisonCommand {
14
+ preparePageImageSnapshotComparison: (
15
+ taskId: string,
16
+ options?: MatchImageSnapshotOptions | undefined,
17
+ ) => Promise<ImageSnapshotComparisonInfo>
18
+ }
19
+
20
+ export interface SetupVisSuiteCommand {
21
+ /**
22
+ * Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
23
+ * When this command is run for the first time,
24
+ * it will remove the results and diffs directory of all suites.
25
+ *
26
+ * In subsequent runs, it will only remove the results and diffs directory of the current suite.
27
+ */
28
+ setupVisSuite: () => Promise<
29
+ Pick<
30
+ VisOptions,
31
+ | 'comparisonMethod'
32
+ | 'diffOptions'
33
+ | 'failureThreshold'
34
+ | 'failureThresholdType'
35
+ | 'snapshotKey'
36
+ | 'subject'
37
+ | 'timeout'
38
+ >
39
+ >
40
+ }
41
+
42
+ export interface LoadImageSnapshotResultsCommand {
43
+ loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
44
+ }
45
+
46
+ export interface ImageSnapshotResult {
47
+ filename: string
48
+ /**
49
+ * The base64 encoded image of the baseline snapshot.
50
+ */
51
+ baseline?: string | undefined
52
+ /**
53
+ * The base64 encoded image of the result snapshot.
54
+ */
55
+ result?: string | undefined
56
+ /**
57
+ * The base64 encoded image of the diff snapshot.
58
+ */
59
+ diff?: string | undefined
60
+ }
61
+
62
+ export interface HasImageSnapshotCommand {
63
+ hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
64
+ }
65
+
66
+ export interface ImageSnapshotNextIndexCommand {
67
+ /**
68
+ * Get the index of the snapshot image to be created.
69
+ */
70
+ imageSnapshotNextIndex(taskId: string): Promise<number>
71
+ }