vitest-plugin-vis 2.4.4 → 3.0.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 (264) hide show
  1. package/esm/client/actions/has_image_snapshot_action.d.ts +4 -0
  2. package/esm/client/actions/has_image_snapshot_action.d.ts.map +1 -0
  3. package/esm/client/actions/has_image_snapshot_action.js +6 -0
  4. package/esm/client/actions/load_image_snapshot_results_action.d.ts +3 -0
  5. package/esm/client/actions/load_image_snapshot_results_action.d.ts.map +1 -0
  6. package/esm/client/actions/load_image_snapshot_results_action.js +3 -0
  7. package/esm/client/actions/match_image_snapshot_action.d.ts +6 -0
  8. package/esm/client/actions/match_image_snapshot_action.d.ts.map +1 -0
  9. package/esm/client/actions/match_image_snapshot_action.js +20 -0
  10. package/esm/client/actions/match_page_image_snapshot_action.d.ts +6 -0
  11. package/esm/client/actions/match_page_image_snapshot_action.d.ts.map +1 -0
  12. package/esm/client/actions/match_page_image_snapshot_action.js +9 -0
  13. package/esm/client/auto_snapshot_options.d.ts +29 -0
  14. package/esm/client/auto_snapshot_options.d.ts.map +1 -0
  15. package/esm/client/auto_snapshot_options.js +49 -0
  16. package/esm/client/compare_image_snapshot.d.ts +6 -0
  17. package/esm/client/compare_image_snapshot.d.ts.map +1 -0
  18. package/esm/client/compare_image_snapshot.js +52 -0
  19. package/esm/client/{image_snapshot_matcher.logic.d.ts → compare_image_snapshot.logic.d.ts} +1 -1
  20. package/esm/client/compare_image_snapshot.logic.d.ts.map +1 -0
  21. package/esm/client/expect/to_match_image_snapshot.d.ts.map +1 -1
  22. package/esm/client/expect/to_match_image_snapshot.js +4 -3
  23. package/esm/client/image_resizer.d.ts.map +1 -1
  24. package/esm/client/image_snapshot_options.d.ts +2 -0
  25. package/esm/client/image_snapshot_options.d.ts.map +1 -0
  26. package/esm/client/image_snapshot_options.js +6 -0
  27. package/esm/client/page/augment.d.ts +2 -1
  28. package/esm/client/page/augment.d.ts.map +1 -1
  29. package/esm/client/page/extend.js +2 -1
  30. package/esm/client/page/has_image_snapshot.d.ts +6 -6
  31. package/esm/client/page/has_image_snapshot.d.ts.map +1 -1
  32. package/esm/client/page/has_image_snapshot.js +2 -11
  33. package/esm/client/page/to_match_image_snapshot.d.ts +8 -0
  34. package/esm/client/page/to_match_image_snapshot.d.ts.map +1 -0
  35. package/esm/client/page/to_match_image_snapshot.js +15 -0
  36. package/esm/client/setup/create_vis.d.ts +96 -0
  37. package/esm/client/setup/create_vis.d.ts.map +1 -0
  38. package/esm/{setup → client/setup}/create_vis.js +43 -31
  39. package/esm/client/setup/vis.ctx.d.ts +12 -0
  40. package/esm/client/setup/vis.ctx.d.ts.map +1 -0
  41. package/esm/client/setup/vis.ctx.js +32 -0
  42. package/esm/client/setup/vis.d.ts +5 -0
  43. package/esm/client/setup/vis.d.ts.map +1 -0
  44. package/esm/client/should_take_snapshot.d.ts +2 -9
  45. package/esm/client/should_take_snapshot.d.ts.map +1 -1
  46. package/esm/client/should_take_snapshot.js +1 -11
  47. package/esm/client/snapshot_meta.d.ts +6 -0
  48. package/esm/client/snapshot_meta.d.ts.map +1 -0
  49. package/esm/client/task_id.d.ts +0 -3
  50. package/esm/client/task_id.d.ts.map +1 -1
  51. package/esm/client/task_id.js +0 -3
  52. package/esm/client/vitest_suite_proxy.d.ts +2 -9
  53. package/esm/client/vitest_suite_proxy.d.ts.map +1 -1
  54. package/esm/client-api.d.ts +11 -0
  55. package/esm/client-api.d.ts.map +1 -0
  56. package/esm/client-api.js +8 -0
  57. package/esm/commands.d.ts +0 -1
  58. package/esm/commands.d.ts.map +1 -1
  59. package/esm/commands.js +0 -1
  60. package/esm/config/types.d.ts +22 -22
  61. package/esm/config/types.d.ts.map +1 -1
  62. package/esm/config/vis.d.ts +4 -3
  63. package/esm/config/vis.d.ts.map +1 -1
  64. package/esm/config/vis.js +3 -4
  65. package/esm/index.d.ts +1 -1
  66. package/esm/index.d.ts.map +1 -1
  67. package/esm/index.js +1 -1
  68. package/esm/presets/auto.d.ts +1 -2
  69. package/esm/presets/auto.d.ts.map +1 -1
  70. package/esm/presets/auto.js +8 -4
  71. package/esm/presets/enable.d.ts +1 -2
  72. package/esm/presets/enable.d.ts.map +1 -1
  73. package/esm/presets/enable.js +4 -4
  74. package/esm/presets/manual.d.ts +1 -2
  75. package/esm/presets/manual.d.ts.map +1 -1
  76. package/esm/presets/manual.js +3 -4
  77. package/esm/server/browser_provider/playwright.d.ts.map +1 -1
  78. package/esm/server/browser_provider/playwright.js +9 -3
  79. package/esm/server/browser_provider/types.d.ts +5 -1
  80. package/esm/server/browser_provider/types.d.ts.map +1 -1
  81. package/esm/server/browser_provider/webdriverio.d.ts.map +1 -1
  82. package/esm/server/browser_provider/webdriverio.js +7 -4
  83. package/esm/server/commands/augment.d.ts +11 -0
  84. package/esm/server/commands/augment.d.ts.map +1 -0
  85. package/esm/server/commands/augment.js +1 -0
  86. package/esm/server/commands/commands.d.ts +9 -0
  87. package/esm/server/commands/commands.d.ts.map +1 -0
  88. package/esm/server/commands/commands.js +14 -0
  89. package/esm/server/commands/has_image_snapshot.d.ts +2 -6
  90. package/esm/server/commands/has_image_snapshot.d.ts.map +1 -1
  91. package/esm/server/commands/has_image_snapshot.js +3 -3
  92. package/esm/server/commands/image_snapshot_next_index.d.ts +1 -1
  93. package/esm/server/commands/image_snapshot_next_index.d.ts.map +1 -1
  94. package/esm/server/commands/image_snapshot_next_index.js +2 -2
  95. package/esm/server/commands/load_image_snapshot_results.d.ts +21 -0
  96. package/esm/server/commands/load_image_snapshot_results.d.ts.map +1 -0
  97. package/esm/server/commands/load_image_snapshot_results.js +6 -0
  98. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +8 -10
  99. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
  100. package/esm/server/commands/prepare_image_snapshot_comparison.js +11 -9
  101. package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts +35 -0
  102. package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts.map +1 -0
  103. package/esm/server/commands/prepare_page_image_snapshot_comparison.js +27 -0
  104. package/esm/server/commands/setup_vis_suite.d.ts +3 -3
  105. package/esm/server/commands/setup_vis_suite.d.ts.map +1 -1
  106. package/esm/server/commands/setup_vis_suite.js +2 -3
  107. package/esm/server/commands/types.d.ts +3 -0
  108. package/esm/server/commands/types.d.ts.map +1 -0
  109. package/esm/server/commands/types.js +1 -0
  110. package/esm/server/externals/file.d.ts +10 -0
  111. package/esm/server/externals/file.d.ts.map +1 -0
  112. package/esm/server/{file.js → externals/file.js} +12 -4
  113. package/esm/server/{commands/browser_command_context.d.ts → project.d.ts} +8 -3
  114. package/esm/server/project.d.ts.map +1 -0
  115. package/esm/server/{commands/browser_command_context.js → project.js} +2 -2
  116. package/esm/server/snapshot.d.ts +4 -5
  117. package/esm/server/snapshot.d.ts.map +1 -1
  118. package/esm/server/snapshot.js +15 -13
  119. package/esm/server/snapshot_path.d.ts +3 -3
  120. package/esm/server/snapshot_path.d.ts.map +1 -1
  121. package/esm/server/snapshot_path.js +12 -11
  122. package/esm/server/snapshot_writer.d.ts +13 -0
  123. package/esm/server/snapshot_writer.d.ts.map +1 -0
  124. package/esm/server/snapshot_writer.js +15 -0
  125. package/esm/server/suite.d.ts +53 -0
  126. package/esm/server/suite.d.ts.map +1 -0
  127. package/esm/server/suite.js +73 -0
  128. package/esm/server/vis_options.d.ts +18 -0
  129. package/esm/server/vis_options.d.ts.map +1 -0
  130. package/esm/server/vis_options.js +14 -0
  131. package/esm/server/vis_server_context.d.ts +50 -0
  132. package/esm/server/vis_server_context.d.ts.map +1 -0
  133. package/esm/server/{vis_context.ctx.d.ts → vis_server_context.deps.d.ts} +2 -2
  134. package/esm/server/vis_server_context.deps.d.ts.map +1 -0
  135. package/esm/server/{vis_context.ctx.js → vis_server_context.deps.js} +1 -1
  136. package/esm/server/vis_server_context.js +2 -0
  137. package/esm/server/{vis_context.logic.d.ts → vis_server_context.logic.d.ts} +12 -32
  138. package/esm/server/vis_server_context.logic.d.ts.map +1 -0
  139. package/esm/server/vis_server_context.logic.js +79 -0
  140. package/esm/server/{vis_context.types.d.ts → vis_server_context.types.d.ts} +6 -6
  141. package/esm/server/vis_server_context.types.d.ts.map +1 -0
  142. package/esm/server/vis_server_context.types.js +1 -0
  143. package/esm/server-utils.d.ts +3 -0
  144. package/esm/server-utils.d.ts.map +1 -0
  145. package/esm/server-utils.js +2 -0
  146. package/esm/setup.d.ts +2 -2
  147. package/esm/setup.d.ts.map +1 -1
  148. package/esm/setup.js +2 -2
  149. package/esm/shared/asserts.d.ts +2 -0
  150. package/esm/shared/asserts.d.ts.map +1 -0
  151. package/esm/shared/asserts.js +5 -0
  152. package/esm/shared/types.d.ts +22 -21
  153. package/esm/shared/types.d.ts.map +1 -1
  154. package/esm/testing/stubBrowserCommandContext.d.ts +1 -1
  155. package/esm/testing/stubBrowserCommandContext.d.ts.map +1 -1
  156. package/esm/testing/stubBrowserCommandContext.js +3 -13
  157. package/esm/testing/stubSuite.d.ts +10 -0
  158. package/esm/testing/stubSuite.d.ts.map +1 -0
  159. package/esm/testing/stubSuite.js +27 -0
  160. package/esm/testing/stubUserConfig.d.ts +7 -0
  161. package/esm/testing/stubUserConfig.d.ts.map +1 -0
  162. package/esm/testing/stubUserConfig.js +4 -0
  163. package/package.json +29 -28
  164. package/readme.md +409 -110
  165. package/src/client/actions/has_image_snapshot_action.ts +14 -0
  166. package/src/client/actions/load_image_snapshot_results_action.ts +5 -0
  167. package/src/client/actions/match_image_snapshot_action.ts +32 -0
  168. package/src/client/actions/match_page_image_snapshot_action.ts +20 -0
  169. package/src/client/auto_snapshot_options.ts +71 -0
  170. package/src/client/compare_image_snapshot.ts +84 -0
  171. package/src/client/expect/to_match_image_snapshot.ts +4 -3
  172. package/src/client/image_snapshot_options.ts +6 -0
  173. package/src/client/page/augment.ts +2 -1
  174. package/src/client/page/extend.ts +2 -1
  175. package/src/client/page/has_image_snapshot.ts +8 -21
  176. package/src/client/page/to_match_image_snapshot.ts +27 -0
  177. package/src/client/setup/create_vis.ts +227 -0
  178. package/src/client/setup/vis.ctx.ts +33 -0
  179. package/src/client/should_take_snapshot.ts +3 -13
  180. package/src/client/snapshot_meta.ts +7 -0
  181. package/src/client/task_id.ts +0 -3
  182. package/src/client/vitest_suite_proxy.ts +2 -5
  183. package/src/client-api.ts +11 -0
  184. package/src/commands.ts +0 -1
  185. package/src/config/types.ts +32 -27
  186. package/src/config/vis.ts +3 -5
  187. package/src/index.ts +1 -1
  188. package/src/presets/auto.ts +8 -4
  189. package/src/presets/enable.ts +4 -4
  190. package/src/presets/manual.ts +3 -4
  191. package/src/server/browser_provider/playwright.ts +9 -3
  192. package/src/server/browser_provider/types.ts +12 -1
  193. package/src/server/browser_provider/webdriverio.ts +7 -4
  194. package/src/server/commands/augment.ts +16 -0
  195. package/src/server/commands/commands.ts +15 -0
  196. package/src/server/commands/has_image_snapshot.ts +8 -6
  197. package/src/server/commands/image_snapshot_next_index.ts +5 -3
  198. package/src/server/commands/load_image_snapshot_results.ts +32 -0
  199. package/src/server/commands/prepare_image_snapshot_comparison.ts +20 -14
  200. package/src/server/commands/prepare_page_image_snapshot_comparison.ts +75 -0
  201. package/src/server/commands/setup_vis_suite.ts +17 -7
  202. package/src/server/commands/types.ts +9 -0
  203. package/src/server/externals/file.ts +21 -0
  204. package/src/server/{commands/browser_command_context.ts → project.ts} +2 -4
  205. package/src/server/snapshot.ts +23 -14
  206. package/src/server/snapshot_path.ts +15 -13
  207. package/src/server/snapshot_writer.ts +22 -0
  208. package/src/server/suite.ts +96 -0
  209. package/src/server/vis_options.ts +27 -0
  210. package/src/server/{vis_context.ctx.ts → vis_server_context.deps.ts} +1 -1
  211. package/src/server/vis_server_context.logic.ts +112 -0
  212. package/src/server/vis_server_context.ts +3 -0
  213. package/src/server/{vis_context.types.ts → vis_server_context.types.ts} +5 -5
  214. package/src/server-utils.ts +2 -0
  215. package/src/setup.ts +2 -2
  216. package/src/shared/asserts.ts +5 -0
  217. package/src/shared/types.ts +25 -23
  218. package/src/testing/stubBrowserCommandContext.ts +4 -14
  219. package/src/testing/stubSuite.ts +38 -0
  220. package/src/testing/stubUserConfig.ts +6 -0
  221. package/esm/client/image_snapshot_matcher.d.ts +0 -11
  222. package/esm/client/image_snapshot_matcher.d.ts.map +0 -1
  223. package/esm/client/image_snapshot_matcher.js +0 -80
  224. package/esm/client/image_snapshot_matcher.logic.d.ts.map +0 -1
  225. package/esm/client/snapshot_options.d.ts +0 -33
  226. package/esm/client/snapshot_options.d.ts.map +0 -1
  227. package/esm/client/snapshot_options.js +0 -37
  228. package/esm/client.d.ts +0 -8
  229. package/esm/client.d.ts.map +0 -1
  230. package/esm/client.js +0 -5
  231. package/esm/server/commands/browser_command_context.d.ts.map +0 -1
  232. package/esm/server/commands/extend.d.ts +0 -17
  233. package/esm/server/commands/extend.d.ts.map +0 -1
  234. package/esm/server/commands/extend.js +0 -12
  235. package/esm/server/commands/match_image_snapshot.d.ts +0 -18
  236. package/esm/server/commands/match_image_snapshot.d.ts.map +0 -1
  237. package/esm/server/commands/match_image_snapshot.js +0 -81
  238. package/esm/server/file.d.ts +0 -7
  239. package/esm/server/file.d.ts.map +0 -1
  240. package/esm/server/vis_context.ctx.d.ts.map +0 -1
  241. package/esm/server/vis_context.d.ts +0 -56
  242. package/esm/server/vis_context.d.ts.map +0 -1
  243. package/esm/server/vis_context.js +0 -2
  244. package/esm/server/vis_context.logic.d.ts.map +0 -1
  245. package/esm/server/vis_context.logic.js +0 -137
  246. package/esm/server/vis_context.types.d.ts.map +0 -1
  247. package/esm/setup/create_vis.d.ts +0 -53
  248. package/esm/setup/create_vis.d.ts.map +0 -1
  249. package/esm/setup/vis.d.ts +0 -5
  250. package/esm/setup/vis.d.ts.map +0 -1
  251. package/src/client/image_snapshot_matcher.ts +0 -121
  252. package/src/client/snapshot_options.ts +0 -82
  253. package/src/client.ts +0 -7
  254. package/src/server/commands/extend.ts +0 -25
  255. package/src/server/commands/match_image_snapshot.ts +0 -128
  256. package/src/server/file.ts +0 -13
  257. package/src/server/vis_context.logic.ts +0 -200
  258. package/src/server/vis_context.ts +0 -3
  259. package/src/setup/create_vis.ts +0 -154
  260. /package/esm/client/{image_snapshot_matcher.logic.js → compare_image_snapshot.logic.js} +0 -0
  261. /package/esm/{setup → client/setup}/vis.js +0 -0
  262. /package/esm/{server/vis_context.types.js → client/snapshot_meta.js} +0 -0
  263. /package/src/client/{image_snapshot_matcher.logic.ts → compare_image_snapshot.logic.ts} +0 -0
  264. /package/src/{setup → client/setup}/vis.ts +0 -0
@@ -0,0 +1,4 @@
1
+ import type { HasImageSnapshotCommand, ImageSnapshotNextIndexCommand } from '../../commands.ts';
2
+ import type { ImageSnapshotKeyOptions } from '../../shared/types.ts';
3
+ export declare function hasImageSnapshotAction(commands: ImageSnapshotNextIndexCommand & HasImageSnapshotCommand, taskId: string, options?: ImageSnapshotKeyOptions | undefined): Promise<boolean>;
4
+ //# sourceMappingURL=has_image_snapshot_action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has_image_snapshot_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/has_image_snapshot_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,wBAAgB,sBAAsB,CACrC,QAAQ,EAAE,6BAA6B,GAAG,uBAAuB,EACjE,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,uBAAuB,GAAG,SAAS,oBAO7C"}
@@ -0,0 +1,6 @@
1
+ export function hasImageSnapshotAction(commands, taskId, options) {
2
+ if (options?.snapshotKey?.includes('-')) {
3
+ throw new Error('Snapshot key cannot contain dash');
4
+ }
5
+ return commands.hasImageSnapshot(taskId, options?.snapshotKey);
6
+ }
@@ -0,0 +1,3 @@
1
+ import type { LoadImageSnapshotResultsCommand } from '../../server/commands/load_image_snapshot_results.ts';
2
+ export declare function loadImageSnapshotResultsAction(commands: LoadImageSnapshotResultsCommand, taskId: string): Promise<import("../../server/commands/load_image_snapshot_results.ts").ImageSnapshotResult[]>;
3
+ //# sourceMappingURL=load_image_snapshot_results_action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load_image_snapshot_results_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/load_image_snapshot_results_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,sDAAsD,CAAA;AAE3G,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,+BAA+B,EAAE,MAAM,EAAE,MAAM,iGAEvG"}
@@ -0,0 +1,3 @@
1
+ export function loadImageSnapshotResultsAction(commands, taskId) {
2
+ return commands.loadImageSnapshotResults(taskId);
3
+ }
@@ -0,0 +1,6 @@
1
+ import type { BrowserCommands } from '@vitest/browser/context';
2
+ import type { ImageSnapshotNextIndexCommand } from '../../commands.ts';
3
+ import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts';
4
+ import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts';
5
+ export declare function matchImageSnapshotAction(commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand, taskId: string, subject: any, options?: ToMatchImageSnapshotOptions<any>): Promise<void>;
6
+ //# sourceMappingURL=match_image_snapshot_action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match_image_snapshot_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/match_image_snapshot_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,4DAA4D,CAAA;AAGvH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAIxE,wBAAsB,wBAAwB,CAC7C,QAAQ,EAAE,eAAe,GAAG,qCAAqC,GAAG,6BAA6B,EACjG,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,2BAA2B,CAAC,GAAG,CAAC,iBAS1C"}
@@ -0,0 +1,20 @@
1
+ import { assertSnapshotKeyWithoutDash } from "../../shared/asserts.js";
2
+ import { isBase64String } from "../../shared/base64.js";
3
+ import { compareImageSnapshot } from "../compare_image_snapshot.js";
4
+ import { convertElementToCssSelector } from "../selector.js";
5
+ export async function matchImageSnapshotAction(commands, taskId, subject, options) {
6
+ assertSnapshotKeyWithoutDash(options?.snapshotKey);
7
+ const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options);
8
+ if (!info)
9
+ return;
10
+ return compareImageSnapshot(commands, taskId, info, options);
11
+ }
12
+ function parseImageSnapshotSubject(subject) {
13
+ if (subject instanceof Element)
14
+ return convertElementToCssSelector(subject);
15
+ if (subject?.['selector'])
16
+ return subject['selector'];
17
+ if (isBase64String(subject))
18
+ return subject;
19
+ throw new Error(`'toMatchImageSnapshot()' expects the subject to be an element, locator, or image encoded in base64 string, but got: ${subject}`);
20
+ }
@@ -0,0 +1,6 @@
1
+ import type { BrowserCommands } from '@vitest/browser/context';
2
+ import type { ImageSnapshotNextIndexCommand } from '../../commands.ts';
3
+ import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts';
4
+ import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts';
5
+ export declare function matchPageImageSnapshotAction(commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand, taskId: string, options?: ToMatchImageSnapshotOptions<any>): Promise<void>;
6
+ //# sourceMappingURL=match_page_image_snapshot_action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match_page_image_snapshot_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/match_page_image_snapshot_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,4DAA4D,CAAA;AAEvH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAGxE,wBAAsB,4BAA4B,CACjD,QAAQ,EAAE,eAAe,GAAG,qCAAqC,GAAG,6BAA6B,EACjG,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,2BAA2B,CAAC,GAAG,CAAC,iBAS1C"}
@@ -0,0 +1,9 @@
1
+ import { assertSnapshotKeyWithoutDash } from "../../shared/asserts.js";
2
+ import { compareImageSnapshot } from "../compare_image_snapshot.js";
3
+ export async function matchPageImageSnapshotAction(commands, taskId, options) {
4
+ assertSnapshotKeyWithoutDash(options?.snapshotKey);
5
+ const info = await commands.preparePageImageSnapshotComparison(taskId, options);
6
+ if (!info)
7
+ return;
8
+ return compareImageSnapshot(commands, taskId, info, options);
9
+ }
@@ -0,0 +1,29 @@
1
+ import type { ComparisonMethod } from '../shared/types.ts';
2
+ import type { SnapshotMeta } from './snapshot_meta.ts';
3
+ type Suite = {
4
+ meta: Record<string, any>;
5
+ suite?: Suite | undefined;
6
+ };
7
+ export type MetaTask = {
8
+ file?: {
9
+ meta: Record<string, any>;
10
+ } | undefined;
11
+ suite?: Suite | undefined;
12
+ meta: Record<string, any>;
13
+ } | undefined;
14
+ /**
15
+ * Set the snapshot options for auto snapshot.
16
+ *
17
+ * ```ts
18
+ * beforeAll(() => setAutoSnapshotOptions(...))
19
+ * beforeEach(() => setAutoSnapshotOptions(...))
20
+ *
21
+ * it('...', () => {
22
+ * setAutoSnapshotOptions(...)
23
+ * })
24
+ * ```
25
+ */
26
+ export declare function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: SnapshotMeta<M> | boolean): void;
27
+ export declare function extractAutoSnapshotOptions<M extends SnapshotMeta<any> = SnapshotMeta<any>>(task: MetaTask): M | undefined;
28
+ export {};
29
+ //# sourceMappingURL=auto_snapshot_options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto_snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/auto_snapshot_options.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,CAAA;AAErE,MAAM,MAAM,QAAQ,GACjB;IACA,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,SAAS,CAAA;IAChD,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACxB,GACD,SAAS,CAAA;AAEZ;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,CAYxG;AAUD,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,EACzF,IAAI,EAAE,QAAQ,GACZ,CAAC,GAAG,SAAS,CAkBf"}
@@ -0,0 +1,49 @@
1
+ import { assertSnapshotKeyWithoutDash } from "../shared/asserts.js";
2
+ import { NAME } from "../shared/constants.js";
3
+ import { ctx } from "./ctx.js";
4
+ /**
5
+ * Set the snapshot options for auto snapshot.
6
+ *
7
+ * ```ts
8
+ * beforeAll(() => setAutoSnapshotOptions(...))
9
+ * beforeEach(() => setAutoSnapshotOptions(...))
10
+ *
11
+ * it('...', () => {
12
+ * setAutoSnapshotOptions(...)
13
+ * })
14
+ * ```
15
+ */
16
+ export function setAutoSnapshotOptions(meta) {
17
+ if (typeof meta === 'object') {
18
+ assertSnapshotKeyWithoutDash(meta.snapshotKey);
19
+ }
20
+ const task = getTask();
21
+ if (!task)
22
+ return;
23
+ task.meta[NAME] = {
24
+ ...task.meta[NAME],
25
+ ...parseMeta(meta),
26
+ };
27
+ }
28
+ function getTask() {
29
+ return ctx.getCurrentTest() ?? ctx.getCurrentSuite()?.tasks?.[0]?.file;
30
+ }
31
+ function parseMeta(meta) {
32
+ return typeof meta === 'boolean' ? { enable: meta } : { enable: true, ...meta };
33
+ }
34
+ export function extractAutoSnapshotOptions(task) {
35
+ if (!task)
36
+ return;
37
+ const list = [];
38
+ let current = task;
39
+ while (current?.suite) {
40
+ list.unshift(current.suite.meta);
41
+ current = current.suite;
42
+ }
43
+ list.unshift(task.file?.meta);
44
+ list.push(task.meta);
45
+ return list.reduce((acc, cur) => {
46
+ const meta = cur?.[NAME];
47
+ return meta ? Object.assign({}, acc, meta) : acc;
48
+ }, { enable: false });
49
+ }
@@ -0,0 +1,6 @@
1
+ import type { BrowserCommands } from '@vitest/browser/context';
2
+ import type { ImageSnapshotNextIndexCommand } from '../commands.ts';
3
+ import type { ImageSnapshotComparisonInfo, PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts';
4
+ import type { ToMatchImageSnapshotOptions } from '../shared/types.ts';
5
+ export declare function compareImageSnapshot(commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand, taskId: string, info: ImageSnapshotComparisonInfo, options?: ToMatchImageSnapshotOptions<any>): Promise<void>;
6
+ //# sourceMappingURL=compare_image_snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare_image_snapshot.d.ts","sourceRoot":"","sources":["../../src/client/compare_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAG9D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EACX,2BAA2B,EAC3B,qCAAqC,EACrC,MAAM,yDAAyD,CAAA;AAEhE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAMrE,wBAAsB,oBAAoB,CACzC,QAAQ,EAAE,eAAe,GAAG,qCAAqC,GAAG,6BAA6B,EACjG,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,2BAA2B,EACjC,OAAO,CAAC,EAAE,2BAA2B,CAAC,GAAG,CAAC,iBA2D1C"}
@@ -0,0 +1,52 @@
1
+ import dedent from 'dedent';
2
+ import { resolve } from 'pathe';
3
+ import { compareImage } from "../shared/compare_image.js";
4
+ import { alignImagesToSameSize } from "./align_images.js";
5
+ import { prettifyOptions } from "./compare_image_snapshot.logic.js";
6
+ import { toDataURL, toImageData } from "./image_data.js";
7
+ import { server } from "./vitest_browser_context_proxy.js";
8
+ export async function compareImageSnapshot(commands, taskId, info, options) {
9
+ options = { ...info, ...options };
10
+ const baselineImage = await toImageData(info.baseline);
11
+ const resultImage = await toImageData(info.result);
12
+ const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage);
13
+ const { width, height } = baselineAlignedImage;
14
+ const diffImage = new ImageData(width, height);
15
+ const { pass, diffAmount } = compareImage(baselineAlignedImage.data, resultAlignedImage.data, diffImage.data, width, height, options);
16
+ if (pass) {
17
+ if (options?.expectToFail) {
18
+ throw new Error(dedent `Snapshot \`${taskId}\` matched but expected to fail.
19
+
20
+ Options: ${prettifyOptions(options)}
21
+ Diff: ${options.failureThresholdType === 'percent' ? `${diffAmount}%` : `${diffAmount} pixels`}
22
+
23
+ Expected: ${resolve(info.projectRoot, info.baselinePath)}
24
+ Actual: ${resolve(info.projectRoot, info.resultPath)}`);
25
+ }
26
+ return;
27
+ }
28
+ if (server.config.snapshotOptions.updateSnapshot === 'all' && !options?.expectToFail) {
29
+ await writeSnapshot(commands, resolve(info.projectRoot, info.baselinePath), resultImage);
30
+ return;
31
+ }
32
+ await writeSnapshot(commands, resolve(info.projectRoot, info.diffPath), diffImage);
33
+ throw new Error(dedent `Snapshot \`${taskId}\` mismatched
34
+
35
+ ${options?.failureThreshold
36
+ ? options?.failureThresholdType === 'percent'
37
+ ? `Expected image to match within ${options.failureThreshold}% but was differ by ${diffAmount}%.`
38
+ : `Expected image to match within ${options.failureThreshold} pixels but was differ by ${diffAmount} pixels.`
39
+ : `Expected image to match but was differ by ${options?.failureThresholdType === 'percent' ? `${diffAmount}%` : `${diffAmount} pixels`}.`}${baselineImage.width !== resultImage.width || baselineImage.height !== resultImage.height
40
+ ? `\nThe image size changed from ${baselineImage.width}x${baselineImage.height} to ${resultImage.width}x${resultImage.height}.`
41
+ : ''}
42
+
43
+ Options: ${prettifyOptions(options)}
44
+
45
+ Expected: ${resolve(info.projectRoot, info.baselinePath)}
46
+ Actual: ${resolve(info.projectRoot, info.resultPath)}
47
+ Difference: ${resolve(info.projectRoot, info.diffPath)}`);
48
+ }
49
+ async function writeSnapshot(commands, path, image) {
50
+ const content = (await toDataURL(image)).split(',')[1];
51
+ return commands.writeFile(path, content, { encoding: 'base64' });
52
+ }
@@ -1,3 +1,3 @@
1
1
  import type { ToMatchImageSnapshotOptions } from '../shared/types.ts';
2
2
  export declare function prettifyOptions(options: ToMatchImageSnapshotOptions<any> | undefined): string;
3
- //# sourceMappingURL=image_snapshot_matcher.logic.d.ts.map
3
+ //# sourceMappingURL=compare_image_snapshot.logic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare_image_snapshot.logic.d.ts","sourceRoot":"","sources":["../../src/client/compare_image_snapshot.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAErE,wBAAgB,eAAe,CAAC,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,GAAG,SAAS,UAWpF"}
@@ -1 +1 @@
1
- {"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAKxE,wBAAgB,oBAAoB;AACnC;;;GAGG;AACH,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,GAC/C,sBAAsB,CAcxB"}
1
+ {"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAMxE,wBAAgB,oBAAoB;AACnC;;;GAGG;AACH,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,GAC/C,sBAAsB,CAcxB"}
@@ -1,6 +1,7 @@
1
1
  import { commands } from '@vitest/browser/context';
2
+ import { matchImageSnapshotAction } from "../actions/match_image_snapshot_action.js";
2
3
  import { ctx } from "../ctx.js";
3
- import { imageSnapshotMatcher } from "../image_snapshot_matcher.js";
4
+ import { toTaskId } from "../task_id.js";
4
5
  import { success } from "./expectation_result.js";
5
6
  export function toMatchImageSnapshot(
6
7
  /**
@@ -14,7 +15,7 @@ subject, options) {
14
15
  }
15
16
  if (test.concurrent) {
16
17
  throw new Error('`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +
17
- "concurrent tests run at the same time in the same iframe and affect each other's environment. ");
18
+ "concurrent tests run at the same time in the same iframe and affect each other's environment.");
18
19
  }
19
- return imageSnapshotMatcher(commands)(test, subject, options).then(() => success);
20
+ return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success);
20
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"image_resizer.d.ts","sourceRoot":"","sources":["../../src/client/image_resizer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,sBACV;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,aAC7C,SAAS,cA2BhB,CAAA;AAGF,eAAO,MAAM,mBAAmB,sBACX;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,aAC7C,SAAS,cAsBhB,CAAA"}
1
+ {"version":3,"file":"image_resizer.d.ts","sourceRoot":"","sources":["../../src/client/image_resizer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,GAC7B,mBAAmB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,MACpD,OAAO,SAAS,cA2BhB,CAAA;AAGF,eAAO,MAAM,mBAAmB,GAC9B,mBAAmB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,MACpD,OAAO,SAAS,cAsBhB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=image_snapshot_options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image_snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ // import type { ToMatchImageSnapshotOptions } from '../shared/types.ts'
2
+ export {};
3
+ // export function parseImageSnapshotOptions(taskId: string, options: ToMatchImageSnapshotOptions<any> | undefined) {
4
+ // const { snapshotKey, ...rest } = options ?? {}
5
+ // return snapshotKey ? { ...options, snapshotFileId: `${taskId}-${snapshotKey}` } : rest
6
+ // }
@@ -1,6 +1,7 @@
1
1
  import type { HasImageSnapshotAction } from './has_image_snapshot.ts';
2
+ import type { ToMatchImageSnapshotAction } from './to_match_image_snapshot.ts';
2
3
  declare module '@vitest/browser/context' {
3
- interface BrowserPage extends HasImageSnapshotAction {
4
+ interface BrowserPage extends HasImageSnapshotAction, ToMatchImageSnapshotAction {
4
5
  }
5
6
  }
6
7
  //# sourceMappingURL=augment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"augment.d.ts","sourceRoot":"","sources":["../../../src/client/page/augment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAErE,OAAO,QAAQ,yBAAyB,CAAC;IACxC,UAAU,WAAY,SAAQ,sBAAsB;KAAG;CACvD"}
1
+ {"version":3,"file":"augment.d.ts","sourceRoot":"","sources":["../../../src/client/page/augment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AAE9E,OAAO,QAAQ,yBAAyB,CAAC;IACxC,UAAU,WAAY,SAAQ,sBAAsB,EAAE,0BAA0B;KAAG;CACnF"}
@@ -1,4 +1,5 @@
1
1
  import { page } from '@vitest/browser/context';
2
2
  import "./augment.js";
3
3
  import { hasImageSnapshot } from "./has_image_snapshot.js";
4
- page.extend({ hasImageSnapshot });
4
+ import { toMatchImageSnapshot } from "./to_match_image_snapshot.js";
5
+ page.extend({ hasImageSnapshot, toMatchImageSnapshot });
@@ -1,10 +1,10 @@
1
1
  import { type BrowserPage } from '@vitest/browser/context';
2
- import type { ImageSnapshotIdOptions } from '../../shared/types.ts';
2
+ import type { ImageSnapshotKeyOptions } from '../../shared/types.ts';
3
3
  export interface HasImageSnapshotAction {
4
- hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotIdOptions | undefined): Promise<boolean>;
4
+ /**
5
+ * Check if the snapshot image exists.
6
+ */
7
+ hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOptions | undefined): Promise<boolean>;
5
8
  }
6
- /**
7
- * Check if the snapshot image exists.
8
- */
9
- export declare function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotIdOptions | undefined): Promise<boolean>;
9
+ export declare function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOptions | undefined): Promise<boolean>;
10
10
  //# sourceMappingURL=has_image_snapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAInE,MAAM,WAAW,sBAAsB;IACtC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACnG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,oBA2B/F"}
1
+ {"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAKpE,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACpG;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,SAAS,oBAahG"}
@@ -1,9 +1,7 @@
1
1
  import { commands } from '@vitest/browser/context';
2
+ import { hasImageSnapshotAction } from "../actions/has_image_snapshot_action.js";
2
3
  import { ctx } from "../ctx.js";
3
4
  import { toTaskId } from "../task_id.js";
4
- /**
5
- * Check if the snapshot image exists.
6
- */
7
5
  export function hasImageSnapshot(options) {
8
6
  const test = ctx.getCurrentTest();
9
7
  if (!test) {
@@ -13,12 +11,5 @@ export function hasImageSnapshot(options) {
13
11
  throw new Error('`hasImageSnapshot()` cannot be called in a concurrent test because ' +
14
12
  "concurrent tests run at the same time in the same iframe and affect each other's environment. ");
15
13
  }
16
- const taskId = toTaskId(test);
17
- const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot;
18
- if (options?.customizeSnapshotId) {
19
- return commands
20
- .imageSnapshotNextIndex(taskId)
21
- .then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot }), isAutoSnapshot));
22
- }
23
- return commands.hasImageSnapshot(taskId, undefined, isAutoSnapshot);
14
+ return hasImageSnapshotAction(commands, toTaskId(test), options);
24
15
  }
@@ -0,0 +1,8 @@
1
+ import type { PageImageSnapshotOptions, ToMatchImageSnapshotOptions } from '../../shared/types.ts';
2
+ export interface ToMatchPageImageSnapshotOptions extends ToMatchImageSnapshotOptions, PageImageSnapshotOptions {
3
+ }
4
+ export interface ToMatchImageSnapshotAction {
5
+ toMatchImageSnapshot(options?: ToMatchPageImageSnapshotOptions | undefined): Promise<void>;
6
+ }
7
+ export declare function toMatchImageSnapshot(options?: ToMatchPageImageSnapshotOptions | undefined): Promise<void>;
8
+ //# sourceMappingURL=to_match_image_snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAKlG,MAAM,WAAW,+BAAgC,SAAQ,2BAA2B,EAAE,wBAAwB;CAAG;AAEjH,MAAM,WAAW,0BAA0B;IAC1C,oBAAoB,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1F;AAED,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,SAAS,iBAczF"}
@@ -0,0 +1,15 @@
1
+ import { commands } from '@vitest/browser/context';
2
+ import { matchPageImageSnapshotAction } from "../actions/match_page_image_snapshot_action.js";
3
+ import { ctx } from "../ctx.js";
4
+ import { toTaskId } from "../task_id.js";
5
+ export function toMatchImageSnapshot(options) {
6
+ const test = ctx.getCurrentTest();
7
+ if (!test) {
8
+ throw new Error('`toMatchImageSnapshot()` must be called in a test.');
9
+ }
10
+ if (test.concurrent) {
11
+ throw new Error('`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +
12
+ "concurrent tests run at the same time in the same iframe and affect each other's environment.");
13
+ }
14
+ return matchPageImageSnapshotAction(commands, toTaskId(test), options);
15
+ }
@@ -0,0 +1,96 @@
1
+ import type { SetupVisSuiteCommand } from '../../server/commands/setup_vis_suite.ts';
2
+ import type { ComparisonMethod } from '../../shared/types.ts';
3
+ import type { SnapshotMeta } from '../snapshot_meta.ts';
4
+ /**
5
+ * Visual test configuration on the client side.
6
+ */
7
+ export type VisClientConfigurator<GM extends Record<string, any> | unknown = unknown> = {
8
+ /**
9
+ * Setup the visual test configuration.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // Setup with auto snapshot enabled
14
+ * vis().setup({ auto: true })
15
+ *
16
+ * // Setup with auto snapshot disabled
17
+ * vis().setup({ auto: false })
18
+ *
19
+ * // Same as `vis.setup({ auto: false })`
20
+ * vis.setup()
21
+ *
22
+ * // Setup with auto snapshot determined by the test meta
23
+ * vis.setup({
24
+ * auto: async ({ meta }) => meta['darkOnly'],
25
+ * })
26
+ *
27
+ * // Setup with multiple auto snapshots
28
+ * vis.setup({
29
+ * auto: {
30
+ * async light() { document.body.classList.remove('dark') },
31
+ * async dark() { document.body.classList.add('dark') },
32
+ * }
33
+ * })
34
+ * ```
35
+ */
36
+ setup(options?: {
37
+ auto?: boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => boolean | Promise<boolean>) | Record<string, boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => boolean | Promise<boolean>)>;
38
+ }): void;
39
+ /**
40
+ * @deprecated Use `vis.setup()` instead.
41
+ */
42
+ presets: {
43
+ /**
44
+ * @deprecated Use `vis.setup()` instead.
45
+ *
46
+ * Enable visual testing.
47
+ *
48
+ * auto snapshot is turned off by default.
49
+ * You can specify the test to take a snapshot during `afterEach()` hook with `setAutoSnapshotOptions()`.
50
+ */
51
+ enable(): void;
52
+ /**
53
+ * @deprecated Use `vis.setup()` instead.
54
+ *
55
+ * Enable visual testing.
56
+ *
57
+ * `setAutoSnapshotOptions` will have no effect in this preset.
58
+ */
59
+ manual(): void;
60
+ /**
61
+ * @deprecated Use `vis.setup()` instead.
62
+ *
63
+ * Enable automatic visual testing.
64
+ *
65
+ * This will take a snapshot after each test.
66
+ */
67
+ auto(): void;
68
+ /**
69
+ * @deprecated Use `vis.setup()` instead.
70
+ *
71
+ * Enable automatic visual testing with multiple themes.
72
+ *
73
+ * This will take a snapshot after each test for each theme.
74
+ *
75
+ * @param themes A record of theme names and their setup functions.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * vis().presets.theme({
80
+ * light() { document.body.classList.add('light') },
81
+ * dark() { document.body.classList.add('dark') },
82
+ * })
83
+ * ```
84
+ */
85
+ 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;
86
+ };
87
+ beforeAll: {
88
+ setup(): Promise<void>;
89
+ };
90
+ afterEach: {
91
+ matchImageSnapshot(): Promise<void>;
92
+ 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>;
93
+ };
94
+ };
95
+ export declare function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand): VisClientConfigurator<GM>;
96
+ //# sourceMappingURL=create_vis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_vis.d.ts","sourceRoot":"","sources":["../../../src/client/setup/create_vis.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAA;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAI7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGvD;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,IAAI;IACvF;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QACf,IAAI,CAAC,EACF,OAAO,GACP,CAAC,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAC/E,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAC5B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAChC,MAAM,CACN,MAAM,EACJ,OAAO,GACP,CAAC,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAC/E,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAC5B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CACjC,CAAA;KACJ,GAAG,IAAI,CAAA;IACR;;OAEG;IACH,OAAO,EAAE;QACR;;;;;;;WAOG;QACH,MAAM,IAAI,IAAI,CAAA;QACd;;;;;;WAMG;QACH,MAAM,IAAI,IAAI,CAAA;QACd;;;;;;WAMG;QACH,IAAI,IAAI,IAAI,CAAA;QACZ;;;;;;;;;;;;;;;;WAgBG;QACH,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAClF,MAAM,EAAE,MAAM,CACb,MAAM,EACN,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,CACpG,GACC,IAAI,CAAA;KACP,CAAA;IACD,SAAS,EAAE;QACV,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;KACtB,CAAA;IACD,SAAS,EAAE;QACV,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;QACnC,aAAa,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAC1F,MAAM,EAAE,MAAM,CACb,MAAM,EACN,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,CACpG,GACC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;KACtB,CAAA;CACD,CAAA;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,oBAAoB,6BAmG3G"}
@@ -1,12 +1,34 @@
1
1
  import dedent from 'dedent';
2
2
  import { afterEach, beforeAll } from 'vitest';
3
- import { toTaskId } from "../client.js";
4
- import { ctx } from "../client/ctx.js";
5
- import { shouldTakeSnapshot } from "../client/should_take_snapshot.js";
6
- import { enableAuto, extractAutoSnapshotOptions } from "../client/snapshot_options.js";
3
+ import { extractAutoSnapshotOptions, setAutoSnapshotOptions } from "../auto_snapshot_options.js";
4
+ import { ctx } from "../ctx.js";
5
+ import { shouldTakeSnapshot } from "../should_take_snapshot.js";
6
+ import { toTaskId } from "../task_id.js";
7
7
  export function createVis(commands) {
8
- let subjectDataTestId;
8
+ let subject;
9
9
  const vis = {
10
+ setup(options) {
11
+ if (!options || options.auto === false) {
12
+ beforeAll(vis.beforeAll.setup);
13
+ }
14
+ else {
15
+ beforeAll(async () => {
16
+ await vis.beforeAll.setup();
17
+ setAutoSnapshotOptions(true);
18
+ });
19
+ }
20
+ if (typeof options?.auto === 'function') {
21
+ afterEach(vis.afterEach.matchPerTheme({
22
+ auto: options.auto,
23
+ }));
24
+ }
25
+ else if (typeof options?.auto === 'object') {
26
+ afterEach(vis.afterEach.matchPerTheme(options.auto));
27
+ }
28
+ else {
29
+ afterEach(vis.afterEach.matchImageSnapshot);
30
+ }
31
+ },
10
32
  presets: {
11
33
  enable() {
12
34
  beforeAll(vis.beforeAll.setup);
@@ -16,30 +38,28 @@ export function createVis(commands) {
16
38
  beforeAll(vis.beforeAll.setup);
17
39
  },
18
40
  auto() {
19
- beforeAll(vis.beforeAll.setup);
41
+ beforeAll(async () => {
42
+ await vis.beforeAll.setup();
43
+ setAutoSnapshotOptions(true);
44
+ });
20
45
  afterEach(vis.afterEach.matchImageSnapshot);
21
- enableAuto();
22
46
  },
23
47
  theme(themes) {
24
- beforeAll(vis.beforeAll.setup);
48
+ beforeAll(async () => {
49
+ await vis.beforeAll.setup();
50
+ setAutoSnapshotOptions(true);
51
+ });
25
52
  afterEach(vis.afterEach.matchPerTheme(themes));
26
53
  },
27
54
  },
28
55
  beforeAll: {
29
56
  async setup() {
30
- subjectDataTestId = (await commands.setupVisSuite()).subjectDataTestId;
57
+ subject = (await commands.setupVisSuite()).subject;
31
58
  },
32
59
  },
33
60
  afterEach: {
34
61
  async matchImageSnapshot() {
35
- const test = ctx.getCurrentTest();
36
- if ((test?.result?.errors?.length ?? 0) > 0)
37
- return;
38
- const meta = extractAutoSnapshotOptions(test);
39
- if (!shouldTakeSnapshot(meta))
40
- return;
41
- test.meta.vis = { ...test.meta.vis, isAutoSnapshot: true };
42
- await test.context.expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta);
62
+ return vis.afterEach.matchPerTheme({ async auto() { } })();
43
63
  },
44
64
  matchPerTheme(themes) {
45
65
  return async function matchImageSnapshot() {
@@ -53,16 +73,13 @@ export function createVis(commands) {
53
73
  for (const themeId in themes) {
54
74
  try {
55
75
  await new Promise((a) => setTimeout(a, 10));
56
- const r = await themes[themeId](meta);
76
+ const theme = themes[themeId];
77
+ const r = typeof theme === 'function' ? await theme(meta) : theme;
57
78
  if (r === false)
58
79
  continue;
59
- await test.context
60
- .expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId))
61
- .toMatchImageSnapshot({
80
+ await test.context.expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
62
81
  ...meta,
63
- customizeSnapshotId: meta?.customizeSnapshotId
64
- ? ({ id, index }) => `${meta.customizeSnapshotId({ id, index, isAutoSnapshot: true })}-${themeId}`
65
- : ({ id }) => `${id}-${themeId}`,
82
+ snapshotKey: meta?.snapshotKey ?? themeId,
66
83
  });
67
84
  }
68
85
  catch (error) {
@@ -87,11 +104,6 @@ export function createVis(commands) {
87
104
  };
88
105
  return vis;
89
106
  }
90
- function getSubject(subjectDataTestId) {
91
- if (subjectDataTestId) {
92
- const subject = document.querySelector(`[data-testid="${subjectDataTestId}"]`);
93
- if (subject)
94
- return subject;
95
- }
96
- return document.body;
107
+ function getSubject(selectors) {
108
+ return selectors ? (document.querySelector(selectors) ?? document.body) : document.body;
97
109
  }