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,82 @@
1
+ import { file } from "./externals/file.mjs";
2
+ import { getVisOption } from "./vis_options.mjs";
3
+ import { getSuite, getTaskSubpath } from "./suite.mjs";
4
+ import { basename, join, resolve } from "pathe";
5
+ import { pick } from "type-plus";
6
+
7
+ //#region src/server/vis_server_context.logic.ts
8
+ function createVisServerContext() {
9
+ const context = {
10
+ async getSnapshotResults(browserContext, taskId) {
11
+ const suiteInfo = await context.getSuiteInfo(browserContext, taskId);
12
+ const baselines = await file.glob(join(suiteInfo.projectRoot, suiteInfo.baselineDir, `${suiteInfo.taskId}-*.png`));
13
+ const results = await file.glob(join(suiteInfo.projectRoot, suiteInfo.resultDir, `${suiteInfo.taskId}-*.png`));
14
+ const diffs = await file.glob(join(suiteInfo.projectRoot, suiteInfo.diffDir, `${suiteInfo.taskId}-*.png`));
15
+ const r = [];
16
+ await Promise.all(baselines.map(async (baselinePath) => {
17
+ const filename = basename(baselinePath);
18
+ const resultPath = results.find((r$1) => r$1.endsWith(filename));
19
+ const diffPath = diffs.find((d) => d.endsWith(filename));
20
+ const baselineBuffer = await file.tryReadFile(baselinePath);
21
+ const resultBuffer = await file.tryReadFile(resultPath);
22
+ const diffBuffer = await file.tryReadFile(diffPath);
23
+ r.push({
24
+ filename,
25
+ baseline: baselineBuffer?.toString("base64"),
26
+ result: resultBuffer?.toString("base64"),
27
+ diff: diffBuffer?.toString("base64")
28
+ });
29
+ }));
30
+ return r;
31
+ },
32
+ async getSnapshotInfo(browserContext, taskId, options) {
33
+ const suiteInfo = await context.getSuiteInfo(browserContext, taskId);
34
+ const snapshotFilename = context.getSnapshotFilename(browserContext, suiteInfo, options?.snapshotKey);
35
+ const { baselineDir, resultDir, diffDir, task } = suiteInfo;
36
+ task.count = task.count + 1;
37
+ const baselinePath = join(baselineDir, snapshotFilename);
38
+ const resultPath = join(resultDir, snapshotFilename);
39
+ const diffPath = join(diffDir, snapshotFilename);
40
+ return {
41
+ ...pick(getVisOption(browserContext), "comparisonMethod", "diffOptions", "failureThreshold", "failureThresholdType", "timeout"),
42
+ baselinePath,
43
+ resultPath,
44
+ diffPath
45
+ };
46
+ },
47
+ async getTaskCount(browserContext, taskId) {
48
+ return (await context.getSuiteInfo(browserContext, taskId)).task.count;
49
+ },
50
+ async hasImageSnapshot(browserContext, taskId, snapshotKey) {
51
+ const info = await context.getSuiteInfo(browserContext, taskId);
52
+ return file.existFile(resolve(info.projectRoot, info.baselineDir, context.getSnapshotFilename(browserContext, info, snapshotKey)));
53
+ },
54
+ getSnapshotFilename(browserContext, info, snapshotKey) {
55
+ if (snapshotKey) return `${info.taskId}-${snapshotKey}.png`;
56
+ const visOptions = getVisOption(browserContext);
57
+ if (typeof visOptions.snapshotKey === "string") return `${info.taskId}-${visOptions.snapshotKey}.png`;
58
+ return `${info.taskId}-${info.task.count}.png`;
59
+ },
60
+ async getSuiteInfo(browserContext, taskId) {
61
+ const projectState = await getSuite(browserContext);
62
+ const visOptions = getVisOption(browserContext);
63
+ const moduleId = getTaskSubpath(projectState, browserContext.testPath, visOptions);
64
+ const m = projectState.modules[moduleId];
65
+ const task = m.tasks[taskId] = m.tasks[taskId] ?? { count: 1 };
66
+ return {
67
+ projectRoot: projectState.projectRoot,
68
+ suiteId: moduleId,
69
+ taskId,
70
+ baselineDir: m.baselineDir,
71
+ resultDir: m.resultDir,
72
+ diffDir: m.diffDir,
73
+ task
74
+ };
75
+ }
76
+ };
77
+ return context;
78
+ }
79
+
80
+ //#endregion
81
+ export { createVisServerContext };
82
+ //# sourceMappingURL=vis_server_context.logic.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis_server_context.logic.mjs","names":["r"],"sources":["../../src/server/vis_server_context.logic.ts"],"sourcesContent":["import { basename, join, resolve } from 'pathe'\nimport { pick } from 'type-plus'\nimport type { ImageSnapshotKeyOptions } from '../client-api.ts'\nimport type { ImageSnapshotResult } from '../shared/commands.types.ts'\nimport { file } from './externals/file.ts'\nimport { getSuite, getTaskSubpath } from './suite.ts'\nimport { getVisOption } from './vis_options.ts'\nimport type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'\n\nexport function createVisServerContext() {\n\tconst context = {\n\t\tasync getSnapshotResults(browserContext: ExtendedBrowserCommandContext, taskId: string) {\n\t\t\tconst suiteInfo = await context.getSuiteInfo(browserContext, taskId)\n\t\t\tconst baselines = await file.glob(join(suiteInfo.projectRoot, suiteInfo.baselineDir, `${suiteInfo.taskId}-*.png`))\n\t\t\tconst results = await file.glob(join(suiteInfo.projectRoot, suiteInfo.resultDir, `${suiteInfo.taskId}-*.png`))\n\t\t\tconst diffs = await file.glob(join(suiteInfo.projectRoot, suiteInfo.diffDir, `${suiteInfo.taskId}-*.png`))\n\n\t\t\tconst r: ImageSnapshotResult[] = []\n\t\t\tawait Promise.all(\n\t\t\t\tbaselines.map(async (baselinePath) => {\n\t\t\t\t\tconst filename = basename(baselinePath)\n\t\t\t\t\tconst resultPath = results.find((r) => r.endsWith(filename))\n\t\t\t\t\tconst diffPath = diffs.find((d) => d.endsWith(filename))\n\n\t\t\t\t\tconst baselineBuffer = await file.tryReadFile(baselinePath)\n\t\t\t\t\tconst resultBuffer = await file.tryReadFile(resultPath)\n\t\t\t\t\tconst diffBuffer = await file.tryReadFile(diffPath)\n\t\t\t\t\tr.push({\n\t\t\t\t\t\tfilename,\n\t\t\t\t\t\tbaseline: baselineBuffer?.toString('base64'),\n\t\t\t\t\t\tresult: resultBuffer?.toString('base64'),\n\t\t\t\t\t\tdiff: diffBuffer?.toString('base64'),\n\t\t\t\t\t})\n\t\t\t\t}),\n\t\t\t)\n\t\t\treturn r\n\t\t},\n\t\tasync getSnapshotInfo(\n\t\t\tbrowserContext: ExtendedBrowserCommandContext,\n\t\t\ttaskId: string,\n\t\t\toptions?: ImageSnapshotKeyOptions,\n\t\t) {\n\t\t\tconst suiteInfo = await context.getSuiteInfo(browserContext, taskId)\n\t\t\tconst snapshotFilename = context.getSnapshotFilename(browserContext, suiteInfo, options?.snapshotKey)\n\n\t\t\tconst { baselineDir, resultDir, diffDir, task } = suiteInfo\n\n\t\t\ttask.count = task.count + 1\n\t\t\tconst baselinePath = join(baselineDir, snapshotFilename)\n\t\t\tconst resultPath = join(resultDir, snapshotFilename)\n\t\t\tconst diffPath = join(diffDir, snapshotFilename)\n\n\t\t\treturn {\n\t\t\t\t...pick(\n\t\t\t\t\tgetVisOption(browserContext),\n\t\t\t\t\t'comparisonMethod',\n\t\t\t\t\t'diffOptions',\n\t\t\t\t\t'failureThreshold',\n\t\t\t\t\t'failureThresholdType',\n\t\t\t\t\t'timeout',\n\t\t\t\t),\n\t\t\t\tbaselinePath,\n\t\t\t\tresultPath,\n\t\t\t\tdiffPath,\n\t\t\t}\n\t\t},\n\n\t\tasync getTaskCount(browserContext: ExtendedBrowserCommandContext, taskId: string) {\n\t\t\treturn (await context.getSuiteInfo(browserContext, taskId)).task.count\n\t\t},\n\t\tasync hasImageSnapshot(\n\t\t\tbrowserContext: ExtendedBrowserCommandContext,\n\t\t\ttaskId: string,\n\t\t\tsnapshotKey: string | undefined,\n\t\t) {\n\t\t\tconst info = await context.getSuiteInfo(browserContext, taskId)\n\n\t\t\treturn file.existFile(\n\t\t\t\tresolve(info.projectRoot, info.baselineDir, context.getSnapshotFilename(browserContext, info, snapshotKey)),\n\t\t\t)\n\t\t},\n\t\tgetSnapshotFilename(\n\t\t\tbrowserContext: ExtendedBrowserCommandContext,\n\t\t\tinfo: { taskId: string; task: { count: number } },\n\t\t\tsnapshotKey: string | undefined,\n\t\t) {\n\t\t\tif (snapshotKey) return `${info.taskId}-${snapshotKey}.png`\n\t\t\tconst visOptions = getVisOption(browserContext)\n\t\t\tif (typeof visOptions.snapshotKey === 'string') {\n\t\t\t\treturn `${info.taskId}-${visOptions.snapshotKey}.png`\n\t\t\t}\n\t\t\treturn `${info.taskId}-${info.task.count}.png`\n\t\t},\n\t\tasync getSuiteInfo(browserContext: ExtendedBrowserCommandContext, taskId: string) {\n\t\t\tconst projectState = await getSuite(browserContext)\n\t\t\tconst visOptions = getVisOption(browserContext)\n\t\t\tconst moduleId = getTaskSubpath(projectState, browserContext.testPath, visOptions)\n\t\t\tconst m = projectState.modules[moduleId]!\n\t\t\tconst task = (m.tasks[taskId] = m.tasks[taskId] ?? { count: 1 })\n\t\t\treturn {\n\t\t\t\tprojectRoot: projectState.projectRoot,\n\t\t\t\tsuiteId: moduleId,\n\t\t\t\ttaskId,\n\t\t\t\tbaselineDir: m.baselineDir,\n\t\t\t\tresultDir: m.resultDir,\n\t\t\t\tdiffDir: m.diffDir,\n\t\t\t\ttask,\n\t\t\t}\n\t\t},\n\t}\n\treturn context\n}\n"],"mappings":";;;;;;;AASA,SAAgB,yBAAyB;CACxC,MAAM,UAAU;EACf,MAAM,mBAAmB,gBAA+C,QAAgB;GACvF,MAAM,YAAY,MAAM,QAAQ,aAAa,gBAAgB,OAAO;GACpE,MAAM,YAAY,MAAM,KAAK,KAAK,KAAK,UAAU,aAAa,UAAU,aAAa,GAAG,UAAU,OAAO,QAAQ,CAAC;GAClH,MAAM,UAAU,MAAM,KAAK,KAAK,KAAK,UAAU,aAAa,UAAU,WAAW,GAAG,UAAU,OAAO,QAAQ,CAAC;GAC9G,MAAM,QAAQ,MAAM,KAAK,KAAK,KAAK,UAAU,aAAa,UAAU,SAAS,GAAG,UAAU,OAAO,QAAQ,CAAC;GAE1G,MAAM,IAA2B,EAAE;AACnC,SAAM,QAAQ,IACb,UAAU,IAAI,OAAO,iBAAiB;IACrC,MAAM,WAAW,SAAS,aAAa;IACvC,MAAM,aAAa,QAAQ,MAAM,QAAMA,IAAE,SAAS,SAAS,CAAC;IAC5D,MAAM,WAAW,MAAM,MAAM,MAAM,EAAE,SAAS,SAAS,CAAC;IAExD,MAAM,iBAAiB,MAAM,KAAK,YAAY,aAAa;IAC3D,MAAM,eAAe,MAAM,KAAK,YAAY,WAAW;IACvD,MAAM,aAAa,MAAM,KAAK,YAAY,SAAS;AACnD,MAAE,KAAK;KACN;KACA,UAAU,gBAAgB,SAAS,SAAS;KAC5C,QAAQ,cAAc,SAAS,SAAS;KACxC,MAAM,YAAY,SAAS,SAAS;KACpC,CAAC;KACD,CACF;AACD,UAAO;;EAER,MAAM,gBACL,gBACA,QACA,SACC;GACD,MAAM,YAAY,MAAM,QAAQ,aAAa,gBAAgB,OAAO;GACpE,MAAM,mBAAmB,QAAQ,oBAAoB,gBAAgB,WAAW,SAAS,YAAY;GAErG,MAAM,EAAE,aAAa,WAAW,SAAS,SAAS;AAElD,QAAK,QAAQ,KAAK,QAAQ;GAC1B,MAAM,eAAe,KAAK,aAAa,iBAAiB;GACxD,MAAM,aAAa,KAAK,WAAW,iBAAiB;GACpD,MAAM,WAAW,KAAK,SAAS,iBAAiB;AAEhD,UAAO;IACN,GAAG,KACF,aAAa,eAAe,EAC5B,oBACA,eACA,oBACA,wBACA,UACA;IACD;IACA;IACA;IACA;;EAGF,MAAM,aAAa,gBAA+C,QAAgB;AACjF,WAAQ,MAAM,QAAQ,aAAa,gBAAgB,OAAO,EAAE,KAAK;;EAElE,MAAM,iBACL,gBACA,QACA,aACC;GACD,MAAM,OAAO,MAAM,QAAQ,aAAa,gBAAgB,OAAO;AAE/D,UAAO,KAAK,UACX,QAAQ,KAAK,aAAa,KAAK,aAAa,QAAQ,oBAAoB,gBAAgB,MAAM,YAAY,CAAC,CAC3G;;EAEF,oBACC,gBACA,MACA,aACC;AACD,OAAI,YAAa,QAAO,GAAG,KAAK,OAAO,GAAG,YAAY;GACtD,MAAM,aAAa,aAAa,eAAe;AAC/C,OAAI,OAAO,WAAW,gBAAgB,SACrC,QAAO,GAAG,KAAK,OAAO,GAAG,WAAW,YAAY;AAEjD,UAAO,GAAG,KAAK,OAAO,GAAG,KAAK,KAAK,MAAM;;EAE1C,MAAM,aAAa,gBAA+C,QAAgB;GACjF,MAAM,eAAe,MAAM,SAAS,eAAe;GACnD,MAAM,aAAa,aAAa,eAAe;GAC/C,MAAM,WAAW,eAAe,cAAc,eAAe,UAAU,WAAW;GAClF,MAAM,IAAI,aAAa,QAAQ;GAC/B,MAAM,OAAQ,EAAE,MAAM,UAAU,EAAE,MAAM,WAAW,EAAE,OAAO,GAAG;AAC/D,UAAO;IACN,aAAa,aAAa;IAC1B,SAAS;IACT;IACA,aAAa,EAAE;IACf,WAAW,EAAE;IACb,SAAS,EAAE;IACX;IACA;;EAEF;AACD,QAAO"}
@@ -0,0 +1,8 @@
1
+ import { createVisServerContext } from "./vis_server_context.logic.mjs";
2
+
3
+ //#region src/server/vis_server_context.ts
4
+ const visServerContext = createVisServerContext();
5
+
6
+ //#endregion
7
+ export { visServerContext };
8
+ //# sourceMappingURL=vis_server_context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis_server_context.mjs","names":[],"sources":["../../src/server/vis_server_context.ts"],"sourcesContent":["import { createVisServerContext } from './vis_server_context.logic.ts'\n\nexport const visServerContext = createVisServerContext()\n"],"mappings":";;;AAEA,MAAa,mBAAmB,wBAAwB"}
@@ -0,0 +1,2 @@
1
+ import "../shared/types.mjs";
2
+ import "type-plus";
@@ -1,19 +1,4 @@
1
- import { _ as DIFF_DIR, b as SNAPSHOT_ROOT_DIR, g as BASELINE_DIR, v as NAME, y as RESULT_DIR } from "./types-DFb23VE1.mjs";
2
- import "./vis_server_context.types-Ce1f9vOO.mjs";
3
- import "./types-Do1N7g4c.mjs";
4
- import { t as trimCommonFolder } from "./trim_common_folder-ModiubEJ.mjs";
5
-
6
- //#region src/server/snapshot_path.d.ts
7
-
8
- /**
9
- * Gets the root directory for storing snapshots.
10
- *
11
- * @param snapshotRootDir - Base directory for snapshots. Defaults to `__vis__`.
12
- * @returns The full snapshot root directory path, which includes a platform-specific subdirectory:
13
- * - When running in CI: `<snapshotRootDir>/<platform>` (e.g. `__vis__/linux`)
14
- * - When running locally: `<snapshotRootDir>/local`
15
- */
16
- declare function getSnapshotRootDir(snapshotRootDir?: string): string;
17
- //#endregion
18
- export { BASELINE_DIR, DIFF_DIR, NAME, RESULT_DIR, SNAPSHOT_ROOT_DIR, getSnapshotRootDir, trimCommonFolder };
19
- //# sourceMappingURL=server-utils.d.mts.map
1
+ import { BASELINE_DIR, DIFF_DIR, NAME, RESULT_DIR, SNAPSHOT_ROOT_DIR } from "./shared/constants.mjs";
2
+ import { trimCommonFolder } from "./shared/trim_common_folder.mjs";
3
+ import { getSnapshotRootDir } from "./server/snapshot_path.mjs";
4
+ export { BASELINE_DIR, DIFF_DIR, NAME, RESULT_DIR, SNAPSHOT_ROOT_DIR, getSnapshotRootDir, trimCommonFolder };
@@ -1,4 +1,5 @@
1
- import { a as SNAPSHOT_ROOT_DIR, i as RESULT_DIR, n as DIFF_DIR, r as NAME, t as BASELINE_DIR } from "./constants-CTBaz8Ml.mjs";
2
- import { i as trimCommonFolder, t as getSnapshotRootDir } from "./snapshot_path-7GliOSH_.mjs";
1
+ import { BASELINE_DIR, DIFF_DIR, NAME, RESULT_DIR, SNAPSHOT_ROOT_DIR } from "./shared/constants.mjs";
2
+ import { trimCommonFolder } from "./shared/trim_common_folder.mjs";
3
+ import { getSnapshotRootDir } from "./server/snapshot_path.mjs";
3
4
 
4
5
  export { BASELINE_DIR, DIFF_DIR, NAME, RESULT_DIR, SNAPSHOT_ROOT_DIR, getSnapshotRootDir, trimCommonFolder };
@@ -0,0 +1,108 @@
1
+ import { SnapshotMeta } from "../auto_snapshots/snapshot_meta.mjs";
2
+ import { ComparisonMethod, SetupVisOptions } from "../shared/types.mjs";
3
+ import { SetupVisSuiteCommand } from "../shared/commands.types.mjs";
4
+
5
+ //#region src/setup/create_vis.d.ts
6
+
7
+ /**
8
+ * Visual test configuration on the client side.
9
+ */
10
+ type VisClientConfigurator<GM extends Record<string, any> | unknown = unknown> = {
11
+ /**
12
+ * Setup the visual test configuration.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Setup with auto snapshot enabled
17
+ * vis().setup({ auto: true })
18
+ *
19
+ * // Setup with auto snapshot disabled
20
+ * vis().setup({ auto: false })
21
+ *
22
+ * // Same as `vis.setup({ auto: false })`
23
+ * vis.setup()
24
+ *
25
+ * // Setup with auto snapshot determined by the test meta
26
+ * vis.setup({
27
+ * auto: async ({ meta }) => meta['darkOnly'],
28
+ * })
29
+ *
30
+ * // Setup with multiple auto snapshots
31
+ * vis.setup({
32
+ * auto: {
33
+ * async light() { document.body.classList.remove('dark') },
34
+ * async dark() { document.body.classList.add('dark') },
35
+ * }
36
+ * })
37
+ * ```
38
+ */
39
+ setup(options?: SetupVisOptions<GM>): void;
40
+ /**
41
+ * @deprecated Use `vis.setup()` instead.
42
+ */
43
+ presets: {
44
+ /**
45
+ * @deprecated Use `vis.setup()` instead.
46
+ *
47
+ * Enable visual testing.
48
+ *
49
+ * auto snapshot is turned off by default.
50
+ * You can specify the test to take a snapshot during `afterEach()` hook with `setAutoSnapshotOptions()`.
51
+ */
52
+ enable(): void;
53
+ /**
54
+ * @deprecated Use `vis.setup()` instead.
55
+ *
56
+ * Enable visual testing.
57
+ *
58
+ * `setAutoSnapshotOptions` will have no effect in this preset.
59
+ */
60
+ manual(): void;
61
+ /**
62
+ * @deprecated Use `vis.setup()` instead.
63
+ *
64
+ * Enable automatic visual testing.
65
+ *
66
+ * This will take a snapshot after each test.
67
+ */
68
+ auto(): void;
69
+ /**
70
+ * @deprecated Use `vis.setup()` instead.
71
+ *
72
+ * Enable automatic visual testing with multiple themes.
73
+ *
74
+ * This will take a snapshot after each test for each theme.
75
+ *
76
+ * @param themes A record of theme names and their setup functions.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * vis().presets.theme({
81
+ * light() { document.body.classList.add('light') },
82
+ * dark() { document.body.classList.add('dark') },
83
+ * })
84
+ * ```
85
+ */
86
+ theme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(themes: Record<string, boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>): void;
87
+ };
88
+ beforeAll: {
89
+ /**
90
+ * @deprecated No known use case.
91
+ */
92
+ setup(): Promise<void>;
93
+ };
94
+ afterEach: {
95
+ /**
96
+ * @deprecated No known use case.
97
+ */
98
+ matchImageSnapshot(): Promise<void>;
99
+ /**
100
+ * @deprecated No known use case.
101
+ */
102
+ matchPerTheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(themes: Record<string, boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>): () => Promise<void>;
103
+ };
104
+ };
105
+ declare function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand): VisClientConfigurator<GM>;
106
+ //#endregion
107
+ export { VisClientConfigurator, createVis };
108
+ //# sourceMappingURL=create_vis.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_vis.d.mts","names":[],"sources":["../../src/setup/create_vis.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUA;AAA6C,KAAjC,qBAAiC,CAAA,WAAA,MAAA,CAAA,MAAA,EAAA,GAAA,CAAA,GAAA,OAAA,GAAA,OAAA,CAAA,GAAA;EA6BZ;;;;;;;;;;;;;;;;;;;;;;;;AA6EjC;;;;EAA4G,KAAA,CAAA,OAAA,CAAA,EA7E3F,eA6E2F,CA7E3E,EA6E2E,CAAA,CAAA,EAAA,IAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBA9B1F,4BAA4B,iDACnC,oCAEc,aAAa,KAAK,IAAI,OAAO,mBAAmB;;;;;;aAQ9D;;;;;;0BAMa;;;;4BAIE,4BAA4B,iDAC3C,oCAEc,aAAa,KAAK,IAAI,OAAO,mBAAmB,yCAE9D;;;iBAIK,qBAAqB,mDAAmD,uBAAoB,sBAAA"}
@@ -0,0 +1,58 @@
1
+ import { setAutoSnapshotOptions } from "../auto_snapshots/auto_snapshot_options.mjs";
2
+ import { autoSnapshotMatcher } from "../client/suite/auto_snapshot_matcher.mjs";
3
+ import { afterEach, beforeAll, expect } from "vitest";
4
+
5
+ //#region src/setup/create_vis.ts
6
+ function createVis(commands) {
7
+ const matcher = autoSnapshotMatcher(commands, expect);
8
+ return {
9
+ setup(options) {
10
+ if (!options || options.auto === false) beforeAll(matcher.setup);
11
+ else beforeAll(async () => {
12
+ await matcher.setup();
13
+ setAutoSnapshotOptions(true);
14
+ });
15
+ if (typeof options?.auto === "function") afterEach(matcher.createMatcher({ auto: options.auto }));
16
+ else if (typeof options?.auto === "object") afterEach(matcher.createMatcher(options.auto));
17
+ else afterEach(matcher.createMatcher({ async auto() {} }));
18
+ },
19
+ presets: {
20
+ enable() {
21
+ beforeAll(matcher.setup);
22
+ afterEach(matcher.createMatcher({ async auto() {} }));
23
+ },
24
+ manual() {
25
+ beforeAll(matcher.setup);
26
+ },
27
+ auto() {
28
+ beforeAll(async () => {
29
+ await matcher.setup();
30
+ setAutoSnapshotOptions(true);
31
+ });
32
+ afterEach(matcher.createMatcher({ async auto() {} }));
33
+ },
34
+ theme(themes) {
35
+ beforeAll(async () => {
36
+ await matcher.setup();
37
+ setAutoSnapshotOptions(true);
38
+ });
39
+ afterEach(matcher.createMatcher(themes));
40
+ }
41
+ },
42
+ beforeAll: { async setup() {
43
+ await matcher.setup();
44
+ } },
45
+ afterEach: {
46
+ async matchImageSnapshot() {
47
+ return matcher.createMatcher({ async auto() {} })();
48
+ },
49
+ matchPerTheme(themes) {
50
+ return matcher.createMatcher(themes);
51
+ }
52
+ }
53
+ };
54
+ }
55
+
56
+ //#endregion
57
+ export { createVis };
58
+ //# sourceMappingURL=create_vis.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_vis.mjs","names":[],"sources":["../../src/setup/create_vis.ts"],"sourcesContent":["import { afterEach, beforeAll, expect } from 'vitest'\nimport { setAutoSnapshotOptions } from '../auto_snapshots/auto_snapshot_options.ts'\nimport type { SnapshotMeta } from '../auto_snapshots/snapshot_meta.ts'\nimport { autoSnapshotMatcher } from '../client/suite/auto_snapshot_matcher.ts'\nimport type { SetupVisSuiteCommand } from '../shared/commands.types.ts'\nimport type { ComparisonMethod, SetupVisOptions } from '../shared/types.ts'\n\n/**\n * Visual test configuration on the client side.\n */\nexport type VisClientConfigurator<GM extends Record<string, any> | unknown = unknown> = {\n\t/**\n\t * Setup the visual test configuration.\n\t *\n\t * @example\n\t * ```ts\n\t * // Setup with auto snapshot enabled\n\t * vis().setup({ auto: true })\n\t *\n\t * // Setup with auto snapshot disabled\n\t * vis().setup({ auto: false })\n\t *\n\t * // Same as `vis.setup({ auto: false })`\n\t * vis.setup()\n\t *\n\t * // Setup with auto snapshot determined by the test meta\n\t * vis.setup({\n\t * \tauto: async ({ meta }) => meta['darkOnly'],\n\t * })\n\t *\n\t * // Setup with multiple auto snapshots\n\t * vis.setup({\n\t * auto: {\n\t * async light() { document.body.classList.remove('dark') },\n\t * async dark() { document.body.classList.add('dark') },\n\t * }\n\t * })\n\t * ```\n\t */\n\tsetup(options?: SetupVisOptions<GM>): void\n\t/**\n\t * @deprecated Use `vis.setup()` instead.\n\t */\n\tpresets: {\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable visual testing.\n\t\t *\n\t\t * auto snapshot is turned off by default.\n\t\t * You can specify the test to take a snapshot during `afterEach()` hook with `setAutoSnapshotOptions()`.\n\t\t */\n\t\tenable(): void\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable visual testing.\n\t\t *\n\t\t * `setAutoSnapshotOptions` will have no effect in this preset.\n\t\t */\n\t\tmanual(): void\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable automatic visual testing.\n\t\t *\n\t\t * This will take a snapshot after each test.\n\t\t */\n\t\tauto(): void\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable automatic visual testing with multiple themes.\n\t\t *\n\t\t * This will take a snapshot after each test for each theme.\n\t\t *\n\t\t * @param themes A record of theme names and their setup functions.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * vis().presets.theme({\n\t\t * light() { document.body.classList.add('light') },\n\t\t * dark() { document.body.classList.add('dark') },\n\t\t * })\n\t\t * ```\n\t\t */\n\t\ttheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(\n\t\t\tthemes: Record<\n\t\t\t\tstring,\n\t\t\t\tboolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)\n\t\t\t>,\n\t\t): void\n\t}\n\tbeforeAll: {\n\t\t/**\n\t\t * @deprecated No known use case.\n\t\t */\n\t\tsetup(): Promise<void>\n\t}\n\tafterEach: {\n\t\t/**\n\t\t * @deprecated No known use case.\n\t\t */\n\t\tmatchImageSnapshot(): Promise<void>\n\t\t/**\n\t\t * @deprecated No known use case.\n\t\t */\n\t\tmatchPerTheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(\n\t\t\tthemes: Record<\n\t\t\t\tstring,\n\t\t\t\tboolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)\n\t\t\t>,\n\t\t): () => Promise<void>\n\t}\n}\n\nexport function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand) {\n\tconst matcher = autoSnapshotMatcher(commands, expect)\n\n\tconst vis: VisClientConfigurator<GM> = {\n\t\tsetup(options) {\n\t\t\tif (!options || options.auto === false) {\n\t\t\t\tbeforeAll(matcher.setup)\n\t\t\t} else {\n\t\t\t\tbeforeAll(async () => {\n\t\t\t\t\tawait matcher.setup()\n\t\t\t\t\tsetAutoSnapshotOptions(true)\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (typeof options?.auto === 'function') {\n\t\t\t\tafterEach(matcher.createMatcher({ auto: options.auto }))\n\t\t\t} else if (typeof options?.auto === 'object') {\n\t\t\t\tafterEach(matcher.createMatcher(options.auto))\n\t\t\t} else {\n\t\t\t\tafterEach(matcher.createMatcher({ async auto() {} }))\n\t\t\t}\n\t\t},\n\t\tpresets: {\n\t\t\tenable() {\n\t\t\t\tbeforeAll(matcher.setup)\n\t\t\t\tafterEach(matcher.createMatcher({ async auto() {} }))\n\t\t\t},\n\t\t\tmanual() {\n\t\t\t\tbeforeAll(matcher.setup)\n\t\t\t},\n\t\t\tauto() {\n\t\t\t\tbeforeAll(async () => {\n\t\t\t\t\tawait matcher.setup()\n\t\t\t\t\tsetAutoSnapshotOptions(true)\n\t\t\t\t})\n\t\t\t\tafterEach(matcher.createMatcher({ async auto() {} }))\n\t\t\t},\n\t\t\ttheme(themes) {\n\t\t\t\tbeforeAll(async () => {\n\t\t\t\t\tawait matcher.setup()\n\t\t\t\t\tsetAutoSnapshotOptions(true)\n\t\t\t\t})\n\t\t\t\tafterEach(matcher.createMatcher(themes))\n\t\t\t},\n\t\t},\n\t\tbeforeAll: {\n\t\t\tasync setup() {\n\t\t\t\tawait matcher.setup()\n\t\t\t},\n\t\t},\n\t\tafterEach: {\n\t\t\tasync matchImageSnapshot() {\n\t\t\t\treturn matcher.createMatcher({ async auto() {} })()\n\t\t\t},\n\t\t\tmatchPerTheme(themes) {\n\t\t\t\treturn matcher.createMatcher(themes)\n\t\t\t},\n\t\t},\n\t}\n\treturn vis\n}\n"],"mappings":";;;;;AAoHA,SAAgB,UAA8D,UAAgC;CAC7G,MAAM,UAAU,oBAAoB,UAAU,OAAO;AA0DrD,QAxDuC;EACtC,MAAM,SAAS;AACd,OAAI,CAAC,WAAW,QAAQ,SAAS,MAChC,WAAU,QAAQ,MAAM;OAExB,WAAU,YAAY;AACrB,UAAM,QAAQ,OAAO;AACrB,2BAAuB,KAAK;KAC3B;AAGH,OAAI,OAAO,SAAS,SAAS,WAC5B,WAAU,QAAQ,cAAc,EAAE,MAAM,QAAQ,MAAM,CAAC,CAAC;YAC9C,OAAO,SAAS,SAAS,SACnC,WAAU,QAAQ,cAAc,QAAQ,KAAK,CAAC;OAE9C,WAAU,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,CAAC,CAAC;;EAGvD,SAAS;GACR,SAAS;AACR,cAAU,QAAQ,MAAM;AACxB,cAAU,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,CAAC,CAAC;;GAEtD,SAAS;AACR,cAAU,QAAQ,MAAM;;GAEzB,OAAO;AACN,cAAU,YAAY;AACrB,WAAM,QAAQ,OAAO;AACrB,4BAAuB,KAAK;MAC3B;AACF,cAAU,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,CAAC,CAAC;;GAEtD,MAAM,QAAQ;AACb,cAAU,YAAY;AACrB,WAAM,QAAQ,OAAO;AACrB,4BAAuB,KAAK;MAC3B;AACF,cAAU,QAAQ,cAAc,OAAO,CAAC;;GAEzC;EACD,WAAW,EACV,MAAM,QAAQ;AACb,SAAM,QAAQ,OAAO;KAEtB;EACD,WAAW;GACV,MAAM,qBAAqB;AAC1B,WAAO,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,CAAC,EAAE;;GAEpD,cAAc,QAAQ;AACrB,WAAO,QAAQ,cAAc,OAAO;;GAErC;EACD"}
@@ -0,0 +1,10 @@
1
+ import { VisClientConfigurator } from "./create_vis.mjs";
2
+
3
+ //#region src/setup/vis.d.ts
4
+ /**
5
+ * Visual test configuration on the client side.
6
+ */
7
+ declare const vis: VisClientConfigurator<unknown>;
8
+ //#endregion
9
+ export { vis };
10
+ //# sourceMappingURL=vis.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis.d.mts","names":[],"sources":["../../src/setup/vis.ts"],"sourcesContent":[],"mappings":";;;;;;AAMa,cAAA,GAAyB,EAAA,qBAAtB,CAAA,OAAA,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { createVis } from "./create_vis.mjs";
2
+ import { commands } from "vitest/browser";
3
+
4
+ //#region src/setup/vis.ts
5
+ /**
6
+ * Visual test configuration on the client side.
7
+ */
8
+ const vis = createVis(commands);
9
+
10
+ //#endregion
11
+ export { vis };
12
+ //# sourceMappingURL=vis.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis.mjs","names":[],"sources":["../../src/setup/vis.ts"],"sourcesContent":["import { commands } from 'vitest/browser'\nimport { createVis } from './create_vis.ts'\n\n/**\n * Visual test configuration on the client side.\n */\nexport const vis = createVis(commands)\n"],"mappings":";;;;;;;AAMA,MAAa,MAAM,UAAU,SAAS"}
@@ -0,0 +1,4 @@
1
+ import "./client/expect/extend.mjs";
2
+ import "./client/page/extend.mjs";
3
+ import { VisClientConfigurator, createVis } from "./setup/create_vis.mjs";
4
+ export { VisClientConfigurator, createVis };
@@ -0,0 +1,5 @@
1
+ import "./client/expect/extend.mjs";
2
+ import "./client/page/extend.mjs";
3
+ import { createVis } from "./setup/create_vis.mjs";
4
+
5
+ export { createVis };
package/dist/setup.d.mts CHANGED
@@ -1,110 +1,13 @@
1
- import { n as ComparisonMethod, x as SnapshotMeta } from "./types-DFb23VE1.mjs";
2
- import "./vis_server_context.types-Ce1f9vOO.mjs";
3
- import "./types-Do1N7g4c.mjs";
4
- import { t as SetupVisSuiteCommand } from "./setup_vis_suite-C6JGGT7B.mjs";
5
- import "./to_match_image_snapshot.types-p-zilA_M.mjs";
6
- import "./augment-BJmy1S7i.mjs";
1
+ import { createVis as createVis$1 } from "./setup/create_vis.mjs";
2
+ import "./setup-api.mjs";
3
+ import { vis } from "./setup/vis.mjs";
4
+
5
+ //#region src/setup.d.ts
7
6
 
8
- //#region src/client/setup/create_vis.d.ts
9
- type SetupVisOptions<GM extends Record<string, any> | unknown = unknown> = {
10
- auto?: boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void) | Record<string, boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>;
11
- };
12
- /**
13
- * Visual test configuration on the client side.
14
- */
15
- type VisClientConfigurator<GM extends Record<string, any> | unknown = unknown> = {
16
- /**
17
- * Setup the visual test configuration.
18
- *
19
- * @example
20
- * ```ts
21
- * // Setup with auto snapshot enabled
22
- * vis().setup({ auto: true })
23
- *
24
- * // Setup with auto snapshot disabled
25
- * vis().setup({ auto: false })
26
- *
27
- * // Same as `vis.setup({ auto: false })`
28
- * vis.setup()
29
- *
30
- * // Setup with auto snapshot determined by the test meta
31
- * vis.setup({
32
- * auto: async ({ meta }) => meta['darkOnly'],
33
- * })
34
- *
35
- * // Setup with multiple auto snapshots
36
- * vis.setup({
37
- * auto: {
38
- * async light() { document.body.classList.remove('dark') },
39
- * async dark() { document.body.classList.add('dark') },
40
- * }
41
- * })
42
- * ```
43
- */
44
- setup(options?: SetupVisOptions<GM>): void;
45
- /**
46
- * @deprecated Use `vis.setup()` instead.
47
- */
48
- presets: {
49
- /**
50
- * @deprecated Use `vis.setup()` instead.
51
- *
52
- * Enable visual testing.
53
- *
54
- * auto snapshot is turned off by default.
55
- * You can specify the test to take a snapshot during `afterEach()` hook with `setAutoSnapshotOptions()`.
56
- */
57
- enable(): void;
58
- /**
59
- * @deprecated Use `vis.setup()` instead.
60
- *
61
- * Enable visual testing.
62
- *
63
- * `setAutoSnapshotOptions` will have no effect in this preset.
64
- */
65
- manual(): void;
66
- /**
67
- * @deprecated Use `vis.setup()` instead.
68
- *
69
- * Enable automatic visual testing.
70
- *
71
- * This will take a snapshot after each test.
72
- */
73
- auto(): void;
74
- /**
75
- * @deprecated Use `vis.setup()` instead.
76
- *
77
- * Enable automatic visual testing with multiple themes.
78
- *
79
- * This will take a snapshot after each test for each theme.
80
- *
81
- * @param themes A record of theme names and their setup functions.
82
- *
83
- * @example
84
- * ```ts
85
- * vis().presets.theme({
86
- * light() { document.body.classList.add('light') },
87
- * dark() { document.body.classList.add('dark') },
88
- * })
89
- * ```
90
- */
91
- theme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(themes: Record<string, boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>): void;
92
- };
93
- beforeAll: {
94
- setup(): Promise<void>;
95
- };
96
- afterEach: {
97
- matchImageSnapshot(): Promise<void>;
98
- matchPerTheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(themes: Record<string, boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>): () => Promise<void>;
99
- };
100
- };
101
- declare function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand): VisClientConfigurator<GM>;
102
- //#endregion
103
- //#region src/client/setup/vis.d.ts
104
7
  /**
105
- * Visual test configuration on the client side.
8
+ * @deprecated Use `createVis` from `vitest-plugin-vis/setup-api` instead.
106
9
  */
107
- declare const vis: VisClientConfigurator<unknown>;
10
+ declare const createVis: typeof createVis$1;
108
11
  //#endregion
109
- export { SetupVisOptions, VisClientConfigurator, createVis, vis };
12
+ export { createVis, vis };
110
13
  //# sourceMappingURL=setup.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.mts","names":[],"sources":["../src/client/setup/create_vis.ts","../src/client/setup/vis.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAUY,2BAA2B;+BAGvB,4BAA4B,kDAC/B,aAAa,KAAK,IAAI,OAC1B,mBAAmB,kCACxB,qCAGc,4BAA4B,kDAC/B,aAAa,KAAK,IAAI,OAC1B,mBAAmB;;;;AAX9B;AAAuC,KAkB3B,qBAlB2B,CAAA,WAkBM,MAlBN,CAAA,MAAA,EAAA,GAAA,CAAA,GAAA,OAAA,GAAA,OAAA,CAAA,GAAA;EAGvB;;;;;;;;;;;;;;;;;;AAehB;;;;;;;;;;EA+EsD,KAAA,CAAA,OAAA,CAAA,EAlDrC,eAkDqC,CAlDrB,EAkDqB,CAAA,CAAA,EAAA,IAAA;EAAmB;;;EAQjD,OAAA,EAAA;IACE;;;;;;;;IACf,MAAA,EAAA,EAAA,IAAA;IAIA;;AAIX;;;;;IAA4G,MAAA,EAAA,EAAA,IAAA;;;;ACvH5G;;;;;;;;;;;;;;;;;;;;;;oBDkGkB,4BAA4B,iDACnC,oCAEc,aAAa,KAAK,IAAI,OAAO,mBAAmB;;;aAK9D;;;0BAGa;4BACE,4BAA4B,iDAC3C,oCAEc,aAAa,KAAK,IAAI,OAAO,mBAAmB,yCAE9D;;;iBAIK,qBAAqB,mDAAmD,uBAAoB,sBAAA;;;;;;cCvH/F,KAAyB"}
1
+ {"version":3,"file":"setup.d.mts","names":[],"sources":["../src/setup.ts"],"sourcesContent":[],"mappings":";;;;;;;;AASA;cAAa,kBAAS"}
package/dist/setup.mjs CHANGED
@@ -1,8 +1,13 @@
1
- import "./asserts--HSSlgPD.mjs";
2
- import "./constants-CTBaz8Ml.mjs";
3
- import "./auto_snapshot_options-CAD43Zkp.mjs";
4
- import "./base64-CHSENEAO.mjs";
5
- import "./task_id-DnS9_4Ub.mjs";
6
- import { n as createVis, t as vis } from "./setup-BWgIDtv-.mjs";
1
+ import { createVis as createVis$1 } from "./setup/create_vis.mjs";
2
+ import "./setup-api.mjs";
3
+ import { vis } from "./setup/vis.mjs";
7
4
 
8
- export { createVis, vis };
5
+ //#region src/setup.ts
6
+ /**
7
+ * @deprecated Use `createVis` from `vitest-plugin-vis/setup-api` instead.
8
+ */
9
+ const createVis = createVis$1;
10
+
11
+ //#endregion
12
+ export { createVis, vis };
13
+ //# sourceMappingURL=setup.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.mjs","names":["createVisDeprecated"],"sources":["../src/setup.ts"],"sourcesContent":["import './setup-api.ts'\n\nexport * from './setup/vis.ts'\n\nimport { createVis as createVisDeprecated } from './setup/create_vis.ts'\n\n/**\n * @deprecated Use `createVis` from `vitest-plugin-vis/setup-api` instead.\n */\nexport const createVis = createVisDeprecated\n"],"mappings":";;;;;;;;AASA,MAAa,YAAYA"}
@@ -4,5 +4,5 @@ function assertSnapshotKeyWithoutDash(snapshotKey) {
4
4
  }
5
5
 
6
6
  //#endregion
7
- export { assertSnapshotKeyWithoutDash as t };
8
- //# sourceMappingURL=asserts--HSSlgPD.mjs.map
7
+ export { assertSnapshotKeyWithoutDash };
8
+ //# sourceMappingURL=asserts.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asserts.mjs","names":[],"sources":["../../src/shared/asserts.ts"],"sourcesContent":["export function assertSnapshotKeyWithoutDash(snapshotKey: string | undefined) {\n\tif (snapshotKey?.includes('-')) {\n\t\tthrow new Error('Snapshot key cannot contain dash')\n\t}\n}\n"],"mappings":";AAAA,SAAgB,6BAA6B,aAAiC;AAC7E,KAAI,aAAa,SAAS,IAAI,CAC7B,OAAM,IAAI,MAAM,mCAAmC"}
@@ -4,5 +4,5 @@ function isBase64String(value) {
4
4
  }
5
5
 
6
6
  //#endregion
7
- export { isBase64String as t };
8
- //# sourceMappingURL=base64-CHSENEAO.mjs.map
7
+ export { isBase64String };
8
+ //# sourceMappingURL=base64.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.mjs","names":[],"sources":["../../src/shared/base64.ts"],"sourcesContent":["export function isBase64String(value: unknown): value is string {\n\treturn typeof value === 'string' && /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/.test(value)\n}\n"],"mappings":";AAAA,SAAgB,eAAe,OAAiC;AAC/D,QAAO,OAAO,UAAU,YAAY,mEAAmE,KAAK,MAAM"}
@@ -0,0 +1,51 @@
1
+ import { ImageSnapshotComparisonInfo, MatchImageSnapshotOptions } from "./types.mjs";
2
+ import { VisOptions } from "../config/types.mjs";
3
+ import { Pick } from "type-plus";
4
+
5
+ //#region src/shared/commands.types.d.ts
6
+ interface PrepareImageSnapshotComparisonCommand {
7
+ prepareImageSnapshotComparison: (taskId: string, subject: string, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo>;
8
+ }
9
+ interface PreparePageImageSnapshotComparisonCommand {
10
+ preparePageImageSnapshotComparison: (taskId: string, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo>;
11
+ }
12
+ interface SetupVisSuiteCommand {
13
+ /**
14
+ * Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
15
+ * When this command is run for the first time,
16
+ * it will remove the results and diffs directory of all suites.
17
+ *
18
+ * In subsequent runs, it will only remove the results and diffs directory of the current suite.
19
+ */
20
+ setupVisSuite: () => Promise<Pick<VisOptions, 'comparisonMethod' | 'diffOptions' | 'failureThreshold' | 'failureThresholdType' | 'snapshotKey' | 'subject' | 'timeout'>>;
21
+ }
22
+ interface LoadImageSnapshotResultsCommand {
23
+ loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>;
24
+ }
25
+ interface ImageSnapshotResult {
26
+ filename: string;
27
+ /**
28
+ * The base64 encoded image of the baseline snapshot.
29
+ */
30
+ baseline?: string | undefined;
31
+ /**
32
+ * The base64 encoded image of the result snapshot.
33
+ */
34
+ result?: string | undefined;
35
+ /**
36
+ * The base64 encoded image of the diff snapshot.
37
+ */
38
+ diff?: string | undefined;
39
+ }
40
+ interface HasImageSnapshotCommand {
41
+ hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>;
42
+ }
43
+ interface ImageSnapshotNextIndexCommand {
44
+ /**
45
+ * Get the index of the snapshot image to be created.
46
+ */
47
+ imageSnapshotNextIndex(taskId: string): Promise<number>;
48
+ }
49
+ //#endregion
50
+ export { HasImageSnapshotCommand, ImageSnapshotNextIndexCommand, ImageSnapshotResult, LoadImageSnapshotResultsCommand, PrepareImageSnapshotComparisonCommand, PreparePageImageSnapshotComparisonCommand, SetupVisSuiteCommand };
51
+ //# sourceMappingURL=commands.types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.types.d.mts","names":[],"sources":["../../src/shared/commands.types.ts"],"sourcesContent":[],"mappings":";;;;;UAIiB,qCAAA;8EAIL,0CACN,QAAQ;AALd;AAIY,UAIK,yCAAA,CAJL;EACE,kCAAA,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAMF,yBANE,GAAA,SAAA,EAAA,GAOR,OAPQ,CAOA,2BAPA,CAAA;;AAAD,UAUI,oBAAA,CAVJ;EAGI;;;;;AAOjB;;EASE,aAAA,EAAA,GAAA,GADoB,OACpB,CAAA,IAAA,CACC,UADD,EAAA,kBAAA,GAAA,aAAA,GAAA,kBAAA,GAAA,sBAAA,GAAA,aAAA,GAAA,SAAA,GAAA,SAAA,CAAA,CAAA;;AAD2B,UAcZ,+BAAA,CAdY;EAcZ,wBAAA,CAAA,MAAA,EAAA,MAA+B,CAAA,EACL,OAAQ,CAAA,mBAAR,EAAA,CAAA;AAG3C;AAgBiB,UAhBA,mBAAA,CAgBuB;EAIvB,QAAA,EAAA,MAAA;;;;;;;;;;;;;;UAJA,uBAAA;qEACmD;;UAGnD,6BAAA;;;;0CAIwB"}