vitest-plugin-vis 2.4.3 → 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 -135
  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 -198
  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,21 @@
1
+ import type { BrowserCommand } from 'vitest/node';
2
+ export interface ImageSnapshotResult {
3
+ filename: string;
4
+ /**
5
+ * The base64 encoded image of the baseline snapshot.
6
+ */
7
+ baseline?: string | undefined;
8
+ /**
9
+ * The base64 encoded image of the result snapshot.
10
+ */
11
+ result?: string | undefined;
12
+ /**
13
+ * The base64 encoded image of the diff snapshot.
14
+ */
15
+ diff?: string | undefined;
16
+ }
17
+ export interface LoadImageSnapshotResultsCommand {
18
+ loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>;
19
+ }
20
+ export declare const loadImageSnapshotResults: BrowserCommand<[taskId: string]>;
21
+ //# sourceMappingURL=load_image_snapshot_results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load_image_snapshot_results.d.ts","sourceRoot":"","sources":["../../../src/server/commands/load_image_snapshot_results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACzB;AAED,MAAM,WAAW,+BAA+B;IAC/C,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAA;CACxE;AAED,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAOrE,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { visServerContext } from "../vis_server_context.js";
2
+ import { assertTestPathDefined } from "./_assertions.js";
3
+ export const loadImageSnapshotResults = async (context, taskId) => {
4
+ assertTestPathDefined(context, 'loadImageSnapshotResults');
5
+ return visServerContext.getSnapshotResults(context, taskId);
6
+ };
@@ -1,7 +1,7 @@
1
1
  import type { BrowserCommand } from 'vitest/node';
2
2
  import type { FailureThresholdOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions } from '../../shared/types.ts';
3
- import type { MatchImageSnapshotOptions } from './match_image_snapshot.ts';
4
- type ImageSnapshotComparisonInfo = {
3
+ import type { MatchImageSnapshotOptions } from './types.ts';
4
+ export type ImageSnapshotComparisonInfo = {
5
5
  /**
6
6
  * Path to the project root.
7
7
  */
@@ -26,15 +26,13 @@ type ImageSnapshotComparisonInfo = {
26
26
  * Base64 encoded result image.
27
27
  */
28
28
  result: string;
29
+ /**
30
+ * Base64 encoded diff image.
31
+ */
32
+ diff?: string | undefined;
29
33
  } & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions);
30
34
  export interface PrepareImageSnapshotComparisonCommand {
31
- prepareImageSnapshotComparison: (taskId: string | undefined, subject: string, isAutoSnapshot: boolean, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo | undefined>;
35
+ prepareImageSnapshotComparison: (taskId: string, subject: string, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo | undefined>;
32
36
  }
33
- export declare const prepareImageSnapshotComparison: BrowserCommand<[
34
- taskId: string,
35
- snapshotId: string,
36
- isAutoSnapshot: boolean,
37
- options?: MatchImageSnapshotOptions | undefined
38
- ]>;
39
- export {};
37
+ export declare const prepareImageSnapshotComparison: BrowserCommand<Parameters<PrepareImageSnapshotComparisonCommand['prepareImageSnapshotComparison']>>;
40
38
  //# sourceMappingURL=prepare_image_snapshot_comparison.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepare_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAE1E,KAAK,2BAA2B,GAAG;IAClC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;CACd,GAAG,2BAA2B,GAC9B,uBAAuB,GACvB,CAAC,qBAAqB,GAAG,sBAAsB,CAAC,CAAA;AAEjD,MAAM,WAAW,qCAAqC;IACrD,8BAA8B,EAAE,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,OAAO,EACvB,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAAA;CACrD;AAED,eAAO,MAAM,8BAA8B,EAAE,cAAc,CAC1D;IAAC,MAAM,EAAE,MAAM;IAAE,UAAU,EAAE,MAAM;IAAE,cAAc,EAAE,OAAO;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CA0B9G,CAAA"}
1
+ {"version":3,"file":"prepare_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,uBAAuB,CAAA;AAO9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAE3D,MAAM,MAAM,2BAA2B,GAAG;IACzC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACzB,GAAG,2BAA2B,GAC9B,uBAAuB,GACvB,CAAC,qBAAqB,GAAG,sBAAsB,CAAC,CAAA;AAEjD,MAAM,WAAW,qCAAqC;IACrD,8BAA8B,EAAE,CAC/B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAAA;CACrD;AAED,eAAO,MAAM,8BAA8B,EAAE,cAAc,CAC1D,UAAU,CAAC,qCAAqC,CAAC,gCAAgC,CAAC,CAAC,CA2BnF,CAAA"}
@@ -1,28 +1,30 @@
1
1
  import { resolve } from 'pathe';
2
2
  import { isBase64String } from "../../shared/base64.js";
3
- import { file } from "../file.js";
4
- import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from "../snapshot.js";
5
- import { visContext } from "../vis_context.js";
3
+ import { file } from "../externals/file.js";
4
+ import { getProjectRoot } from "../project.js";
5
+ import { takeSnapshot, takeSnapshotByBrowser } from "../snapshot.js";
6
+ import { snapshotWriter } from "../snapshot_writer.js";
7
+ import { visServerContext } from "../vis_server_context.js";
6
8
  import { assertTestPathDefined } from "./_assertions.js";
7
- export const prepareImageSnapshotComparison = async (context, taskId, subject, isAutoSnapshot, options) => {
9
+ export const prepareImageSnapshotComparison = async (context, taskId, subject, options) => {
8
10
  assertTestPathDefined(context, 'prepareImageSnapshotComparison');
9
11
  // vitest:browser passes in `null` when not defined
10
12
  if (!options)
11
13
  options = {};
12
14
  options.timeout = options.timeout ?? 30000;
13
- const projectRoot = context.project.config.root;
14
- const info = await visContext.getSnapshotInfo(context, taskId, isAutoSnapshot, options);
15
+ const projectRoot = getProjectRoot(context);
16
+ const info = await visServerContext.getSnapshotInfo(context, taskId, options);
15
17
  const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath));
16
18
  if (!baselineBuffer) {
17
19
  if (isBase64String(subject)) {
18
- await writeSnapshot(resolve(projectRoot, info.baselinePath), subject);
20
+ await snapshotWriter.writeBase64(resolve(projectRoot, info.baselinePath), subject);
19
21
  }
20
22
  else {
21
- await takeSnapshotByBrowser(context, resolve(projectRoot, info.baselinePath), subject, options);
23
+ await takeSnapshotByBrowser(context, projectRoot, info.baselinePath, subject, options);
22
24
  }
23
25
  return;
24
26
  }
25
- const resultBuffer = await takeSnapshot(context, resolve(projectRoot, info.resultPath), subject, options);
27
+ const resultBuffer = await takeSnapshot(context, projectRoot, info.resultPath, subject, options);
26
28
  return {
27
29
  ...info,
28
30
  projectRoot,
@@ -0,0 +1,35 @@
1
+ import type { BrowserCommand } from 'vitest/node';
2
+ import type { FailureThresholdOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions } from '../../shared/types.ts';
3
+ import type { MatchImageSnapshotOptions } from './types.ts';
4
+ type ImageSnapshotComparisonInfo = {
5
+ /**
6
+ * Path to the project root.
7
+ */
8
+ projectRoot: string;
9
+ /**
10
+ * Path to the baseline image relative to the project root.
11
+ */
12
+ baselinePath: string;
13
+ /**
14
+ * Path to the result image relative to the project root.
15
+ */
16
+ resultPath: string;
17
+ /**
18
+ * Path to the diff image relative to the project root.
19
+ */
20
+ diffPath: string;
21
+ /**
22
+ * Base64 encoded baseline image.
23
+ */
24
+ baseline: string;
25
+ /**
26
+ * Base64 encoded result image.
27
+ */
28
+ result: string;
29
+ } & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions);
30
+ export interface PreparePageImageSnapshotComparisonCommand {
31
+ preparePageImageSnapshotComparison: (taskId: string, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo | undefined>;
32
+ }
33
+ export declare const preparePageImageSnapshotComparison: BrowserCommand<Parameters<PreparePageImageSnapshotComparisonCommand['preparePageImageSnapshotComparison']>>;
34
+ export {};
35
+ //# sourceMappingURL=prepare_page_image_snapshot_comparison.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare_page_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_page_image_snapshot_comparison.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,uBAAuB,CAAA;AAM9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAE3D,KAAK,2BAA2B,GAAG;IAClC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;CACd,GAAG,2BAA2B,GAC9B,uBAAuB,GACvB,CAAC,qBAAqB,GAAG,sBAAsB,CAAC,CAAA;AAEjD,MAAM,WAAW,yCAAyC;IACzD,kCAAkC,EAAE,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAAA;CACrD;AAED,eAAO,MAAM,kCAAkC,EAAE,cAAc,CAC9D,UAAU,CAAC,yCAAyC,CAAC,oCAAoC,CAAC,CAAC,CAsB3F,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { resolve } from 'pathe';
2
+ import { file } from "../externals/file.js";
3
+ import { getProjectRoot } from "../project.js";
4
+ import { takePageSnapshot } from "../snapshot.js";
5
+ import { visServerContext } from "../vis_server_context.js";
6
+ import { assertTestPathDefined } from "./_assertions.js";
7
+ export const preparePageImageSnapshotComparison = async (context, taskId, options) => {
8
+ assertTestPathDefined(context, 'preparePageImageSnapshotComparison');
9
+ // vitest:browser passes in `null` when not defined
10
+ if (!options)
11
+ options = {};
12
+ options.timeout = options.timeout ?? 30000;
13
+ const projectRoot = getProjectRoot(context);
14
+ const info = await visServerContext.getSnapshotInfo(context, taskId, options);
15
+ const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath));
16
+ if (!baselineBuffer) {
17
+ await takePageSnapshot(context, projectRoot, info.baselinePath, options);
18
+ return;
19
+ }
20
+ const resultBuffer = await takePageSnapshot(context, projectRoot, info.resultPath, options);
21
+ return {
22
+ ...info,
23
+ projectRoot,
24
+ baseline: baselineBuffer.toString('base64'),
25
+ result: resultBuffer.toString('base64'),
26
+ };
27
+ };
@@ -1,4 +1,6 @@
1
+ import type { Pick } from 'type-plus';
1
2
  import type { BrowserCommand } from 'vitest/node';
3
+ import type { VisOptions } from '../../config/types.ts';
2
4
  export interface SetupVisSuiteCommand {
3
5
  /**
4
6
  * Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
@@ -7,9 +9,7 @@ export interface SetupVisSuiteCommand {
7
9
  *
8
10
  * In subsequent runs, it will only remove the results and diffs directory of the current suite.
9
11
  */
10
- setupVisSuite: () => Promise<{
11
- subjectDataTestId: string | undefined;
12
- }>;
12
+ setupVisSuite: () => Promise<Pick<VisOptions, 'comparisonMethod' | 'diffOptions' | 'failureThreshold' | 'failureThresholdType' | 'snapshotKey' | 'subject' | 'timeout'>>;
13
13
  }
14
14
  export declare const setupVisSuite: BrowserCommand<[]>;
15
15
  //# sourceMappingURL=setup_vis_suite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup_vis_suite.d.ts","sourceRoot":"","sources":["../../../src/server/commands/setup_vis_suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,OAAO,CAAC;QAAE,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC,CAAA;CACvE;AAED,eAAO,MAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAM5C,CAAA"}
1
+ {"version":3,"file":"setup_vis_suite.d.ts","sourceRoot":"","sources":["../../../src/server/commands/setup_vis_suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAIvD,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,OAAO,CAC3B,IAAI,CACH,UAAU,EACR,kBAAkB,GAClB,aAAa,GACb,kBAAkB,GAClB,sBAAsB,GACtB,aAAa,GACb,SAAS,GACT,SAAS,CACX,CACD,CAAA;CACD;AAED,eAAO,MAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAG5C,CAAA"}
@@ -1,7 +1,6 @@
1
- import { visContext } from "../vis_context.js";
1
+ import { setupSuite } from "../suite.js";
2
2
  import { assertTestPathDefined } from "./_assertions.js";
3
3
  export const setupVisSuite = async (context) => {
4
4
  assertTestPathDefined(context, 'setupVisSuite');
5
- // using props not currently listed in the types
6
- return visContext.setupSuite(context);
5
+ return setupSuite(context);
7
6
  };
@@ -0,0 +1,3 @@
1
+ import type { ImageSnapshotCompareOptions, ImageSnapshotKeyOptions, ImageSnapshotTimeoutOptions } from '../../shared/types.ts';
2
+ export type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotCompareOptions<any> & ImageSnapshotKeyOptions;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/server/commands/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAE9B,MAAM,MAAM,yBAAyB,GAAG,2BAA2B,GAClE,2BAA2B,CAAC,GAAG,CAAC,GAChC,uBAAuB,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { type GlobOptionsWithFileTypesUnset } from 'glob';
2
+ import { writeFile } from 'node:fs/promises';
3
+ export declare const file: {
4
+ existFile(filePath: string): Promise<boolean>;
5
+ glob(pattern: string | string[], options?: GlobOptionsWithFileTypesUnset | undefined): Promise<string[]>;
6
+ mkdirp: (path: string) => Promise<string | undefined>;
7
+ tryReadFile(filePath: string | undefined): Promise<Buffer | undefined>;
8
+ writeFile: typeof writeFile;
9
+ };
10
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/server/externals/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,6BAA6B,EAAE,MAAM,MAAM,CAAA;AAE/D,OAAO,EAAkB,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5D,eAAO,MAAM,IAAI;wBACI,MAAM;kBAKZ,MAAM,GAAG,MAAM,EAAE,YAAY,6BAA6B,GAAG,SAAS;YAGlE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;0BACnC,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;;CAM5E,CAAA"}
@@ -1,12 +1,20 @@
1
+ import { glob } from 'glob';
2
+ import { mkdirp } from 'mkdirp';
1
3
  import { readFile, stat, writeFile } from 'node:fs/promises';
2
4
  export const file = {
3
- async tryReadFile(filePath) {
4
- return readFile(filePath).catch(() => undefined);
5
- },
6
- writeFile,
7
5
  existFile(filePath) {
8
6
  return stat(filePath)
9
7
  .then((s) => s.isFile())
10
8
  .catch(() => false);
11
9
  },
10
+ glob(pattern, options) {
11
+ return glob(pattern, options);
12
+ },
13
+ mkdirp: mkdirp,
14
+ async tryReadFile(filePath) {
15
+ if (!filePath)
16
+ return undefined;
17
+ return readFile(filePath).catch(() => undefined);
18
+ },
19
+ writeFile,
12
20
  };
@@ -1,4 +1,3 @@
1
- import type { BrowserCommandContext } from 'vitest/node';
2
1
  export declare function getProjectName(context: {
3
2
  project: {
4
3
  vite: {
@@ -10,5 +9,11 @@ export declare function getProjectName(context: {
10
9
  };
11
10
  };
12
11
  }): string | undefined;
13
- export declare function getBrowserInstanceProjectName(context: BrowserCommandContext): import("vitest/node").ResolvedConfig;
14
- //# sourceMappingURL=browser_command_context.d.ts.map
12
+ export declare function getProjectRoot(context: {
13
+ project: {
14
+ config: {
15
+ root: string;
16
+ };
17
+ };
18
+ }): string;
19
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/server/project.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,MAAM,EAAE;gBAAE,IAAI,CAAC,EAAE;oBAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;iBAAE,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,sBAElH;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE;QAAE,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,UAEhF"}
@@ -1,6 +1,6 @@
1
1
  export function getProjectName(context) {
2
2
  return context.project.vite.config.test?.name;
3
3
  }
4
- export function getBrowserInstanceProjectName(context) {
5
- return context.project.config;
4
+ export function getProjectRoot(context) {
5
+ return context.project.config.root;
6
6
  }
@@ -1,7 +1,6 @@
1
1
  import type { BrowserCommandContext } from 'vitest/node';
2
- import type { ImageSnapshotTimeoutOptions } from '../client.ts';
3
- export declare function takeSnapshot(context: BrowserCommandContext, filePath: string, subject: string, options: ImageSnapshotTimeoutOptions | undefined): Promise<Buffer<ArrayBufferLike>>;
4
- export declare function takeSnapshotByBrowser(context: BrowserCommandContext, filePath: string, subject: string, options: ImageSnapshotTimeoutOptions | undefined): Promise<Buffer<ArrayBufferLike>>;
5
- export declare function writeSnapshot(filePath: string, subject: string): Promise<void>;
6
- export declare function writeSnapshotBuffer(filePath: string, subject: Buffer): Promise<void>;
2
+ import type { ImageSnapshotTimeoutOptions, PageImageSnapshotOptions } from '../shared/types.ts';
3
+ export declare function takeSnapshot(context: BrowserCommandContext, projectRoot: string, relativeFilePath: string, subject: string, options: ImageSnapshotTimeoutOptions | undefined): Promise<Buffer<ArrayBufferLike>>;
4
+ export declare function takeSnapshotByBrowser(context: BrowserCommandContext, projectRoot: string, relativeFilePath: string, subject: string, options: ImageSnapshotTimeoutOptions | undefined): Promise<Buffer<ArrayBufferLike>>;
5
+ export declare function takePageSnapshot(context: BrowserCommandContext, projectRoot: string, relativeFilePath: string, options: (PageImageSnapshotOptions & ImageSnapshotTimeoutOptions) | undefined): Promise<Buffer<ArrayBufferLike>>;
7
6
  //# sourceMappingURL=snapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/server/snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AAK/D,wBAAsB,YAAY,CACjC,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,2BAA2B,GAAG,SAAS,oCAOhD;AAED,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,2BAA2B,GAAG,SAAS,oCAOhD;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAGpE;AACD,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAG1E"}
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/server/snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,KAAK,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAI/F,wBAAsB,YAAY,CACjC,OAAO,EAAE,qBAAqB,EAC9B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,2BAA2B,GAAG,SAAS,oCAOhD;AAED,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,qBAAqB,EAC9B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,2BAA2B,GAAG,SAAS,oCAQhD;AAED,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,CAAC,wBAAwB,GAAG,2BAA2B,CAAC,GAAG,SAAS,oCAS7E"}
@@ -1,27 +1,29 @@
1
1
  import { mkdirp } from 'mkdirp';
2
- import { dirname } from 'pathe';
2
+ import { dirname, resolve } from 'pathe';
3
3
  import { isBase64String } from "../shared/base64.js";
4
4
  import { browserApi } from "./browser_provider/browser_api.js";
5
- import { file } from './file.js';
6
- export async function takeSnapshot(context, filePath, subject, options) {
5
+ import { snapshotWriter } from "./snapshot_writer.js";
6
+ export async function takeSnapshot(context, projectRoot, relativeFilePath, subject, options) {
7
7
  if (isBase64String(subject)) {
8
- await writeSnapshot(filePath, subject);
8
+ await snapshotWriter.writeBase64(resolve(projectRoot, relativeFilePath), subject);
9
9
  return Buffer.from(subject, 'base64');
10
10
  }
11
- return takeSnapshotByBrowser(context, filePath, subject, options);
11
+ return takeSnapshotByBrowser(context, projectRoot, relativeFilePath, subject, options);
12
12
  }
13
- export async function takeSnapshotByBrowser(context, filePath, subject, options) {
13
+ export async function takeSnapshotByBrowser(context, projectRoot, relativeFilePath, subject, options) {
14
+ const filePath = resolve(projectRoot, relativeFilePath);
14
15
  await mkdirp(dirname(filePath));
15
16
  const browser = browserApi(context);
16
- return browser.takeScreenshot(filePath, subject ?? 'body', {
17
+ return browser.takeScreenshot(projectRoot, relativeFilePath, subject ?? 'body', {
17
18
  timeout: options?.timeout,
18
19
  });
19
20
  }
20
- export async function writeSnapshot(filePath, subject) {
21
+ export async function takePageSnapshot(context, projectRoot, relativeFilePath, options) {
22
+ const filePath = resolve(projectRoot, relativeFilePath);
21
23
  await mkdirp(dirname(filePath));
22
- await file.writeFile(filePath, subject, { encoding: 'base64' });
23
- }
24
- export async function writeSnapshotBuffer(filePath, subject) {
25
- await mkdirp(dirname(filePath));
26
- await file.writeFile(filePath, subject);
24
+ const browser = browserApi(context);
25
+ return browser.takePageScreenshot(projectRoot, relativeFilePath, {
26
+ timeout: options?.timeout,
27
+ fullPage: options?.fullPage,
28
+ });
27
29
  }
@@ -1,5 +1,5 @@
1
1
  import type { VisOptions } from '../config/types.ts';
2
- import type { PartialBrowserCommandContext } from './vis_context.types.ts';
3
- export declare function resolveSnapshotRootDir(suite: PartialBrowserCommandContext, options: VisOptions): string;
4
- export declare function getSnapshotSubpath(suiteName: string, options: Pick<VisOptions, 'customizeSnapshotSubpath'>): string;
2
+ import type { PartialBrowserCommandContext } from './vis_server_context.types.ts';
3
+ export declare function resolveSnapshotRootDir(browserCommandContext: PartialBrowserCommandContext, options: VisOptions): string;
4
+ export declare function getSnapshotSubpath(suiteName: string, options: Pick<VisOptions, 'snapshotSubpath'>): string;
5
5
  //# sourceMappingURL=snapshot_path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot_path.d.ts","sourceRoot":"","sources":["../../src/server/snapshot_path.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAE1E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,4BAA4B,EAAE,OAAO,EAAE,UAAU,UAY9F;AAKD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC,UAG1G"}
1
+ {"version":3,"file":"snapshot_path.d.ts","sourceRoot":"","sources":["../../src/server/snapshot_path.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAEjF,wBAAgB,sBAAsB,CAAC,qBAAqB,EAAE,4BAA4B,EAAE,OAAO,EAAE,UAAU,UAY9G;AAMD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,UAGjG"}
@@ -1,25 +1,26 @@
1
1
  import ci from 'is-ci';
2
+ import { platform } from 'node:process';
2
3
  import { SNAPSHOT_ROOT_DIR } from "../shared/constants.js";
3
4
  import { trimCommonFolder } from "../shared/trim_common_folder.js";
4
- export function resolveSnapshotRootDir(suite, options) {
5
+ export function resolveSnapshotRootDir(browserCommandContext, options) {
5
6
  if (!options.snapshotRootDir)
6
- return getSnapshotRootDir(SNAPSHOT_ROOT_DIR, options.platform);
7
+ return getSnapshotRootDir(SNAPSHOT_ROOT_DIR);
7
8
  const snapshotRootDir = options.snapshotRootDir;
8
9
  if (typeof snapshotRootDir === 'string')
9
- return getSnapshotRootDir(snapshotRootDir, options.platform);
10
+ return getSnapshotRootDir(snapshotRootDir);
10
11
  return snapshotRootDir({
11
12
  ci,
12
- browserName: suite.provider.browserName,
13
- providerName: suite.provider.name,
14
- platform: process.platform,
15
- screenshotFailures: suite.provider.options?.screenshotFailures,
16
- screenshotDirectory: suite.provider.options?.screenshotDirectory,
13
+ browserName: browserCommandContext.provider.browserName,
14
+ providerName: browserCommandContext.provider.name,
15
+ platform,
16
+ screenshotFailures: browserCommandContext.provider.options?.screenshotFailures,
17
+ screenshotDirectory: browserCommandContext.provider.options?.screenshotDirectory,
17
18
  });
18
19
  }
19
- function getSnapshotRootDir(snapshotRootDir, platform = process.platform) {
20
+ function getSnapshotRootDir(snapshotRootDir) {
20
21
  return `${snapshotRootDir}/${ci ? platform : 'local'}`;
21
22
  }
22
23
  export function getSnapshotSubpath(suiteName, options) {
23
- const customizeSnapshotSubpath = options.customizeSnapshotSubpath ?? trimCommonFolder;
24
- return customizeSnapshotSubpath(suiteName);
24
+ const customizeSnapshotSubpath = options.snapshotSubpath ?? (({ subpath }) => trimCommonFolder(subpath));
25
+ return customizeSnapshotSubpath({ subpath: suiteName });
25
26
  }
@@ -0,0 +1,13 @@
1
+ export interface SnapshotWriter {
2
+ writeBase64(filePath: string, data: string): Promise<void>;
3
+ writeBuffer(filePath: string, data: Buffer): Promise<void>;
4
+ }
5
+ export declare function createSnapshotWriter({ mkdirp, writeFile }?: {
6
+ existFile(filePath: string): Promise<boolean>;
7
+ glob(pattern: string | string[], options?: import("glob").GlobOptionsWithFileTypesUnset | undefined): Promise<string[]>;
8
+ mkdirp: (path: string) => Promise<string | undefined>;
9
+ tryReadFile(filePath: string | undefined): Promise<Buffer | undefined>;
10
+ writeFile: typeof import("fs/promises").writeFile;
11
+ }): SnapshotWriter;
12
+ export declare const snapshotWriter: SnapshotWriter;
13
+ //# sourceMappingURL=snapshot_writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot_writer.d.ts","sourceRoot":"","sources":["../../src/server/snapshot_writer.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC9B,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1D,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1D;AAED,wBAAgB,oBAAoB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE;;;;;;CAAO,GAAG,cAAc,CAWjF;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { dirname } from 'pathe';
2
+ import { file } from "./externals/file.js";
3
+ export function createSnapshotWriter({ mkdirp, writeFile } = file) {
4
+ return {
5
+ async writeBase64(filePath, data) {
6
+ await mkdirp(dirname(filePath));
7
+ await writeFile(filePath, data, { encoding: 'base64' });
8
+ },
9
+ async writeBuffer(filePath, data) {
10
+ await mkdirp(dirname(filePath));
11
+ await writeFile(filePath, data);
12
+ },
13
+ };
14
+ }
15
+ export const snapshotWriter = createSnapshotWriter();
@@ -0,0 +1,53 @@
1
+ import type { VisOptions } from '../config/types.ts';
2
+ import type { PartialBrowserCommandContext, VisSuite } from './vis_server_context.types.ts';
3
+ /**
4
+ * Setup suite is called on each test file's beforeAll hook.
5
+ * Test files include vitest test files and storybook story files.
6
+ * It needs to make sure there is no race condition between the test files.
7
+ */
8
+ export declare function setupSuite(browserContext: PartialBrowserCommandContext): Promise<{
9
+ comparisonMethod: any;
10
+ diffOptions: Partial<import("ssim.js/dist/types.js").Options> | {
11
+ threshold?: number | undefined;
12
+ includeAA?: boolean | undefined;
13
+ alpha?: number | undefined;
14
+ aaColor?: [number, number, number] | undefined;
15
+ diffColor?: [number, number, number] | undefined;
16
+ diffColorAlt?: [number, number, number] | undefined;
17
+ diffMask?: boolean | undefined;
18
+ } | undefined;
19
+ failureThreshold: number | undefined;
20
+ failureThresholdType: "pixel" | "percent" | undefined;
21
+ snapshotKey: string | undefined;
22
+ subject: string | undefined;
23
+ timeout: number | undefined;
24
+ }>;
25
+ /**
26
+ * Suite ID also contains the project name to make it unique
27
+ * across different projects.
28
+ */
29
+ export declare function getSuiteId(context: {
30
+ project: {
31
+ config: {
32
+ root: string;
33
+ name: string;
34
+ };
35
+ vite: {
36
+ config: {
37
+ test?: {
38
+ name?: string | undefined;
39
+ };
40
+ };
41
+ };
42
+ };
43
+ }): string;
44
+ export declare function createModule(state: VisSuite, testPath: string, options: Pick<VisOptions, 'snapshotSubpath'>): {
45
+ taskSubpath: string;
46
+ baselineDir: string;
47
+ resultDir: string;
48
+ diffDir: string;
49
+ tasks: {};
50
+ };
51
+ export declare function getTaskSubpath(state: VisSuite, testPath: string, options: Pick<VisOptions, 'snapshotSubpath'>): string;
52
+ export declare function getSuite(context: PartialBrowserCommandContext): Promise<VisSuite>;
53
+ //# sourceMappingURL=suite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suite.d.ts","sourceRoot":"","sources":["../../src/server/suite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAMpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,QAAQ,EAAa,MAAM,+BAA+B,CAAA;AAItG;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,cAAc,EAAE,4BAA4B;;;;;;;;;;;;;;;;GA2B5E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE;IACnC,OAAO,EAAE;QAAE,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,IAAI,EAAE;YAAE,MAAM,EAAE;gBAAE,IAAI,CAAC,EAAE;oBAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;iBAAE,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CAC/G,UAEA;AAyBD,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC;;;;;;EAS3G;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,UAE7G;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,4BAA4B,qBAE7D"}
@@ -0,0 +1,73 @@
1
+ import { join, relative } from 'pathe';
2
+ import { BASELINE_DIR, DIFF_DIR, RESULT_DIR } from "../shared/constants.js";
3
+ import { getProjectName, getProjectRoot } from "./project.js";
4
+ import { getSnapshotSubpath, resolveSnapshotRootDir } from "./snapshot_path.js";
5
+ import { getVisOption } from "./vis_options.js";
6
+ import { deps } from "./vis_server_context.deps.js";
7
+ const suites = {};
8
+ /**
9
+ * Setup suite is called on each test file's beforeAll hook.
10
+ * Test files include vitest test files and storybook story files.
11
+ * It needs to make sure there is no race condition between the test files.
12
+ */
13
+ export async function setupSuite(browserContext) {
14
+ const suiteId = getSuiteId(browserContext);
15
+ const visOptions = getVisOption(browserContext);
16
+ if (!suites[suiteId]) {
17
+ suites[suiteId] = createSuite(browserContext, visOptions);
18
+ }
19
+ const suite = await suites[suiteId];
20
+ const { taskSubpath, baselineDir, diffDir, resultDir, tasks } = createModule(suite, browserContext.testPath, visOptions);
21
+ suite.modules[taskSubpath] = { baselineDir, diffDir, resultDir, tasks };
22
+ await Promise.allSettled([deps.rimraf(diffDir), deps.rimraf(resultDir)]);
23
+ return {
24
+ comparisonMethod: visOptions.comparisonMethod,
25
+ diffOptions: visOptions.diffOptions,
26
+ failureThreshold: visOptions.failureThreshold,
27
+ failureThresholdType: visOptions.failureThresholdType,
28
+ snapshotKey: visOptions.snapshotKey,
29
+ subject: visOptions.subject,
30
+ timeout: visOptions.timeout,
31
+ };
32
+ }
33
+ /**
34
+ * Suite ID also contains the project name to make it unique
35
+ * across different projects.
36
+ */
37
+ export function getSuiteId(context) {
38
+ return `${getProjectName(context)}/${context.project.config.name}`;
39
+ }
40
+ async function createSuite(browserContext, visOptions) {
41
+ const snapshotRootDir = resolveSnapshotRootDir(browserContext, visOptions);
42
+ const projectRoot = getProjectRoot(browserContext);
43
+ const state = {
44
+ projectRoot,
45
+ testTimeout: browserContext.project.config.testTimeout,
46
+ hookTimeout: browserContext.project.config.hookTimeout,
47
+ snapshotRootDir,
48
+ snapshotBaselineDir: join(snapshotRootDir, BASELINE_DIR),
49
+ snapshotResultDir: join(snapshotRootDir, RESULT_DIR),
50
+ snapshotDiffDir: join(snapshotRootDir, DIFF_DIR),
51
+ snapshotRootPath: join(projectRoot, snapshotRootDir),
52
+ subject: visOptions.subject,
53
+ modules: {},
54
+ };
55
+ await Promise.allSettled([deps.rimraf(join(state.snapshotDiffDir)), deps.rimraf(join(state.snapshotResultDir))]);
56
+ return state;
57
+ }
58
+ export function createModule(state, testPath, options) {
59
+ const taskSubpath = getTaskSubpath(state, testPath, options);
60
+ return {
61
+ taskSubpath,
62
+ baselineDir: join(state.snapshotBaselineDir, taskSubpath),
63
+ resultDir: join(state.snapshotResultDir, taskSubpath),
64
+ diffDir: join(state.snapshotDiffDir, taskSubpath),
65
+ tasks: {},
66
+ };
67
+ }
68
+ export function getTaskSubpath(state, testPath, options) {
69
+ return getSnapshotSubpath(relative(state.projectRoot, testPath), options);
70
+ }
71
+ export function getSuite(context) {
72
+ return suites[getSuiteId(context)];
73
+ }
@@ -0,0 +1,18 @@
1
+ import type { VisOptions } from '../config/types.ts';
2
+ export declare function setVisOption(userConfig: {
3
+ test?: {
4
+ name?: string | undefined;
5
+ } | undefined;
6
+ }, options: VisOptions<any> | undefined): void;
7
+ export declare function getVisOption(context: {
8
+ project: {
9
+ vite: {
10
+ config: {
11
+ test?: {
12
+ name?: string | undefined;
13
+ };
14
+ };
15
+ };
16
+ };
17
+ }): VisOptions<any>;
18
+ //# sourceMappingURL=vis_options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis_options.d.ts","sourceRoot":"","sources":["../../src/server/vis_options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAQpD,wBAAgB,YAAY,CAC3B,UAAU,EAAE;IAAE,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAA;CAAE,EAChE,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,SAAS,QAQpC;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACrC,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,MAAM,EAAE;gBAAE,IAAI,CAAC,EAAE;oBAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;iBAAE,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CACvE,mBAIA"}