vitest-plugin-vis 3.5.1 → 4.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 (342) hide show
  1. package/dist/asserts--HSSlgPD.mjs +8 -0
  2. package/dist/asserts--HSSlgPD.mjs.map +1 -0
  3. package/dist/augment-BJmy1S7i.d.mts +31 -0
  4. package/dist/augment-BJmy1S7i.d.mts.map +1 -0
  5. package/dist/auto_snapshot_options-CAD43Zkp.mjs +90 -0
  6. package/dist/auto_snapshot_options-CAD43Zkp.mjs.map +1 -0
  7. package/dist/auto_snapshot_options-CaQCXDdi.d.mts +45 -0
  8. package/dist/auto_snapshot_options-CaQCXDdi.d.mts.map +1 -0
  9. package/dist/base64-CHSENEAO.mjs +8 -0
  10. package/dist/base64-CHSENEAO.mjs.map +1 -0
  11. package/dist/client-api.d.mts +141 -0
  12. package/dist/client-api.d.mts.map +1 -0
  13. package/dist/client-api.mjs +14 -0
  14. package/dist/client-api.mjs.map +1 -0
  15. package/dist/config.d.mts +28 -0
  16. package/dist/config.d.mts.map +1 -0
  17. package/dist/config.mjs +412 -0
  18. package/dist/config.mjs.map +1 -0
  19. package/dist/constants-CTBaz8Ml.mjs +10 -0
  20. package/dist/constants-CTBaz8Ml.mjs.map +1 -0
  21. package/dist/index.d.mts +5 -0
  22. package/dist/index.mjs +6 -0
  23. package/dist/presets/auto.d.mts +1 -0
  24. package/dist/presets/auto.mjs +19 -0
  25. package/dist/presets/auto.mjs.map +1 -0
  26. package/dist/presets/enable.d.mts +1 -0
  27. package/dist/presets/enable.mjs +15 -0
  28. package/dist/presets/enable.mjs.map +1 -0
  29. package/dist/presets/manual.d.mts +1 -0
  30. package/dist/presets/manual.mjs +15 -0
  31. package/dist/presets/manual.mjs.map +1 -0
  32. package/dist/server-utils.d.mts +19 -0
  33. package/dist/server-utils.d.mts.map +1 -0
  34. package/dist/server-utils.mjs +4 -0
  35. package/dist/setup-BWgIDtv-.mjs +141 -0
  36. package/dist/setup-BWgIDtv-.mjs.map +1 -0
  37. package/dist/setup.d.mts +110 -0
  38. package/dist/setup.d.mts.map +1 -0
  39. package/dist/setup.mjs +8 -0
  40. package/dist/setup_vis_suite-C6JGGT7B.d.mts +17 -0
  41. package/dist/setup_vis_suite-C6JGGT7B.d.mts.map +1 -0
  42. package/dist/snapshot_path-7GliOSH_.mjs +58 -0
  43. package/dist/snapshot_path-7GliOSH_.mjs.map +1 -0
  44. package/dist/src-CSQnlFa9.mjs +1 -0
  45. package/dist/task_id-DnS9_4Ub.mjs +316 -0
  46. package/dist/task_id-DnS9_4Ub.mjs.map +1 -0
  47. package/dist/testing.d.mts +12 -0
  48. package/dist/testing.d.mts.map +1 -0
  49. package/dist/testing.mjs +65550 -0
  50. package/dist/testing.mjs.map +1 -0
  51. package/dist/to_match_image_snapshot.types-p-zilA_M.d.mts +9 -0
  52. package/dist/to_match_image_snapshot.types-p-zilA_M.d.mts.map +1 -0
  53. package/dist/trim_common_folder-ModiubEJ.d.mts +9 -0
  54. package/dist/trim_common_folder-ModiubEJ.d.mts.map +1 -0
  55. package/dist/types-DFb23VE1.d.mts +110 -0
  56. package/dist/types-DFb23VE1.d.mts.map +1 -0
  57. package/dist/types-Do1N7g4c.d.mts +63 -0
  58. package/dist/types-Do1N7g4c.d.mts.map +1 -0
  59. package/dist/vis_server_context.types-Ce1f9vOO.d.mts +1 -0
  60. package/package.json +55 -39
  61. package/readme.md +58 -6
  62. package/src/client/actions/match_image_snapshot_action.ts +1 -1
  63. package/src/client/actions/match_page_image_snapshot_action.ts +1 -1
  64. package/src/client/auto_snapshot_options.ts +16 -1
  65. package/src/client/compare_image_snapshot.ts +1 -1
  66. package/src/client/expect/to_match_image_snapshot.ts +1 -1
  67. package/src/client/page/extend.ts +1 -1
  68. package/src/client/page/has_image_snapshot.mdx +1 -1
  69. package/src/client/page/has_image_snapshot.ts +1 -1
  70. package/src/client/page/to_match_image_snapshot.mdx +1 -1
  71. package/src/client/page/to_match_image_snapshot.ts +1 -1
  72. package/src/client/setup/create_vis.ts +16 -14
  73. package/src/client/setup/vis.ctx.ts +4 -3
  74. package/src/client/setup/vis.ts +1 -1
  75. package/src/client/snapshot_meta.ts +5 -0
  76. package/src/client/vitest_browser_context_proxy.ts +3 -3
  77. package/src/config/vis.ts +4 -4
  78. package/src/server/browser_provider/browser_api.ts +2 -2
  79. package/src/server/browser_provider/playwright.ts +6 -4
  80. package/src/server/browser_provider/webdriverio.ts +3 -3
  81. package/src/server/commands/_assertions.ts +3 -3
  82. package/src/server/commands/augment.ts +1 -1
  83. package/src/server/commands/has_image_snapshot.ts +2 -2
  84. package/src/server/commands/image_snapshot_next_index.ts +2 -2
  85. package/src/server/commands/load_image_snapshot_results.ts +2 -3
  86. package/src/server/commands/prepare_image_snapshot_comparison.ts +2 -2
  87. package/src/server/commands/prepare_page_image_snapshot_comparison.ts +2 -2
  88. package/src/server/commands/setup_vis_suite.ts +3 -3
  89. package/src/server/project.ts +8 -7
  90. package/src/server/snapshot.ts +4 -4
  91. package/src/server/snapshot_path.ts +6 -5
  92. package/src/server/suite.ts +7 -12
  93. package/src/server/testing/stubBrowserCommandContext.ts +16 -0
  94. package/src/{testing → server/testing}/stubSuite.ts +7 -9
  95. package/src/server/testing/stubUserConfig.ts +6 -0
  96. package/src/server/vis_options.ts +4 -5
  97. package/src/server/vis_server_context.logic.ts +7 -7
  98. package/src/server/vis_server_context.types.ts +31 -26
  99. package/src/shared/types.ts +2 -0
  100. package/src/testing.ts +0 -1
  101. package/esm/client/actions/has_image_snapshot_action.d.ts +0 -4
  102. package/esm/client/actions/has_image_snapshot_action.d.ts.map +0 -1
  103. package/esm/client/actions/has_image_snapshot_action.js +0 -6
  104. package/esm/client/actions/load_image_snapshot_results_action.d.ts +0 -3
  105. package/esm/client/actions/load_image_snapshot_results_action.d.ts.map +0 -1
  106. package/esm/client/actions/load_image_snapshot_results_action.js +0 -3
  107. package/esm/client/actions/match_image_snapshot_action.d.ts +0 -6
  108. package/esm/client/actions/match_image_snapshot_action.d.ts.map +0 -1
  109. package/esm/client/actions/match_image_snapshot_action.js +0 -20
  110. package/esm/client/actions/match_page_image_snapshot_action.d.ts +0 -6
  111. package/esm/client/actions/match_page_image_snapshot_action.d.ts.map +0 -1
  112. package/esm/client/actions/match_page_image_snapshot_action.js +0 -9
  113. package/esm/client/align_images.d.ts +0 -2
  114. package/esm/client/align_images.d.ts.map +0 -1
  115. package/esm/client/align_images.js +0 -10
  116. package/esm/client/auto_snapshot_options.d.ts +0 -29
  117. package/esm/client/auto_snapshot_options.d.ts.map +0 -1
  118. package/esm/client/auto_snapshot_options.js +0 -49
  119. package/esm/client/compare_image_snapshot.d.ts +0 -6
  120. package/esm/client/compare_image_snapshot.d.ts.map +0 -1
  121. package/esm/client/compare_image_snapshot.js +0 -52
  122. package/esm/client/compare_image_snapshot.logic.d.ts +0 -3
  123. package/esm/client/compare_image_snapshot.logic.d.ts.map +0 -1
  124. package/esm/client/compare_image_snapshot.logic.js +0 -12
  125. package/esm/client/ctx.d.ts +0 -7
  126. package/esm/client/ctx.d.ts.map +0 -1
  127. package/esm/client/ctx.js +0 -11
  128. package/esm/client/expect/augment.d.ts +0 -8
  129. package/esm/client/expect/augment.d.ts.map +0 -1
  130. package/esm/client/expect/augment.js +0 -1
  131. package/esm/client/expect/expectation_result.d.ts +0 -3
  132. package/esm/client/expect/expectation_result.d.ts.map +0 -1
  133. package/esm/client/expect/expectation_result.js +0 -5
  134. package/esm/client/expect/extend.d.ts +0 -2
  135. package/esm/client/expect/extend.d.ts.map +0 -1
  136. package/esm/client/expect/extend.js +0 -4
  137. package/esm/client/expect/to_match_image_snapshot.d.ts +0 -9
  138. package/esm/client/expect/to_match_image_snapshot.d.ts.map +0 -1
  139. package/esm/client/expect/to_match_image_snapshot.js +0 -21
  140. package/esm/client/expect/to_match_image_snapshot.types.d.ts +0 -5
  141. package/esm/client/expect/to_match_image_snapshot.types.d.ts.map +0 -1
  142. package/esm/client/expect/to_match_image_snapshot.types.js +0 -1
  143. package/esm/client/image_data.d.ts +0 -3
  144. package/esm/client/image_data.d.ts.map +0 -1
  145. package/esm/client/image_data.js +0 -33
  146. package/esm/client/image_resizer.d.ts +0 -9
  147. package/esm/client/image_resizer.d.ts.map +0 -1
  148. package/esm/client/image_resizer.js +0 -49
  149. package/esm/client/image_snapshot_options.d.ts +0 -2
  150. package/esm/client/image_snapshot_options.d.ts.map +0 -1
  151. package/esm/client/image_snapshot_options.js +0 -6
  152. package/esm/client/page/augment.d.ts +0 -7
  153. package/esm/client/page/augment.d.ts.map +0 -1
  154. package/esm/client/page/augment.js +0 -1
  155. package/esm/client/page/extend.d.ts +0 -2
  156. package/esm/client/page/extend.d.ts.map +0 -1
  157. package/esm/client/page/extend.js +0 -5
  158. package/esm/client/page/has_image_snapshot.d.ts +0 -10
  159. package/esm/client/page/has_image_snapshot.d.ts.map +0 -1
  160. package/esm/client/page/has_image_snapshot.js +0 -15
  161. package/esm/client/page/to_match_image_snapshot.d.ts +0 -6
  162. package/esm/client/page/to_match_image_snapshot.d.ts.map +0 -1
  163. package/esm/client/page/to_match_image_snapshot.js +0 -15
  164. package/esm/client/selector.d.ts +0 -7
  165. package/esm/client/selector.d.ts.map +0 -1
  166. package/esm/client/selector.js +0 -97
  167. package/esm/client/setup/create_vis.d.ts +0 -96
  168. package/esm/client/setup/create_vis.d.ts.map +0 -1
  169. package/esm/client/setup/create_vis.js +0 -109
  170. package/esm/client/setup/vis.ctx.d.ts +0 -12
  171. package/esm/client/setup/vis.ctx.d.ts.map +0 -1
  172. package/esm/client/setup/vis.ctx.js +0 -32
  173. package/esm/client/setup/vis.d.ts +0 -5
  174. package/esm/client/setup/vis.d.ts.map +0 -1
  175. package/esm/client/setup/vis.js +0 -6
  176. package/esm/client/should_take_snapshot.d.ts +0 -3
  177. package/esm/client/should_take_snapshot.d.ts.map +0 -1
  178. package/esm/client/should_take_snapshot.js +0 -3
  179. package/esm/client/snapshot_meta.d.ts +0 -6
  180. package/esm/client/snapshot_meta.d.ts.map +0 -1
  181. package/esm/client/snapshot_meta.js +0 -1
  182. package/esm/client/task_id.d.ts +0 -7
  183. package/esm/client/task_id.d.ts.map +0 -1
  184. package/esm/client/task_id.js +0 -10
  185. package/esm/client/vitest_browser_context_proxy.d.ts +0 -32
  186. package/esm/client/vitest_browser_context_proxy.d.ts.map +0 -1
  187. package/esm/client/vitest_browser_context_proxy.js +0 -11
  188. package/esm/client/vitest_suite_proxy.d.ts +0 -7
  189. package/esm/client/vitest_suite_proxy.d.ts.map +0 -1
  190. package/esm/client/vitest_suite_proxy.js +0 -8
  191. package/esm/client-api.d.ts +0 -12
  192. package/esm/client-api.d.ts.map +0 -1
  193. package/esm/client-api.js +0 -9
  194. package/esm/commands.d.ts +0 -5
  195. package/esm/commands.d.ts.map +0 -1
  196. package/esm/commands.js +0 -4
  197. package/esm/config/types.d.ts +0 -60
  198. package/esm/config/types.d.ts.map +0 -1
  199. package/esm/config/types.js +0 -1
  200. package/esm/config/vis.d.ts +0 -28
  201. package/esm/config/vis.d.ts.map +0 -1
  202. package/esm/config/vis.js +0 -27
  203. package/esm/config.d.ts +0 -4
  204. package/esm/config.d.ts.map +0 -1
  205. package/esm/config.js +0 -2
  206. package/esm/index.d.ts +0 -5
  207. package/esm/index.d.ts.map +0 -1
  208. package/esm/index.js +0 -4
  209. package/esm/presets/auto.d.ts +0 -2
  210. package/esm/presets/auto.d.ts.map +0 -1
  211. package/esm/presets/auto.js +0 -8
  212. package/esm/presets/enable.d.ts +0 -2
  213. package/esm/presets/enable.d.ts.map +0 -1
  214. package/esm/presets/enable.js +0 -4
  215. package/esm/presets/manual.d.ts +0 -2
  216. package/esm/presets/manual.d.ts.map +0 -1
  217. package/esm/presets/manual.js +0 -4
  218. package/esm/server/browser_provider/browser_api.d.ts +0 -3
  219. package/esm/server/browser_provider/browser_api.d.ts.map +0 -1
  220. package/esm/server/browser_provider/browser_api.js +0 -11
  221. package/esm/server/browser_provider/playwright.d.ts +0 -4
  222. package/esm/server/browser_provider/playwright.d.ts.map +0 -1
  223. package/esm/server/browser_provider/playwright.js +0 -18
  224. package/esm/server/browser_provider/types.d.ts +0 -10
  225. package/esm/server/browser_provider/types.d.ts.map +0 -1
  226. package/esm/server/browser_provider/types.js +0 -1
  227. package/esm/server/browser_provider/webdriverio.d.ts +0 -4
  228. package/esm/server/browser_provider/webdriverio.d.ts.map +0 -1
  229. package/esm/server/browser_provider/webdriverio.js +0 -12
  230. package/esm/server/commands/_assertions.d.ts +0 -5
  231. package/esm/server/commands/_assertions.d.ts.map +0 -1
  232. package/esm/server/commands/_assertions.js +0 -11
  233. package/esm/server/commands/augment.d.ts +0 -11
  234. package/esm/server/commands/augment.d.ts.map +0 -1
  235. package/esm/server/commands/augment.js +0 -1
  236. package/esm/server/commands/commands.d.ts +0 -9
  237. package/esm/server/commands/commands.d.ts.map +0 -1
  238. package/esm/server/commands/commands.js +0 -14
  239. package/esm/server/commands/has_image_snapshot.d.ts +0 -6
  240. package/esm/server/commands/has_image_snapshot.d.ts.map +0 -1
  241. package/esm/server/commands/has_image_snapshot.js +0 -6
  242. package/esm/server/commands/image_snapshot_next_index.d.ts +0 -9
  243. package/esm/server/commands/image_snapshot_next_index.d.ts.map +0 -1
  244. package/esm/server/commands/image_snapshot_next_index.js +0 -6
  245. package/esm/server/commands/load_image_snapshot_results.d.ts +0 -21
  246. package/esm/server/commands/load_image_snapshot_results.d.ts.map +0 -1
  247. package/esm/server/commands/load_image_snapshot_results.js +0 -6
  248. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +0 -38
  249. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +0 -1
  250. package/esm/server/commands/prepare_image_snapshot_comparison.js +0 -34
  251. package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts +0 -35
  252. package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts.map +0 -1
  253. package/esm/server/commands/prepare_page_image_snapshot_comparison.js +0 -27
  254. package/esm/server/commands/setup_vis_suite.d.ts +0 -15
  255. package/esm/server/commands/setup_vis_suite.d.ts.map +0 -1
  256. package/esm/server/commands/setup_vis_suite.js +0 -6
  257. package/esm/server/commands/types.d.ts +0 -3
  258. package/esm/server/commands/types.d.ts.map +0 -1
  259. package/esm/server/commands/types.js +0 -1
  260. package/esm/server/externals/file.d.ts +0 -10
  261. package/esm/server/externals/file.d.ts.map +0 -1
  262. package/esm/server/externals/file.js +0 -20
  263. package/esm/server/project.d.ts +0 -21
  264. package/esm/server/project.d.ts.map +0 -1
  265. package/esm/server/project.js +0 -13
  266. package/esm/server/snapshot.d.ts +0 -6
  267. package/esm/server/snapshot.d.ts.map +0 -1
  268. package/esm/server/snapshot.js +0 -29
  269. package/esm/server/snapshot_path.d.ts +0 -14
  270. package/esm/server/snapshot_path.d.ts.map +0 -1
  271. package/esm/server/snapshot_path.js +0 -34
  272. package/esm/server/snapshot_writer.d.ts +0 -13
  273. package/esm/server/snapshot_writer.d.ts.map +0 -1
  274. package/esm/server/snapshot_writer.js +0 -15
  275. package/esm/server/suite.d.ts +0 -54
  276. package/esm/server/suite.d.ts.map +0 -1
  277. package/esm/server/suite.js +0 -73
  278. package/esm/server/vis_options.d.ts +0 -19
  279. package/esm/server/vis_options.d.ts.map +0 -1
  280. package/esm/server/vis_options.js +0 -14
  281. package/esm/server/vis_server_context.d.ts +0 -50
  282. package/esm/server/vis_server_context.d.ts.map +0 -1
  283. package/esm/server/vis_server_context.deps.d.ts +0 -29
  284. package/esm/server/vis_server_context.deps.d.ts.map +0 -1
  285. package/esm/server/vis_server_context.deps.js +0 -10
  286. package/esm/server/vis_server_context.js +0 -2
  287. package/esm/server/vis_server_context.logic.d.ts +0 -53
  288. package/esm/server/vis_server_context.logic.d.ts.map +0 -1
  289. package/esm/server/vis_server_context.logic.js +0 -79
  290. package/esm/server/vis_server_context.types.d.ts +0 -54
  291. package/esm/server/vis_server_context.types.d.ts.map +0 -1
  292. package/esm/server/vis_server_context.types.js +0 -1
  293. package/esm/server-utils.d.ts +0 -4
  294. package/esm/server-utils.d.ts.map +0 -1
  295. package/esm/server-utils.js +0 -3
  296. package/esm/setup.d.ts +0 -5
  297. package/esm/setup.d.ts.map +0 -1
  298. package/esm/setup.js +0 -5
  299. package/esm/shared/asserts.d.ts +0 -2
  300. package/esm/shared/asserts.d.ts.map +0 -1
  301. package/esm/shared/asserts.js +0 -5
  302. package/esm/shared/base64.d.ts +0 -2
  303. package/esm/shared/base64.d.ts.map +0 -1
  304. package/esm/shared/base64.js +0 -3
  305. package/esm/shared/compare_image.d.ts +0 -6
  306. package/esm/shared/compare_image.d.ts.map +0 -1
  307. package/esm/shared/compare_image.js +0 -42
  308. package/esm/shared/constants.d.ts +0 -6
  309. package/esm/shared/constants.d.ts.map +0 -1
  310. package/esm/shared/constants.js +0 -5
  311. package/esm/shared/convert_threshold_unit.d.ts +0 -6
  312. package/esm/shared/convert_threshold_unit.d.ts.map +0 -1
  313. package/esm/shared/convert_threshold_unit.js +0 -10
  314. package/esm/shared/get_max_size.d.ts +0 -11
  315. package/esm/shared/get_max_size.d.ts.map +0 -1
  316. package/esm/shared/get_max_size.js +0 -5
  317. package/esm/shared/is_same_size.d.ts +0 -8
  318. package/esm/shared/is_same_size.d.ts.map +0 -1
  319. package/esm/shared/is_same_size.js +0 -3
  320. package/esm/shared/trim_common_folder.d.ts +0 -6
  321. package/esm/shared/trim_common_folder.d.ts.map +0 -1
  322. package/esm/shared/trim_common_folder.js +0 -11
  323. package/esm/shared/types.d.ts +0 -90
  324. package/esm/shared/types.d.ts.map +0 -1
  325. package/esm/shared/types.js +0 -1
  326. package/esm/testing/constants.d.ts +0 -9
  327. package/esm/testing/constants.d.ts.map +0 -1
  328. package/esm/testing/constants.js +0 -1933
  329. package/esm/testing/stubBrowserCommandContext.d.ts +0 -8
  330. package/esm/testing/stubBrowserCommandContext.d.ts.map +0 -1
  331. package/esm/testing/stubBrowserCommandContext.js +0 -12
  332. package/esm/testing/stubSuite.d.ts +0 -10
  333. package/esm/testing/stubSuite.d.ts.map +0 -1
  334. package/esm/testing/stubSuite.js +0 -27
  335. package/esm/testing/stubUserConfig.d.ts +0 -7
  336. package/esm/testing/stubUserConfig.d.ts.map +0 -1
  337. package/esm/testing/stubUserConfig.js +0 -4
  338. package/esm/testing.d.ts +0 -3
  339. package/esm/testing.d.ts.map +0 -1
  340. package/esm/testing.js +0 -2
  341. package/src/testing/stubBrowserCommandContext.ts +0 -16
  342. package/src/testing/stubUserConfig.ts +0 -6
@@ -1,5 +1,6 @@
1
- import { commands } from '@vitest/browser/context'
2
- import { afterEach, beforeAll, beforeEach, vi, type Awaitable, type Suite } from 'vitest'
1
+ import { afterEach, beforeAll, beforeEach, vi, type SuiteAPI } from 'vitest'
2
+ import { commands } from 'vitest/browser'
3
+ import type { Awaitable } from '../../shared/types.ts'
3
4
 
4
5
  export const ctx = {
5
6
  beforeAll,
@@ -7,7 +8,7 @@ export const ctx = {
7
8
  afterEach,
8
9
  commands,
9
10
  mock() {
10
- const beforeAllListeners: Array<(suite: Readonly<Suite | File>) => Awaitable<unknown>> = []
11
+ const beforeAllListeners: Array<(suite: Readonly<SuiteAPI | File>) => Awaitable<unknown>> = []
11
12
  beforeEach(() => {
12
13
  ctx.beforeAll = vi.fn((fn) => {
13
14
  beforeAllListeners.push(fn)
@@ -1,4 +1,4 @@
1
- import { commands } from '@vitest/browser/context'
1
+ import { commands } from 'vitest/browser'
2
2
  import { createVis } from './create_vis.ts'
3
3
 
4
4
  /**
@@ -2,6 +2,11 @@ import type { ComparisonMethod, ImageSnapshotSubjectOptions, ToMatchImageSnapsho
2
2
 
3
3
  export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> &
4
4
  ImageSnapshotSubjectOptions & {
5
+ /**
6
+ * Whether to enable the snapshot.
7
+ *
8
+ * Default: `true`
9
+ */
5
10
  enable?: boolean | undefined
6
11
  [key: string]: unknown
7
12
  }
@@ -1,10 +1,10 @@
1
- import type { BrowserCommands, Platform } from '@vitest/browser/context'
2
1
  import type { SerializedConfig } from 'vitest'
2
+ import type { BrowserCommands, Platform } from 'vitest/browser'
3
3
 
4
- let ctx: Awaited<typeof import('@vitest/browser/context')>
4
+ let ctx: Awaited<typeof import('vitest/browser')>
5
5
 
6
6
  if ((globalThis as any).__vitest_browser__) {
7
- import('@vitest/browser/context').then((m) => {
7
+ import('vitest/browser').then((m) => {
8
8
  ctx = m
9
9
  })
10
10
  }
package/src/config/vis.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { PluginOption } from 'vite'
1
+ import type { Plugin } from 'vitest/config'
2
2
  import { commands } from '../server/commands/commands.ts'
3
3
  import { setVisOption } from '../server/vis_options.ts'
4
4
  import { NAME } from '../shared/constants.ts'
@@ -20,12 +20,12 @@ export function vis<M extends ComparisonMethod = 'pixel'>(options: VisOptions<M>
20
20
  return {
21
21
  test: {
22
22
  browser: {
23
- name: undefined as unknown as string,
24
- commands,
23
+ name: undefined,
24
+ commands: commands as any,
25
25
  },
26
26
  setupFiles: preset && preset !== 'none' && preset !== 'custom' ? [`vitest-plugin-vis/presets/${preset}`] : [],
27
27
  },
28
28
  }
29
29
  },
30
- } satisfies PluginOption
30
+ } satisfies Plugin
31
31
  }
@@ -1,8 +1,8 @@
1
- import type { BrowserCommandContext } from 'vitest/node'
1
+ import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
2
2
  import { playwright } from './playwright.ts'
3
3
  import { webdriverio } from './webdriverio.ts'
4
4
 
5
- export function browserApi(context: BrowserCommandContext) {
5
+ export function browserApi(context: ExtendedBrowserCommandContext) {
6
6
  if (context.provider.name === 'playwright') {
7
7
  return playwright(context)
8
8
  }
@@ -1,18 +1,20 @@
1
1
  import { resolve } from 'pathe'
2
- import type { BrowserCommandContext } from 'vitest/node'
2
+ import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
3
3
  import type { BrowserApi } from './types.ts'
4
4
 
5
- export function playwright(context: BrowserCommandContext): BrowserApi {
5
+ export function playwright(context: ExtendedBrowserCommandContext): BrowserApi {
6
+ const { page, iframe } = context
7
+
6
8
  return {
7
9
  async takeScreenshot(projectRoot, relativeFilePath, selector, options) {
8
- const subject = context.iframe.locator(selector)
10
+ const subject = iframe.locator(selector)
9
11
  return subject.screenshot({
10
12
  path: resolve(projectRoot, relativeFilePath),
11
13
  ...options,
12
14
  })
13
15
  },
14
16
  async takePageScreenshot(projectRoot, relativeFilePath, options) {
15
- return context.page.screenshot({
17
+ return page.screenshot({
16
18
  path: resolve(projectRoot, relativeFilePath),
17
19
  ...options,
18
20
  })
@@ -1,8 +1,8 @@
1
- import type { BrowserCommandContext } from 'vitest/node'
1
+ import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
2
2
  import type { BrowserApi } from './types.ts'
3
3
 
4
- export function webdriverio(context: BrowserCommandContext): BrowserApi {
5
- const browser = context.browser
4
+ export function webdriverio(context: ExtendedBrowserCommandContext): BrowserApi {
5
+ const { browser } = context
6
6
  return {
7
7
  async takeScreenshot(_projectRoot, relativeFilePath, selector) {
8
8
  const element = await browser.$(`${selector}`)
@@ -1,11 +1,11 @@
1
1
  import { isAbsolute } from 'pathe'
2
2
  import type { RequiredPick } from 'type-plus'
3
- import type { BrowserCommandContext } from 'vitest/node'
3
+ import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
4
4
 
5
5
  export function assertTestPathDefined(
6
- context: BrowserCommandContext,
6
+ context: ExtendedBrowserCommandContext,
7
7
  commandName: string,
8
- ): asserts context is RequiredPick<BrowserCommandContext, 'testPath'> {
8
+ ): asserts context is RequiredPick<ExtendedBrowserCommandContext, 'testPath'> {
9
9
  if (!context.testPath) {
10
10
  throw new Error(`'commands.${commandName}' requires testPath to be defined`)
11
11
  }
@@ -5,7 +5,7 @@ import type { PrepareImageSnapshotComparisonCommand } from './prepare_image_snap
5
5
  import type { PreparePageImageSnapshotComparisonCommand } from './prepare_page_image_snapshot_comparison.ts'
6
6
  import type { SetupVisSuiteCommand } from './setup_vis_suite.ts'
7
7
 
8
- declare module '@vitest/browser/context' {
8
+ declare module 'vitest/browser' {
9
9
  interface BrowserCommands
10
10
  extends SetupVisSuiteCommand,
11
11
  ImageSnapshotNextIndexCommand,
@@ -1,12 +1,12 @@
1
- import type { BrowserCommand } from 'vitest/node'
2
1
  import { visServerContext } from '../vis_server_context.ts'
2
+ import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
3
3
  import { assertTestPathDefined } from './_assertions.ts'
4
4
 
5
5
  export interface HasImageSnapshotCommand {
6
6
  hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
7
7
  }
8
8
 
9
- export const hasImageSnapshot: BrowserCommand<Parameters<HasImageSnapshotCommand['hasImageSnapshot']>> = async (
9
+ export const hasImageSnapshot: ExtendedBrowserCommand<Parameters<HasImageSnapshotCommand['hasImageSnapshot']>> = async (
10
10
  context,
11
11
  taskId,
12
12
  snapshotKey,
@@ -1,5 +1,5 @@
1
- import type { BrowserCommand } from 'vitest/node'
2
1
  import { visServerContext } from '../vis_server_context.ts'
2
+ import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
3
3
  import { assertTestPathDefined } from './_assertions.ts'
4
4
 
5
5
  export interface ImageSnapshotNextIndexCommand {
@@ -9,7 +9,7 @@ export interface ImageSnapshotNextIndexCommand {
9
9
  imageSnapshotNextIndex(taskId: string): Promise<number>
10
10
  }
11
11
 
12
- export const imageSnapshotNextIndex: BrowserCommand<
12
+ export const imageSnapshotNextIndex: ExtendedBrowserCommand<
13
13
  Parameters<ImageSnapshotNextIndexCommand['imageSnapshotNextIndex']>
14
14
  > = async (context, taskId) => {
15
15
  assertTestPathDefined(context, 'imageSnapshotNextIndex')
@@ -1,5 +1,5 @@
1
- import type { BrowserCommand } from 'vitest/node'
2
1
  import { visServerContext } from '../vis_server_context.ts'
2
+ import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
3
3
  import { assertTestPathDefined } from './_assertions.ts'
4
4
 
5
5
  export interface ImageSnapshotResult {
@@ -22,11 +22,10 @@ export interface LoadImageSnapshotResultsCommand {
22
22
  loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
23
23
  }
24
24
 
25
- export const loadImageSnapshotResults: BrowserCommand<[taskId: string]> = async (
25
+ export const loadImageSnapshotResults: ExtendedBrowserCommand<[taskId: string]> = async (
26
26
  context,
27
27
  taskId,
28
28
  ): Promise<ImageSnapshotResult[]> => {
29
29
  assertTestPathDefined(context, 'loadImageSnapshotResults')
30
-
31
30
  return visServerContext.getSnapshotResults(context, taskId)
32
31
  }
@@ -1,5 +1,4 @@
1
1
  import { resolve } from 'pathe'
2
- import type { BrowserCommand } from 'vitest/node'
3
2
  import { isBase64String } from '../../shared/base64.ts'
4
3
  import type {
5
4
  FailureThresholdOptions,
@@ -12,6 +11,7 @@ import { getProjectRoot } from '../project.ts'
12
11
  import { takeSnapshot, takeSnapshotByBrowser } from '../snapshot.ts'
13
12
  import { snapshotWriter } from '../snapshot_writer.ts'
14
13
  import { visServerContext } from '../vis_server_context.ts'
14
+ import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
15
15
  import { assertTestPathDefined } from './_assertions.ts'
16
16
  import type { MatchImageSnapshotOptions } from './types.ts'
17
17
 
@@ -56,7 +56,7 @@ export interface PrepareImageSnapshotComparisonCommand {
56
56
  ) => Promise<ImageSnapshotComparisonInfo | undefined>
57
57
  }
58
58
 
59
- export const prepareImageSnapshotComparison: BrowserCommand<
59
+ export const prepareImageSnapshotComparison: ExtendedBrowserCommand<
60
60
  Parameters<PrepareImageSnapshotComparisonCommand['prepareImageSnapshotComparison']>
61
61
  > = async (context, taskId, subject, options): Promise<ImageSnapshotComparisonInfo | undefined> => {
62
62
  assertTestPathDefined(context, 'prepareImageSnapshotComparison')
@@ -1,5 +1,4 @@
1
1
  import { resolve } from 'pathe'
2
- import type { BrowserCommand } from 'vitest/node'
3
2
  import type {
4
3
  FailureThresholdOptions,
5
4
  ImageSnapshotTimeoutOptions,
@@ -10,6 +9,7 @@ import { file } from '../externals/file.ts'
10
9
  import { getProjectRoot } from '../project.ts'
11
10
  import { takePageSnapshot } from '../snapshot.ts'
12
11
  import { visServerContext } from '../vis_server_context.ts'
12
+ import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
13
13
  import { assertTestPathDefined } from './_assertions.ts'
14
14
  import type { MatchImageSnapshotOptions } from './types.ts'
15
15
 
@@ -49,7 +49,7 @@ export interface PreparePageImageSnapshotComparisonCommand {
49
49
  ) => Promise<ImageSnapshotComparisonInfo | undefined>
50
50
  }
51
51
 
52
- export const preparePageImageSnapshotComparison: BrowserCommand<
52
+ export const preparePageImageSnapshotComparison: ExtendedBrowserCommand<
53
53
  Parameters<PreparePageImageSnapshotComparisonCommand['preparePageImageSnapshotComparison']>
54
54
  > = async (context, taskId, options) => {
55
55
  assertTestPathDefined(context, 'preparePageImageSnapshotComparison')
@@ -1,7 +1,7 @@
1
1
  import type { Pick } from 'type-plus'
2
- import type { BrowserCommand } from 'vitest/node'
3
2
  import type { VisOptions } from '../../config/types.ts'
4
3
  import { setupSuite } from '../suite.ts'
4
+ import type { ExtendedBrowserCommand, ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
5
5
  import { assertTestPathDefined } from './_assertions.ts'
6
6
 
7
7
  export interface SetupVisSuiteCommand {
@@ -26,7 +26,7 @@ export interface SetupVisSuiteCommand {
26
26
  >
27
27
  }
28
28
 
29
- export const setupVisSuite: BrowserCommand<[]> = async (context): Promise<{ subject: string | undefined }> => {
29
+ export const setupVisSuite: ExtendedBrowserCommand<[]> = async (context): Promise<{ subject: string | undefined }> => {
30
30
  assertTestPathDefined(context, 'setupVisSuite')
31
- return setupSuite(context)
31
+ return setupSuite(context as unknown as ExtendedBrowserCommandContext)
32
32
  }
@@ -1,13 +1,14 @@
1
- export function getProjectName(context: {
2
- project: { vite: { config: { test?: { name?: { label: string } | string | undefined } } } }
3
- }) {
4
- const name = context.project.vite.config.test?.name
1
+ import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
2
+
3
+ export function getProjectName(context: ExtendedBrowserCommandContext) {
4
+ const { runner } = context.project
5
+ const name = runner.config.name
5
6
  if (typeof name === 'string') {
6
7
  return name
7
8
  }
8
- if (typeof name === 'object' && 'label' in name) {
9
- return name.label
10
- }
9
+ // if (typeof name === 'object' && 'label' in name) {
10
+ // return (name as { label: string }).label
11
+ // }
11
12
  return undefined
12
13
  }
13
14
 
@@ -1,13 +1,13 @@
1
1
  import { mkdirp } from 'mkdirp'
2
2
  import { dirname, resolve } from 'pathe'
3
- import type { BrowserCommandContext } from 'vitest/node'
4
3
  import { isBase64String } from '../shared/base64.ts'
5
4
  import type { ImageSnapshotTimeoutOptions, PageImageSnapshotOptions } from '../shared/types.ts'
6
5
  import { browserApi } from './browser_provider/browser_api.ts'
7
6
  import { snapshotWriter } from './snapshot_writer.ts'
7
+ import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
8
8
 
9
9
  export async function takeSnapshot(
10
- context: BrowserCommandContext,
10
+ context: ExtendedBrowserCommandContext,
11
11
  projectRoot: string,
12
12
  relativeFilePath: string,
13
13
  subject: string,
@@ -21,7 +21,7 @@ export async function takeSnapshot(
21
21
  }
22
22
 
23
23
  export async function takeSnapshotByBrowser(
24
- context: BrowserCommandContext,
24
+ context: ExtendedBrowserCommandContext,
25
25
  projectRoot: string,
26
26
  relativeFilePath: string,
27
27
  subject: string,
@@ -36,7 +36,7 @@ export async function takeSnapshotByBrowser(
36
36
  }
37
37
 
38
38
  export async function takePageSnapshot(
39
- context: BrowserCommandContext,
39
+ context: ExtendedBrowserCommandContext,
40
40
  projectRoot: string,
41
41
  relativeFilePath: string,
42
42
  options: (PageImageSnapshotOptions & ImageSnapshotTimeoutOptions) | undefined,
@@ -3,19 +3,20 @@ import { platform } from 'node:process'
3
3
  import type { VisOptions } from '../config/types.ts'
4
4
  import { SNAPSHOT_ROOT_DIR } from '../shared/constants.ts'
5
5
  import { trimCommonFolder } from '../shared/trim_common_folder.ts'
6
- import type { PartialBrowserCommandContext } from './vis_server_context.types.ts'
6
+ import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
7
7
 
8
- export function resolveSnapshotRootDir(browserCommandContext: PartialBrowserCommandContext, options: VisOptions) {
8
+ export function resolveSnapshotRootDir(browserCommandContext: ExtendedBrowserCommandContext, options: VisOptions) {
9
9
  if (!options.snapshotRootDir) return getSnapshotRootDir(SNAPSHOT_ROOT_DIR)
10
10
  const snapshotRootDir = options.snapshotRootDir
11
11
  if (typeof snapshotRootDir === 'string') return getSnapshotRootDir(snapshotRootDir)
12
+ const { config } = browserCommandContext.project.browser
12
13
  return snapshotRootDir({
13
14
  ci,
14
- browserName: browserCommandContext.provider.browserName,
15
+ browserName: config.browser.name,
15
16
  providerName: browserCommandContext.provider.name,
16
17
  platform,
17
- screenshotFailures: browserCommandContext.provider.options?.screenshotFailures,
18
- screenshotDirectory: browserCommandContext.provider.options?.screenshotDirectory,
18
+ screenshotFailures: config.browser.screenshotFailures,
19
+ screenshotDirectory: config.browser.screenshotDirectory,
19
20
  })
20
21
  }
21
22
 
@@ -1,12 +1,11 @@
1
1
  import { join, relative } from 'pathe'
2
- import type { UserConfig } from 'vitest/node'
3
2
  import type { VisOptions } from '../config/types.ts'
4
3
  import { BASELINE_DIR, DIFF_DIR, RESULT_DIR } from '../shared/constants.ts'
5
4
  import { getProjectName, getProjectRoot } from './project.ts'
6
5
  import { getSnapshotSubpath, resolveSnapshotRootDir } from './snapshot_path.ts'
7
6
  import { getVisOption } from './vis_options.ts'
8
7
  import { deps } from './vis_server_context.deps.ts'
9
- import type { PartialBrowserCommandContext, VisSuite, VisSuites } from './vis_server_context.types.ts'
8
+ import type { ExtendedBrowserCommandContext, VisSuite, VisSuites } from './vis_server_context.types.ts'
10
9
 
11
10
  const suites: VisSuites = {}
12
11
 
@@ -15,7 +14,7 @@ const suites: VisSuites = {}
15
14
  * Test files include vitest test files and storybook story files.
16
15
  * It needs to make sure there is no race condition between the test files.
17
16
  */
18
- export async function setupSuite(browserContext: PartialBrowserCommandContext) {
17
+ export async function setupSuite(browserContext: ExtendedBrowserCommandContext) {
19
18
  const suiteId = getSuiteId(browserContext)
20
19
  const visOptions = getVisOption(browserContext)
21
20
 
@@ -27,7 +26,7 @@ export async function setupSuite(browserContext: PartialBrowserCommandContext) {
27
26
 
28
27
  const { taskSubpath, baselineDir, diffDir, resultDir, tasks } = createModule(
29
28
  suite,
30
- browserContext.testPath,
29
+ browserContext.testPath!,
31
30
  visOptions,
32
31
  )
33
32
  suite.modules[taskSubpath] = { baselineDir, diffDir, resultDir, tasks }
@@ -48,19 +47,15 @@ export async function setupSuite(browserContext: PartialBrowserCommandContext) {
48
47
  * Suite ID also contains the project name to make it unique
49
48
  * across different projects.
50
49
  */
51
- export function getSuiteId(context: {
52
- project: {
53
- config: { root: string; name: string }
54
- vite: { config: { test?: { name?: UserConfig['name'] | undefined } } }
55
- }
56
- }) {
50
+ export function getSuiteId(context: ExtendedBrowserCommandContext) {
57
51
  return `${getProjectName(context)}/${context.project.config.name}`
58
52
  }
59
53
 
60
54
  async function createSuite(
61
- browserContext: PartialBrowserCommandContext,
55
+ browserContext: ExtendedBrowserCommandContext,
62
56
  visOptions: Pick<VisOptions, 'snapshotRootDir' | 'subject'>,
63
57
  ) {
58
+ // console.log('visOptions', visOptions)
64
59
  const snapshotRootDir = resolveSnapshotRootDir(browserContext, visOptions)
65
60
  const projectRoot = getProjectRoot(browserContext)
66
61
 
@@ -95,6 +90,6 @@ export function getTaskSubpath(state: VisSuite, testPath: string, options: Pick<
95
90
  return getSnapshotSubpath(relative(state.projectRoot, testPath), options)
96
91
  }
97
92
 
98
- export function getSuite(context: PartialBrowserCommandContext) {
93
+ export function getSuite(context: ExtendedBrowserCommandContext) {
99
94
  return suites[getSuiteId(context)]!
100
95
  }
@@ -0,0 +1,16 @@
1
+ import '@vitest/browser-playwright'
2
+ import { stub } from 'type-plus'
3
+ import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
4
+
5
+ export const stubBrowserCommandContext = stub.build<ExtendedBrowserCommandContext>({})
6
+
7
+ export function createStubPartialBrowserCommandContext({ root, testPath }: { root: string; testPath: string }) {
8
+ return stub.build<ExtendedBrowserCommandContext>({
9
+ project: {
10
+ config: { root },
11
+ runner: { config: { name: 'subject' } },
12
+ } as any,
13
+ provider: {},
14
+ testPath,
15
+ })
16
+ }
@@ -1,13 +1,13 @@
1
1
  import { resolve } from 'pathe'
2
2
  import { requiredDeep, type RecursivePartial } from 'type-plus'
3
- import type { UserConfig } from 'vite'
4
- import type { BrowserCommandContext } from 'vitest/node'
3
+ import type { TestUserConfig } from 'vitest/node'
4
+ import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
5
5
  import { stubBrowserCommandContext } from './stubBrowserCommandContext.ts'
6
6
  import { stubUserConfig } from './stubUserConfig.ts'
7
7
 
8
8
  export function stubSuite(
9
- partialUserConfig: RecursivePartial<UserConfig> = {},
10
- partialBrowserCommandContext: RecursivePartial<BrowserCommandContext> = {},
9
+ partialUserConfig: RecursivePartial<{ test?: { name?: TestUserConfig['name'] } }> = {},
10
+ partialBrowserCommandContext: RecursivePartial<ExtendedBrowserCommandContext> = {},
11
11
  ) {
12
12
  const root = resolve(import.meta.dirname, '../..')
13
13
  const userConfig = stubUserConfig({
@@ -15,15 +15,13 @@ export function stubSuite(
15
15
  ...partialUserConfig,
16
16
  })
17
17
  const browserCommandContext = stubBrowserCommandContext(
18
- requiredDeep<RecursivePartial<BrowserCommandContext>>(
18
+ requiredDeep<RecursivePartial<ExtendedBrowserCommandContext>>(
19
19
  {
20
20
  project: {
21
21
  config: { root },
22
- vite: {
22
+ runner: {
23
23
  config: {
24
- test: {
25
- name: partialUserConfig.test?.name,
26
- },
24
+ name: partialUserConfig.test?.name as string | undefined,
27
25
  },
28
26
  },
29
27
  },
@@ -0,0 +1,6 @@
1
+ import { stub } from 'type-plus'
2
+ import type { ViteUserConfig } from 'vitest/config'
3
+
4
+ export const stubUserConfig = stub.build<ViteUserConfig>((stub) => ({
5
+ ...stub,
6
+ }))
@@ -1,26 +1,25 @@
1
- import type { UserConfig } from 'vitest/node'
1
+ import type { TestUserConfig } from 'vitest/node'
2
2
  import type { VisOptions } from '../config/types.ts'
3
3
  import { assertSnapshotKeyWithoutDash } from '../shared/asserts.ts'
4
4
  import { getProjectName } from './project.ts'
5
+ import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
5
6
 
6
7
  const DEFAULT_PROJECT_NAME = '__default'
7
8
 
8
9
  const visOptions: Record<string, VisOptions<any> | undefined> = {}
9
10
 
10
11
  export function setVisOption(
11
- userConfig: { test?: { name?: UserConfig['name'] | undefined } | undefined },
12
+ userConfig: { test?: { name?: TestUserConfig['name'] | undefined } },
12
13
  options: VisOptions<any> | undefined,
13
14
  ) {
14
15
  assertSnapshotKeyWithoutDash(options?.snapshotKey)
15
16
 
16
17
  const name = userConfig.test?.name
17
18
  const id = typeof name === 'string' ? name : typeof name === 'object' ? name?.label : DEFAULT_PROJECT_NAME
18
-
19
19
  visOptions[id] = options
20
20
  }
21
21
 
22
- export function getVisOption(context: { project: { vite: { config: { test?: { name?: UserConfig['name'] } } } } }) {
22
+ export function getVisOption(context: ExtendedBrowserCommandContext) {
23
23
  const id = getProjectName(context) ?? DEFAULT_PROJECT_NAME
24
-
25
24
  return visOptions[id] ?? {}
26
25
  }
@@ -5,11 +5,11 @@ import type { ImageSnapshotResult } from './commands/load_image_snapshot_results
5
5
  import { file } from './externals/file.ts'
6
6
  import { getSuite, getTaskSubpath } from './suite.ts'
7
7
  import { getVisOption } from './vis_options.ts'
8
- import type { PartialBrowserCommandContext } from './vis_server_context.types.ts'
8
+ import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
9
9
 
10
10
  export function createVisServerContext() {
11
11
  const context = {
12
- async getSnapshotResults(browserContext: PartialBrowserCommandContext, taskId: string) {
12
+ async getSnapshotResults(browserContext: ExtendedBrowserCommandContext, taskId: string) {
13
13
  const suiteInfo = await context.getSuiteInfo(browserContext, taskId)
14
14
  const baselines = await file.glob(join(suiteInfo.projectRoot, suiteInfo.baselineDir, `${suiteInfo.taskId}-*.png`))
15
15
  const results = await file.glob(join(suiteInfo.projectRoot, suiteInfo.resultDir, `${suiteInfo.taskId}-*.png`))
@@ -36,7 +36,7 @@ export function createVisServerContext() {
36
36
  return r
37
37
  },
38
38
  async getSnapshotInfo(
39
- browserContext: PartialBrowserCommandContext,
39
+ browserContext: ExtendedBrowserCommandContext,
40
40
  taskId: string,
41
41
  options?: ImageSnapshotKeyOptions,
42
42
  ) {
@@ -65,11 +65,11 @@ export function createVisServerContext() {
65
65
  }
66
66
  },
67
67
 
68
- async getTaskCount(browserContext: PartialBrowserCommandContext, taskId: string) {
68
+ async getTaskCount(browserContext: ExtendedBrowserCommandContext, taskId: string) {
69
69
  return (await context.getSuiteInfo(browserContext, taskId)).task.count
70
70
  },
71
71
  async hasImageSnapshot(
72
- browserContext: PartialBrowserCommandContext,
72
+ browserContext: ExtendedBrowserCommandContext,
73
73
  taskId: string,
74
74
  snapshotKey: string | undefined,
75
75
  ) {
@@ -80,7 +80,7 @@ export function createVisServerContext() {
80
80
  )
81
81
  },
82
82
  getSnapshotFilename(
83
- browserContext: PartialBrowserCommandContext,
83
+ browserContext: ExtendedBrowserCommandContext,
84
84
  info: { taskId: string; task: { count: number } },
85
85
  snapshotKey: string | undefined,
86
86
  ) {
@@ -91,7 +91,7 @@ export function createVisServerContext() {
91
91
  }
92
92
  return `${info.taskId}-${info.task.count}.png`
93
93
  },
94
- async getSuiteInfo(browserContext: PartialBrowserCommandContext, taskId: string) {
94
+ async getSuiteInfo(browserContext: ExtendedBrowserCommandContext, taskId: string) {
95
95
  const projectState = await getSuite(browserContext)
96
96
  const visOptions = getVisOption(browserContext)
97
97
  const moduleId = getTaskSubpath(projectState, browserContext.testPath, visOptions)
@@ -1,4 +1,6 @@
1
- import type { UserConfig } from 'vitest/node'
1
+ import type { Merge } from 'type-plus'
2
+ import type { BrowserCommandContext } from 'vitest/node'
3
+ import type { Awaitable } from '../shared/types.ts'
2
4
 
3
5
  export type VisSuites = {
4
6
  [projectPath: string]: Promise<VisSuite>
@@ -30,33 +32,36 @@ export type VisSuite = {
30
32
  >
31
33
  }
32
34
 
33
- export type PartialBrowserCommandContext = {
34
- project: {
35
- config: {
36
- name: string
37
- root: string
38
- snapshotOptions: {
39
- updateSnapshot: 'all' | 'new' | 'none'
35
+ export type ExtendedBrowserCommand<Payload extends unknown[] = [], ReturnValue = any> = (
36
+ context: ExtendedBrowserCommandContext,
37
+ ...payload: Payload
38
+ ) => Awaitable<ReturnValue>
39
+
40
+ export type ExtendedBrowserCommandContext = {
41
+ page: BrowserCommandContext['page']
42
+ browser: BrowserCommandContext['browser']
43
+ iframe: BrowserCommandContext['iframe']
44
+ testPath: NonNullable<BrowserCommandContext['testPath']>
45
+ provider: BrowserCommandContext['provider']
46
+ // project: BrowserCommandContext['project']
47
+ project: Merge<
48
+ BrowserCommandContext['project'],
49
+ {
50
+ browser: {
51
+ config: {
52
+ browser: {
53
+ name: string
54
+ screenshotFailures: boolean
55
+ screenshotDirectory: string
56
+ }
57
+ }
40
58
  }
41
- testTimeout: number
42
- hookTimeout: number
43
- }
44
- vite: {
45
- config: {
46
- test?: {
47
- name?: UserConfig['name'] | undefined
59
+ config: BrowserCommandContext['project']['config']
60
+ runner: {
61
+ config: {
62
+ name: string
48
63
  }
49
64
  }
50
65
  }
51
- }
52
- provider: {
53
- name: string
54
- browserName?: string | undefined
55
- options?: {
56
- headless?: boolean | undefined
57
- screenshotFailures?: boolean | undefined
58
- screenshotDirectory?: string | undefined
59
- }
60
- }
61
- testPath: string
66
+ >
62
67
  }
@@ -3,6 +3,8 @@ import type { Options as SsimDiffOptions } from 'ssim.js'
3
3
  import type { SnapshotMeta } from '../client/snapshot_meta.ts'
4
4
  import type { NAME } from './constants.ts'
5
5
 
6
+ export type Awaitable<T> = T | PromiseLike<T>
7
+
6
8
  export interface ImageSnapshotTimeoutOptions {
7
9
  /**
8
10
  * Timeout for taking the snapshot.