vitest-plugin-vis 3.5.1 → 4.1.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.
- package/dist/asserts--HSSlgPD.mjs +8 -0
- package/dist/asserts--HSSlgPD.mjs.map +1 -0
- package/dist/augment-C1tjdh5B.d.mts +33 -0
- package/dist/augment-C1tjdh5B.d.mts.map +1 -0
- package/dist/auto_snapshot_matcher-C0y6mAeS.mjs +381 -0
- package/dist/auto_snapshot_matcher-C0y6mAeS.mjs.map +1 -0
- package/dist/auto_snapshot_options-BMRtKmod.d.mts +45 -0
- package/dist/auto_snapshot_options-BMRtKmod.d.mts.map +1 -0
- package/dist/auto_snapshot_options-DUOTpF2N.mjs +88 -0
- package/dist/auto_snapshot_options-DUOTpF2N.mjs.map +1 -0
- package/dist/base64-CHSENEAO.mjs +8 -0
- package/dist/base64-CHSENEAO.mjs.map +1 -0
- package/dist/client-api.d.mts +44 -0
- package/dist/client-api.d.mts.map +1 -0
- package/dist/client-api.mjs +14 -0
- package/dist/client-api.mjs.map +1 -0
- package/dist/commands.types-BVhcnnHw.d.mts +51 -0
- package/dist/commands.types-BVhcnnHw.d.mts.map +1 -0
- package/dist/config.d.mts +28 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +412 -0
- package/dist/config.mjs.map +1 -0
- package/dist/constants-CTBaz8Ml.mjs +10 -0
- package/dist/constants-CTBaz8Ml.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +6 -0
- package/dist/presets/auto.d.mts +1 -0
- package/dist/presets/auto.mjs +19 -0
- package/dist/presets/auto.mjs.map +1 -0
- package/dist/presets/enable.d.mts +1 -0
- package/dist/presets/enable.mjs +15 -0
- package/dist/presets/enable.mjs.map +1 -0
- package/dist/presets/manual.d.mts +1 -0
- package/dist/presets/manual.mjs +15 -0
- package/dist/presets/manual.mjs.map +1 -0
- package/dist/server-utils.d.mts +19 -0
- package/dist/server-utils.d.mts.map +1 -0
- package/dist/server-utils.mjs +4 -0
- package/dist/setup-DCytWz48.mjs +124 -0
- package/dist/setup-DCytWz48.mjs.map +1 -0
- package/dist/setup.d.mts +106 -0
- package/dist/setup.d.mts.map +1 -0
- package/dist/setup.mjs +8 -0
- package/dist/snapshot_path-7GliOSH_.mjs +58 -0
- package/dist/snapshot_path-7GliOSH_.mjs.map +1 -0
- package/dist/src-CSQnlFa9.mjs +1 -0
- package/dist/testing.d.mts +12 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +65550 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/to_match_image_snapshot.types--tTmHoRA.d.mts +9 -0
- package/dist/to_match_image_snapshot.types--tTmHoRA.d.mts.map +1 -0
- package/dist/trim_common_folder-DBThLerp.d.mts +9 -0
- package/dist/trim_common_folder-DBThLerp.d.mts.map +1 -0
- package/dist/types-CEmjj-A9.d.mts +144 -0
- package/dist/types-CEmjj-A9.d.mts.map +1 -0
- package/dist/types-DJYCbyT8.d.mts +63 -0
- package/dist/types-DJYCbyT8.d.mts.map +1 -0
- package/package.json +55 -39
- package/readme.md +58 -6
- package/src/client/actions/has_image_snapshot_action.ts +1 -1
- package/src/client/actions/load_image_snapshot_results_action.ts +1 -1
- package/src/client/actions/match_image_snapshot_action.ts +7 -5
- package/src/client/actions/match_page_image_snapshot_action.ts +6 -4
- package/src/client/expect/_ctx.ts +10 -0
- package/src/client/expect/to_match_image_snapshot.ts +3 -4
- package/src/client/external/browser/has_render_content.ts +3 -0
- package/src/client/{image_resizer.ts → external/browser/image_resizer.ts} +1 -1
- package/src/client/{vitest_browser_context_proxy.ts → external/vitest/vitest_browser_context_proxy.ts} +3 -3
- package/src/client/{vitest_suite_proxy.ts → external/vitest/vitest_suite_proxy.ts} +1 -1
- package/src/client/{align_images.ts → image/align_images.ts} +3 -3
- package/src/client/page/_ctx.ts +12 -0
- package/src/client/page/extend.ts +1 -1
- package/src/client/page/has_image_snapshot.mdx +1 -1
- package/src/client/page/has_image_snapshot.ts +4 -4
- package/src/client/page/to_match_image_snapshot.mdx +1 -1
- package/src/client/page/to_match_image_snapshot.ts +3 -4
- package/src/client/{compare_image_snapshot.logic.ts → snapshot/compare_image_snapshot.logic.ts} +1 -1
- package/src/client/{compare_image_snapshot.ts → snapshot/compare_image_snapshot.ts} +8 -9
- package/src/client/snapshot/should_take_snapshot.ts +6 -0
- package/src/client/suite/_ctx.ts +8 -0
- package/src/client/suite/auto_snapshot_matcher.ts +68 -0
- package/src/client/{ctx.ts → task/_ctx.ts} +1 -3
- package/src/client/{auto_snapshot_options.ts → task/auto_snapshot_options.ts} +20 -5
- package/src/client/{snapshot_meta.ts → task/snapshot_meta.ts} +6 -1
- package/src/client-api.ts +3 -2
- package/src/config/vis.ts +4 -4
- package/src/index.ts +1 -1
- package/src/server/browser_provider/browser_api.ts +2 -2
- package/src/server/browser_provider/playwright.ts +6 -4
- package/src/server/browser_provider/webdriverio.ts +3 -3
- package/src/server/commands/_assertions.ts +3 -3
- package/src/server/commands/augment.ts +9 -7
- package/src/server/commands/has_image_snapshot.ts +3 -6
- package/src/server/commands/image_snapshot_next_index.ts +3 -9
- package/src/server/commands/load_image_snapshot_results.ts +3 -23
- package/src/server/commands/prepare_image_snapshot_comparison.ts +4 -50
- package/src/server/commands/prepare_page_image_snapshot_comparison.ts +3 -45
- package/src/server/commands/setup_vis_suite.ts +3 -27
- package/src/server/project.ts +8 -7
- package/src/server/snapshot.ts +4 -4
- package/src/server/snapshot_path.ts +6 -5
- package/src/server/suite.ts +7 -12
- package/src/server/testing/stubBrowserCommandContext.ts +16 -0
- package/src/{testing → server/testing}/stubSuite.ts +7 -9
- package/src/server/testing/stubUserConfig.ts +6 -0
- package/src/server/vis_options.ts +4 -5
- package/src/server/vis_server_context.logic.ts +8 -8
- package/src/server/vis_server_context.types.ts +31 -26
- package/src/{client/setup → setup}/create_vis.ts +23 -78
- package/src/setup/readme.md +5 -0
- package/src/{client/setup → setup}/vis.ts +1 -1
- package/src/setup.ts +2 -2
- package/src/shared/commands.types.ts +71 -0
- package/src/shared/types.ts +55 -1
- package/src/testing.ts +0 -1
- package/esm/client/actions/has_image_snapshot_action.d.ts +0 -4
- package/esm/client/actions/has_image_snapshot_action.d.ts.map +0 -1
- package/esm/client/actions/has_image_snapshot_action.js +0 -6
- package/esm/client/actions/load_image_snapshot_results_action.d.ts +0 -3
- package/esm/client/actions/load_image_snapshot_results_action.d.ts.map +0 -1
- package/esm/client/actions/load_image_snapshot_results_action.js +0 -3
- package/esm/client/actions/match_image_snapshot_action.d.ts +0 -6
- package/esm/client/actions/match_image_snapshot_action.d.ts.map +0 -1
- package/esm/client/actions/match_image_snapshot_action.js +0 -20
- package/esm/client/actions/match_page_image_snapshot_action.d.ts +0 -6
- package/esm/client/actions/match_page_image_snapshot_action.d.ts.map +0 -1
- package/esm/client/actions/match_page_image_snapshot_action.js +0 -9
- package/esm/client/align_images.d.ts +0 -2
- package/esm/client/align_images.d.ts.map +0 -1
- package/esm/client/align_images.js +0 -10
- package/esm/client/auto_snapshot_options.d.ts +0 -29
- package/esm/client/auto_snapshot_options.d.ts.map +0 -1
- package/esm/client/auto_snapshot_options.js +0 -49
- package/esm/client/compare_image_snapshot.d.ts +0 -6
- package/esm/client/compare_image_snapshot.d.ts.map +0 -1
- package/esm/client/compare_image_snapshot.js +0 -52
- package/esm/client/compare_image_snapshot.logic.d.ts +0 -3
- package/esm/client/compare_image_snapshot.logic.d.ts.map +0 -1
- package/esm/client/compare_image_snapshot.logic.js +0 -12
- package/esm/client/ctx.d.ts +0 -7
- package/esm/client/ctx.d.ts.map +0 -1
- package/esm/client/ctx.js +0 -11
- package/esm/client/expect/augment.d.ts +0 -8
- package/esm/client/expect/augment.d.ts.map +0 -1
- package/esm/client/expect/augment.js +0 -1
- package/esm/client/expect/expectation_result.d.ts +0 -3
- package/esm/client/expect/expectation_result.d.ts.map +0 -1
- package/esm/client/expect/expectation_result.js +0 -5
- package/esm/client/expect/extend.d.ts +0 -2
- package/esm/client/expect/extend.d.ts.map +0 -1
- package/esm/client/expect/extend.js +0 -4
- package/esm/client/expect/to_match_image_snapshot.d.ts +0 -9
- package/esm/client/expect/to_match_image_snapshot.d.ts.map +0 -1
- package/esm/client/expect/to_match_image_snapshot.js +0 -21
- package/esm/client/expect/to_match_image_snapshot.types.d.ts +0 -5
- package/esm/client/expect/to_match_image_snapshot.types.d.ts.map +0 -1
- package/esm/client/expect/to_match_image_snapshot.types.js +0 -1
- package/esm/client/image_data.d.ts +0 -3
- package/esm/client/image_data.d.ts.map +0 -1
- package/esm/client/image_data.js +0 -33
- package/esm/client/image_resizer.d.ts +0 -9
- package/esm/client/image_resizer.d.ts.map +0 -1
- package/esm/client/image_resizer.js +0 -49
- package/esm/client/image_snapshot_options.d.ts +0 -2
- package/esm/client/image_snapshot_options.d.ts.map +0 -1
- package/esm/client/image_snapshot_options.js +0 -6
- package/esm/client/page/augment.d.ts +0 -7
- package/esm/client/page/augment.d.ts.map +0 -1
- package/esm/client/page/augment.js +0 -1
- package/esm/client/page/extend.d.ts +0 -2
- package/esm/client/page/extend.d.ts.map +0 -1
- package/esm/client/page/extend.js +0 -5
- package/esm/client/page/has_image_snapshot.d.ts +0 -10
- package/esm/client/page/has_image_snapshot.d.ts.map +0 -1
- package/esm/client/page/has_image_snapshot.js +0 -15
- package/esm/client/page/to_match_image_snapshot.d.ts +0 -6
- package/esm/client/page/to_match_image_snapshot.d.ts.map +0 -1
- package/esm/client/page/to_match_image_snapshot.js +0 -15
- package/esm/client/selector.d.ts +0 -7
- package/esm/client/selector.d.ts.map +0 -1
- package/esm/client/selector.js +0 -97
- package/esm/client/setup/create_vis.d.ts +0 -96
- package/esm/client/setup/create_vis.d.ts.map +0 -1
- package/esm/client/setup/create_vis.js +0 -109
- package/esm/client/setup/vis.ctx.d.ts +0 -12
- package/esm/client/setup/vis.ctx.d.ts.map +0 -1
- package/esm/client/setup/vis.ctx.js +0 -32
- package/esm/client/setup/vis.d.ts +0 -5
- package/esm/client/setup/vis.d.ts.map +0 -1
- package/esm/client/setup/vis.js +0 -6
- package/esm/client/should_take_snapshot.d.ts +0 -3
- package/esm/client/should_take_snapshot.d.ts.map +0 -1
- package/esm/client/should_take_snapshot.js +0 -3
- package/esm/client/snapshot_meta.d.ts +0 -6
- package/esm/client/snapshot_meta.d.ts.map +0 -1
- package/esm/client/snapshot_meta.js +0 -1
- package/esm/client/task_id.d.ts +0 -7
- package/esm/client/task_id.d.ts.map +0 -1
- package/esm/client/task_id.js +0 -10
- package/esm/client/vitest_browser_context_proxy.d.ts +0 -32
- package/esm/client/vitest_browser_context_proxy.d.ts.map +0 -1
- package/esm/client/vitest_browser_context_proxy.js +0 -11
- package/esm/client/vitest_suite_proxy.d.ts +0 -7
- package/esm/client/vitest_suite_proxy.d.ts.map +0 -1
- package/esm/client/vitest_suite_proxy.js +0 -8
- package/esm/client-api.d.ts +0 -12
- package/esm/client-api.d.ts.map +0 -1
- package/esm/client-api.js +0 -9
- package/esm/commands.d.ts +0 -5
- package/esm/commands.d.ts.map +0 -1
- package/esm/commands.js +0 -4
- package/esm/config/types.d.ts +0 -60
- package/esm/config/types.d.ts.map +0 -1
- package/esm/config/types.js +0 -1
- package/esm/config/vis.d.ts +0 -28
- package/esm/config/vis.d.ts.map +0 -1
- package/esm/config/vis.js +0 -27
- package/esm/config.d.ts +0 -4
- package/esm/config.d.ts.map +0 -1
- package/esm/config.js +0 -2
- package/esm/index.d.ts +0 -5
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -4
- package/esm/presets/auto.d.ts +0 -2
- package/esm/presets/auto.d.ts.map +0 -1
- package/esm/presets/auto.js +0 -8
- package/esm/presets/enable.d.ts +0 -2
- package/esm/presets/enable.d.ts.map +0 -1
- package/esm/presets/enable.js +0 -4
- package/esm/presets/manual.d.ts +0 -2
- package/esm/presets/manual.d.ts.map +0 -1
- package/esm/presets/manual.js +0 -4
- package/esm/server/browser_provider/browser_api.d.ts +0 -3
- package/esm/server/browser_provider/browser_api.d.ts.map +0 -1
- package/esm/server/browser_provider/browser_api.js +0 -11
- package/esm/server/browser_provider/playwright.d.ts +0 -4
- package/esm/server/browser_provider/playwright.d.ts.map +0 -1
- package/esm/server/browser_provider/playwright.js +0 -18
- package/esm/server/browser_provider/types.d.ts +0 -10
- package/esm/server/browser_provider/types.d.ts.map +0 -1
- package/esm/server/browser_provider/types.js +0 -1
- package/esm/server/browser_provider/webdriverio.d.ts +0 -4
- package/esm/server/browser_provider/webdriverio.d.ts.map +0 -1
- package/esm/server/browser_provider/webdriverio.js +0 -12
- package/esm/server/commands/_assertions.d.ts +0 -5
- package/esm/server/commands/_assertions.d.ts.map +0 -1
- package/esm/server/commands/_assertions.js +0 -11
- package/esm/server/commands/augment.d.ts +0 -11
- package/esm/server/commands/augment.d.ts.map +0 -1
- package/esm/server/commands/augment.js +0 -1
- package/esm/server/commands/commands.d.ts +0 -9
- package/esm/server/commands/commands.d.ts.map +0 -1
- package/esm/server/commands/commands.js +0 -14
- package/esm/server/commands/has_image_snapshot.d.ts +0 -6
- package/esm/server/commands/has_image_snapshot.d.ts.map +0 -1
- package/esm/server/commands/has_image_snapshot.js +0 -6
- package/esm/server/commands/image_snapshot_next_index.d.ts +0 -9
- package/esm/server/commands/image_snapshot_next_index.d.ts.map +0 -1
- package/esm/server/commands/image_snapshot_next_index.js +0 -6
- package/esm/server/commands/load_image_snapshot_results.d.ts +0 -21
- package/esm/server/commands/load_image_snapshot_results.d.ts.map +0 -1
- package/esm/server/commands/load_image_snapshot_results.js +0 -6
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +0 -38
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +0 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.js +0 -34
- package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts +0 -35
- package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts.map +0 -1
- package/esm/server/commands/prepare_page_image_snapshot_comparison.js +0 -27
- package/esm/server/commands/setup_vis_suite.d.ts +0 -15
- package/esm/server/commands/setup_vis_suite.d.ts.map +0 -1
- package/esm/server/commands/setup_vis_suite.js +0 -6
- package/esm/server/commands/types.d.ts +0 -3
- package/esm/server/commands/types.d.ts.map +0 -1
- package/esm/server/commands/types.js +0 -1
- package/esm/server/externals/file.d.ts +0 -10
- package/esm/server/externals/file.d.ts.map +0 -1
- package/esm/server/externals/file.js +0 -20
- package/esm/server/project.d.ts +0 -21
- package/esm/server/project.d.ts.map +0 -1
- package/esm/server/project.js +0 -13
- package/esm/server/snapshot.d.ts +0 -6
- package/esm/server/snapshot.d.ts.map +0 -1
- package/esm/server/snapshot.js +0 -29
- package/esm/server/snapshot_path.d.ts +0 -14
- package/esm/server/snapshot_path.d.ts.map +0 -1
- package/esm/server/snapshot_path.js +0 -34
- package/esm/server/snapshot_writer.d.ts +0 -13
- package/esm/server/snapshot_writer.d.ts.map +0 -1
- package/esm/server/snapshot_writer.js +0 -15
- package/esm/server/suite.d.ts +0 -54
- package/esm/server/suite.d.ts.map +0 -1
- package/esm/server/suite.js +0 -73
- package/esm/server/vis_options.d.ts +0 -19
- package/esm/server/vis_options.d.ts.map +0 -1
- package/esm/server/vis_options.js +0 -14
- package/esm/server/vis_server_context.d.ts +0 -50
- package/esm/server/vis_server_context.d.ts.map +0 -1
- package/esm/server/vis_server_context.deps.d.ts +0 -29
- package/esm/server/vis_server_context.deps.d.ts.map +0 -1
- package/esm/server/vis_server_context.deps.js +0 -10
- package/esm/server/vis_server_context.js +0 -2
- package/esm/server/vis_server_context.logic.d.ts +0 -53
- package/esm/server/vis_server_context.logic.d.ts.map +0 -1
- package/esm/server/vis_server_context.logic.js +0 -79
- package/esm/server/vis_server_context.types.d.ts +0 -54
- package/esm/server/vis_server_context.types.d.ts.map +0 -1
- package/esm/server/vis_server_context.types.js +0 -1
- package/esm/server-utils.d.ts +0 -4
- package/esm/server-utils.d.ts.map +0 -1
- package/esm/server-utils.js +0 -3
- package/esm/setup.d.ts +0 -5
- package/esm/setup.d.ts.map +0 -1
- package/esm/setup.js +0 -5
- package/esm/shared/asserts.d.ts +0 -2
- package/esm/shared/asserts.d.ts.map +0 -1
- package/esm/shared/asserts.js +0 -5
- package/esm/shared/base64.d.ts +0 -2
- package/esm/shared/base64.d.ts.map +0 -1
- package/esm/shared/base64.js +0 -3
- package/esm/shared/compare_image.d.ts +0 -6
- package/esm/shared/compare_image.d.ts.map +0 -1
- package/esm/shared/compare_image.js +0 -42
- package/esm/shared/constants.d.ts +0 -6
- package/esm/shared/constants.d.ts.map +0 -1
- package/esm/shared/constants.js +0 -5
- package/esm/shared/convert_threshold_unit.d.ts +0 -6
- package/esm/shared/convert_threshold_unit.d.ts.map +0 -1
- package/esm/shared/convert_threshold_unit.js +0 -10
- package/esm/shared/get_max_size.d.ts +0 -11
- package/esm/shared/get_max_size.d.ts.map +0 -1
- package/esm/shared/get_max_size.js +0 -5
- package/esm/shared/is_same_size.d.ts +0 -8
- package/esm/shared/is_same_size.d.ts.map +0 -1
- package/esm/shared/is_same_size.js +0 -3
- package/esm/shared/trim_common_folder.d.ts +0 -6
- package/esm/shared/trim_common_folder.d.ts.map +0 -1
- package/esm/shared/trim_common_folder.js +0 -11
- package/esm/shared/types.d.ts +0 -90
- package/esm/shared/types.d.ts.map +0 -1
- package/esm/shared/types.js +0 -1
- package/esm/testing/constants.d.ts +0 -9
- package/esm/testing/constants.d.ts.map +0 -1
- package/esm/testing/constants.js +0 -1933
- package/esm/testing/stubBrowserCommandContext.d.ts +0 -8
- package/esm/testing/stubBrowserCommandContext.d.ts.map +0 -1
- package/esm/testing/stubBrowserCommandContext.js +0 -12
- package/esm/testing/stubSuite.d.ts +0 -10
- package/esm/testing/stubSuite.d.ts.map +0 -1
- package/esm/testing/stubSuite.js +0 -27
- package/esm/testing/stubUserConfig.d.ts +0 -7
- package/esm/testing/stubUserConfig.d.ts.map +0 -1
- package/esm/testing/stubUserConfig.js +0 -4
- package/esm/testing.d.ts +0 -3
- package/esm/testing.d.ts.map +0 -1
- package/esm/testing.js +0 -2
- package/src/client/image_snapshot_options.ts +0 -6
- package/src/client/setup/vis.ctx.ts +0 -33
- package/src/client/should_take_snapshot.ts +0 -5
- package/src/server/commands/types.ts +0 -9
- package/src/testing/stubBrowserCommandContext.ts +0 -16
- package/src/testing/stubUserConfig.ts +0 -6
- /package/src/client/{image_data.ts → external/browser/image_data.ts} +0 -0
- /package/src/client/{selector.ts → external/browser/selector.ts} +0 -0
- /package/src/client/{auto_snapshot_options.mdx → task/auto_snapshot_options.mdx} +0 -0
- /package/src/client/{task_id.ts → task/task_id.ts} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type BrowserPage, commands } from 'vitest/browser'
|
|
2
|
+
import { getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
|
|
3
|
+
|
|
4
|
+
export type { BrowserPage }
|
|
5
|
+
|
|
6
|
+
export const ctx = {
|
|
7
|
+
commands,
|
|
8
|
+
getCurrentTest,
|
|
9
|
+
__test__reset() {
|
|
10
|
+
ctx.getCurrentTest = getCurrentTest
|
|
11
|
+
},
|
|
12
|
+
}
|
|
@@ -11,7 +11,7 @@ This method allows you to conditionally execute code based on whether a snapshot
|
|
|
11
11
|
## Basic Usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { page } from '
|
|
14
|
+
import { page } from 'vitest/browser'
|
|
15
15
|
|
|
16
16
|
it('should check if snapshot exists', async ({ expect }) => {
|
|
17
17
|
const hasSnapshot = await page.hasImageSnapshot()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type BrowserPage, commands } from '@vitest/browser/context'
|
|
2
1
|
import type { ImageSnapshotKeyOptions } from '../../shared/types.ts'
|
|
3
2
|
import { hasImageSnapshotAction } from '../actions/has_image_snapshot_action.ts'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { toTaskId } from '../task/task_id.ts'
|
|
4
|
+
import type { BrowserPage } from './_ctx.ts'
|
|
5
|
+
import { ctx } from './_ctx.ts'
|
|
6
6
|
|
|
7
7
|
export interface HasImageSnapshotAction {
|
|
8
8
|
/**
|
|
@@ -23,5 +23,5 @@ export function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOp
|
|
|
23
23
|
"concurrent tests run at the same time in the same iframe and affect each other's environment. ",
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
|
-
return hasImageSnapshotAction(commands, toTaskId(test), options)
|
|
26
|
+
return hasImageSnapshotAction(ctx.commands, toTaskId(test), options)
|
|
27
27
|
}
|
|
@@ -11,7 +11,7 @@ Unlike `expect().toMatchImageSnapshot()` which targets specific elements, `page.
|
|
|
11
11
|
## Basic Usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { page } from '
|
|
14
|
+
import { page } from 'vitest/browser'
|
|
15
15
|
|
|
16
16
|
it('should take a page snapshot', async () => {
|
|
17
17
|
// Your test setup here
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { commands } from '@vitest/browser/context'
|
|
2
1
|
import type { ComparisonMethod, ToMatchPageImageSnapshotOptions } from '../../shared/types.ts'
|
|
3
2
|
import { matchPageImageSnapshotAction } from '../actions/match_page_image_snapshot_action.ts'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { toTaskId } from '../task/task_id.ts'
|
|
4
|
+
import { ctx } from './_ctx.ts'
|
|
6
5
|
|
|
7
6
|
export interface ToMatchImageSnapshotAction {
|
|
8
7
|
toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(
|
|
@@ -25,5 +24,5 @@ export function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(
|
|
|
25
24
|
)
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
return matchPageImageSnapshotAction(commands, toTaskId(test), options)
|
|
27
|
+
return matchPageImageSnapshotAction(ctx.commands, toTaskId(test), options)
|
|
29
28
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { BrowserCommands } from '@vitest/browser/context'
|
|
2
1
|
import dedent from 'dedent'
|
|
3
2
|
import { resolve } from 'pathe'
|
|
4
|
-
import type {
|
|
3
|
+
import type { BrowserCommands } from 'vitest/browser'
|
|
5
4
|
import type {
|
|
6
|
-
|
|
5
|
+
ImageSnapshotNextIndexCommand,
|
|
7
6
|
PrepareImageSnapshotComparisonCommand,
|
|
8
|
-
} from '
|
|
9
|
-
import { compareImage } from '
|
|
10
|
-
import type { ToMatchImageSnapshotOptions } from '
|
|
11
|
-
import {
|
|
7
|
+
} from '../../shared/commands.types.ts'
|
|
8
|
+
import { compareImage } from '../../shared/compare_image.ts'
|
|
9
|
+
import type { ImageSnapshotComparisonInfo, ToMatchImageSnapshotOptions } from '../../shared/types.ts'
|
|
10
|
+
import { toDataURL, toImageData } from '../external/browser/image_data.ts'
|
|
11
|
+
import { server } from '../external/vitest/vitest_browser_context_proxy.ts'
|
|
12
|
+
import { alignImagesToSameSize } from '../image/align_images.ts'
|
|
12
13
|
import { prettifyOptions } from './compare_image_snapshot.logic.ts'
|
|
13
|
-
import { toDataURL, toImageData } from './image_data.ts'
|
|
14
|
-
import { server } from './vitest_browser_context_proxy.ts'
|
|
15
14
|
|
|
16
15
|
export async function compareImageSnapshot(
|
|
17
16
|
commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import dedent from 'dedent'
|
|
2
|
+
import type { SetupVisSuiteCommand } from '../../shared/commands.types.ts'
|
|
3
|
+
import type { ComparisonMethod } from '../../shared/types.ts'
|
|
4
|
+
import { shouldTakeSnapshot } from '../snapshot/should_take_snapshot.ts'
|
|
5
|
+
import { extractAutoSnapshotOptions } from '../task/auto_snapshot_options.ts'
|
|
6
|
+
import type { SnapshotMeta } from '../task/snapshot_meta.ts'
|
|
7
|
+
import { toTaskId } from '../task/task_id.ts'
|
|
8
|
+
import { ctx } from './_ctx.ts'
|
|
9
|
+
|
|
10
|
+
export function autoSnapshotMatcher<GM extends Record<string, any> | unknown = unknown>(
|
|
11
|
+
commands: SetupVisSuiteCommand,
|
|
12
|
+
expect: any,
|
|
13
|
+
) {
|
|
14
|
+
let subject: string | undefined
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
async setup() {
|
|
18
|
+
subject = (await commands.setupVisSuite()).subject
|
|
19
|
+
},
|
|
20
|
+
createMatcher<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
|
|
21
|
+
themes: Record<
|
|
22
|
+
string,
|
|
23
|
+
boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)
|
|
24
|
+
>,
|
|
25
|
+
) {
|
|
26
|
+
return async function matchImageSnapshot() {
|
|
27
|
+
const test = ctx.getCurrentTest()
|
|
28
|
+
if ((test?.result?.errors?.length ?? 0) > 0) return
|
|
29
|
+
|
|
30
|
+
const meta = extractAutoSnapshotOptions(test)
|
|
31
|
+
if (!shouldTakeSnapshot(meta)) return
|
|
32
|
+
const errors: Array<[string, Error]> = []
|
|
33
|
+
for (const themeId in themes) {
|
|
34
|
+
try {
|
|
35
|
+
await new Promise((a) => setTimeout(a, 10))
|
|
36
|
+
const theme = themes[themeId]
|
|
37
|
+
const r = typeof theme === 'function' ? await theme(meta! as any) : theme
|
|
38
|
+
if (r === false) continue
|
|
39
|
+
await expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
|
|
40
|
+
...meta,
|
|
41
|
+
snapshotKey: meta?.snapshotKey ?? themeId,
|
|
42
|
+
})
|
|
43
|
+
} catch (error) {
|
|
44
|
+
errors.push([themeId, error as Error])
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
if (errors.length === 1) throw errors[0]![1]
|
|
49
|
+
const taskId = toTaskId(test!)
|
|
50
|
+
throw new AggregateError(
|
|
51
|
+
errors,
|
|
52
|
+
dedent`Snapshot \`${taskId}\` mismatched
|
|
53
|
+
|
|
54
|
+
${errors
|
|
55
|
+
.map(([themeId, error]) => {
|
|
56
|
+
return `Theme \`${themeId}\` failed: ${error.message}`
|
|
57
|
+
})
|
|
58
|
+
.join('\n\n')}`,
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getSubject(selectors: string | undefined) {
|
|
67
|
+
return selectors ? (document.querySelector(selectors) ?? document.body) : document.body
|
|
68
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { getCurrentSuite, getCurrentTest } from '
|
|
1
|
+
import { getCurrentSuite, getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
|
|
2
2
|
|
|
3
3
|
export const ctx = {
|
|
4
|
-
autoEnabled: undefined as boolean | undefined,
|
|
5
4
|
getCurrentTest,
|
|
6
5
|
getCurrentSuite,
|
|
7
6
|
__test__reset() {
|
|
8
7
|
ctx.getCurrentTest = getCurrentTest
|
|
9
8
|
ctx.getCurrentSuite = getCurrentSuite
|
|
10
|
-
ctx.autoEnabled = undefined
|
|
11
9
|
},
|
|
12
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { assertSnapshotKeyWithoutDash } from '
|
|
2
|
-
import { NAME } from '
|
|
3
|
-
import type { ComparisonMethod } from '
|
|
4
|
-
import { ctx } from './
|
|
1
|
+
import { assertSnapshotKeyWithoutDash } from '../../shared/asserts.ts'
|
|
2
|
+
import { NAME } from '../../shared/constants.ts'
|
|
3
|
+
import type { ComparisonMethod } from '../../shared/types.ts'
|
|
4
|
+
import { ctx } from './_ctx.ts'
|
|
5
5
|
import type { SnapshotMeta } from './snapshot_meta.ts'
|
|
6
6
|
|
|
7
7
|
type Suite = { meta: Record<string, any>; suite?: Suite | undefined }
|
|
@@ -17,6 +17,21 @@ export type MetaTask =
|
|
|
17
17
|
/**
|
|
18
18
|
* Set the snapshot options for auto snapshot.
|
|
19
19
|
*
|
|
20
|
+
* You can use it in beforeAll, beforeEach, or individual test cases.
|
|
21
|
+
*
|
|
22
|
+
* @param meta - The snapshot options to set.
|
|
23
|
+
* You can pass a boolean to enable/disable the snapshot, or an object with the snapshot options.
|
|
24
|
+
* When passing an object, the `enable` property will be set to `true` by default unless you explicitly set it to `false`.
|
|
25
|
+
* @param meta.enable - Whether to enable the snapshot.
|
|
26
|
+
* @param meta.snapshotKey - The key to use for the snapshot.
|
|
27
|
+
* @param meta.comparisonMethod - The comparison method to use for the snapshot.
|
|
28
|
+
* @param meta.diffOptions - The diff options to use for the snapshot.
|
|
29
|
+
* @param meta.failureThreshold - The failure threshold to use for the snapshot.
|
|
30
|
+
* @param meta.failureThresholdType - The failure threshold type to use for the snapshot.
|
|
31
|
+
* @param meta.timeout - The timeout to use for the snapshot.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
20
35
|
* ```ts
|
|
21
36
|
* beforeAll(() => setAutoSnapshotOptions(...))
|
|
22
37
|
* beforeEach(() => setAutoSnapshotOptions(...))
|
|
@@ -26,7 +41,7 @@ export type MetaTask =
|
|
|
26
41
|
* })
|
|
27
42
|
* ```
|
|
28
43
|
*/
|
|
29
|
-
export function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: SnapshotMeta<M>
|
|
44
|
+
export function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: boolean | SnapshotMeta<M>): void {
|
|
30
45
|
if (typeof meta === 'object') {
|
|
31
46
|
assertSnapshotKeyWithoutDash(meta.snapshotKey)
|
|
32
47
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { ComparisonMethod, ImageSnapshotSubjectOptions, ToMatchImageSnapshotOptions } from '
|
|
1
|
+
import type { ComparisonMethod, ImageSnapshotSubjectOptions, ToMatchImageSnapshotOptions } from '../../shared/types.ts'
|
|
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
|
}
|
package/src/client-api.ts
CHANGED
|
@@ -4,9 +4,10 @@ export * from './client/actions/has_image_snapshot_action.ts'
|
|
|
4
4
|
export * from './client/actions/load_image_snapshot_results_action.ts'
|
|
5
5
|
export * from './client/actions/match_image_snapshot_action.ts'
|
|
6
6
|
export * from './client/actions/match_page_image_snapshot_action.ts'
|
|
7
|
-
export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts'
|
|
8
7
|
export * from './client/expect/expectation_result.ts'
|
|
9
8
|
export type * from './client/expect/to_match_image_snapshot.types.ts'
|
|
10
|
-
export * from './client/
|
|
9
|
+
export * from './client/suite/auto_snapshot_matcher.ts'
|
|
10
|
+
export { setAutoSnapshotOptions, type MetaTask } from './client/task/auto_snapshot_options.ts'
|
|
11
|
+
export * from './client/task/task_id.ts'
|
|
11
12
|
export * from './shared/constants.ts'
|
|
12
13
|
export type * from './shared/types.ts'
|
package/src/config/vis.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
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
|
|
30
|
+
} satisfies Plugin
|
|
31
31
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
import './client/expect/augment.ts'
|
|
3
3
|
import './client/page/augment.ts'
|
|
4
4
|
|
|
5
|
-
export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts'
|
|
5
|
+
export { setAutoSnapshotOptions, type MetaTask } from './client/task/auto_snapshot_options.ts'
|
|
6
6
|
export type * from './shared/types.ts'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
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 {
|
|
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:
|
|
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 =
|
|
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
|
|
17
|
+
return page.screenshot({
|
|
16
18
|
path: resolve(projectRoot, relativeFilePath),
|
|
17
19
|
...options,
|
|
18
20
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
5
|
-
const browser = context
|
|
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 {
|
|
3
|
+
import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
|
|
4
4
|
|
|
5
5
|
export function assertTestPathDefined(
|
|
6
|
-
context:
|
|
6
|
+
context: ExtendedBrowserCommandContext,
|
|
7
7
|
commandName: string,
|
|
8
|
-
): asserts context is RequiredPick<
|
|
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
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type {
|
|
2
|
+
HasImageSnapshotCommand,
|
|
3
|
+
ImageSnapshotNextIndexCommand,
|
|
4
|
+
LoadImageSnapshotResultsCommand,
|
|
5
|
+
PrepareImageSnapshotComparisonCommand,
|
|
6
|
+
PreparePageImageSnapshotComparisonCommand,
|
|
7
|
+
SetupVisSuiteCommand,
|
|
8
|
+
} from '../../shared/commands.types.ts'
|
|
7
9
|
|
|
8
|
-
declare module '
|
|
10
|
+
declare module 'vitest/browser' {
|
|
9
11
|
interface BrowserCommands
|
|
10
12
|
extends SetupVisSuiteCommand,
|
|
11
13
|
ImageSnapshotNextIndexCommand,
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HasImageSnapshotCommand } from '../../shared/commands.types.ts'
|
|
2
2
|
import { visServerContext } from '../vis_server_context.ts'
|
|
3
|
+
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
3
4
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const hasImageSnapshot: BrowserCommand<Parameters<HasImageSnapshotCommand['hasImageSnapshot']>> = async (
|
|
6
|
+
export const hasImageSnapshot: ExtendedBrowserCommand<Parameters<HasImageSnapshotCommand['hasImageSnapshot']>> = async (
|
|
10
7
|
context,
|
|
11
8
|
taskId,
|
|
12
9
|
snapshotKey,
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ImageSnapshotNextIndexCommand } from '../../shared/commands.types.ts'
|
|
2
2
|
import { visServerContext } from '../vis_server_context.ts'
|
|
3
|
+
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
3
4
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
/**
|
|
7
|
-
* Get the index of the snapshot image to be created.
|
|
8
|
-
*/
|
|
9
|
-
imageSnapshotNextIndex(taskId: string): Promise<number>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const imageSnapshotNextIndex: BrowserCommand<
|
|
6
|
+
export const imageSnapshotNextIndex: ExtendedBrowserCommand<
|
|
13
7
|
Parameters<ImageSnapshotNextIndexCommand['imageSnapshotNextIndex']>
|
|
14
8
|
> = async (context, taskId) => {
|
|
15
9
|
assertTestPathDefined(context, 'imageSnapshotNextIndex')
|
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ImageSnapshotResult } from '../../shared/commands.types.ts'
|
|
2
2
|
import { visServerContext } from '../vis_server_context.ts'
|
|
3
|
+
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
3
4
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
filename: string
|
|
7
|
-
/**
|
|
8
|
-
* The base64 encoded image of the baseline snapshot.
|
|
9
|
-
*/
|
|
10
|
-
baseline?: string | undefined
|
|
11
|
-
/**
|
|
12
|
-
* The base64 encoded image of the result snapshot.
|
|
13
|
-
*/
|
|
14
|
-
result?: string | undefined
|
|
15
|
-
/**
|
|
16
|
-
* The base64 encoded image of the diff snapshot.
|
|
17
|
-
*/
|
|
18
|
-
diff?: string | undefined
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface LoadImageSnapshotResultsCommand {
|
|
22
|
-
loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const loadImageSnapshotResults: BrowserCommand<[taskId: string]> = async (
|
|
6
|
+
export const loadImageSnapshotResults: ExtendedBrowserCommand<[taskId: string]> = async (
|
|
26
7
|
context,
|
|
27
8
|
taskId,
|
|
28
9
|
): Promise<ImageSnapshotResult[]> => {
|
|
29
10
|
assertTestPathDefined(context, 'loadImageSnapshotResults')
|
|
30
|
-
|
|
31
11
|
return visServerContext.getSnapshotResults(context, taskId)
|
|
32
12
|
}
|
|
@@ -1,62 +1,16 @@
|
|
|
1
1
|
import { resolve } from 'pathe'
|
|
2
|
-
import type { BrowserCommand } from 'vitest/node'
|
|
3
2
|
import { isBase64String } from '../../shared/base64.ts'
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
ImageSnapshotTimeoutOptions,
|
|
7
|
-
PixelComparisonOptions,
|
|
8
|
-
SsimComparisonOptions,
|
|
9
|
-
} from '../../shared/types.ts'
|
|
3
|
+
import type { PrepareImageSnapshotComparisonCommand } from '../../shared/commands.types.ts'
|
|
4
|
+
import type { ImageSnapshotComparisonInfo } from '../../shared/types.ts'
|
|
10
5
|
import { file } from '../externals/file.ts'
|
|
11
6
|
import { getProjectRoot } from '../project.ts'
|
|
12
7
|
import { takeSnapshot, takeSnapshotByBrowser } from '../snapshot.ts'
|
|
13
8
|
import { snapshotWriter } from '../snapshot_writer.ts'
|
|
14
9
|
import { visServerContext } from '../vis_server_context.ts'
|
|
10
|
+
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
15
11
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
16
|
-
import type { MatchImageSnapshotOptions } from './types.ts'
|
|
17
12
|
|
|
18
|
-
export
|
|
19
|
-
/**
|
|
20
|
-
* Path to the project root.
|
|
21
|
-
*/
|
|
22
|
-
projectRoot: string
|
|
23
|
-
/**
|
|
24
|
-
* Path to the baseline image relative to the project root.
|
|
25
|
-
*/
|
|
26
|
-
baselinePath: string
|
|
27
|
-
/**
|
|
28
|
-
* Path to the result image relative to the project root.
|
|
29
|
-
*/
|
|
30
|
-
resultPath: string
|
|
31
|
-
/**
|
|
32
|
-
* Path to the diff image relative to the project root.
|
|
33
|
-
*/
|
|
34
|
-
diffPath: string
|
|
35
|
-
/**
|
|
36
|
-
* Base64 encoded baseline image.
|
|
37
|
-
*/
|
|
38
|
-
baseline: string
|
|
39
|
-
/**
|
|
40
|
-
* Base64 encoded result image.
|
|
41
|
-
*/
|
|
42
|
-
result: string
|
|
43
|
-
/**
|
|
44
|
-
* Base64 encoded diff image.
|
|
45
|
-
*/
|
|
46
|
-
diff?: string | undefined
|
|
47
|
-
} & ImageSnapshotTimeoutOptions &
|
|
48
|
-
FailureThresholdOptions &
|
|
49
|
-
(SsimComparisonOptions | PixelComparisonOptions)
|
|
50
|
-
|
|
51
|
-
export interface PrepareImageSnapshotComparisonCommand {
|
|
52
|
-
prepareImageSnapshotComparison: (
|
|
53
|
-
taskId: string,
|
|
54
|
-
subject: string,
|
|
55
|
-
options?: MatchImageSnapshotOptions | undefined,
|
|
56
|
-
) => Promise<ImageSnapshotComparisonInfo | undefined>
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const prepareImageSnapshotComparison: BrowserCommand<
|
|
13
|
+
export const prepareImageSnapshotComparison: ExtendedBrowserCommand<
|
|
60
14
|
Parameters<PrepareImageSnapshotComparisonCommand['prepareImageSnapshotComparison']>
|
|
61
15
|
> = async (context, taskId, subject, options): Promise<ImageSnapshotComparisonInfo | undefined> => {
|
|
62
16
|
assertTestPathDefined(context, 'prepareImageSnapshotComparison')
|
|
@@ -1,55 +1,13 @@
|
|
|
1
1
|
import { resolve } from 'pathe'
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
FailureThresholdOptions,
|
|
5
|
-
ImageSnapshotTimeoutOptions,
|
|
6
|
-
PixelComparisonOptions,
|
|
7
|
-
SsimComparisonOptions,
|
|
8
|
-
} from '../../shared/types.ts'
|
|
2
|
+
import type { PreparePageImageSnapshotComparisonCommand } from '../../shared/commands.types.ts'
|
|
9
3
|
import { file } from '../externals/file.ts'
|
|
10
4
|
import { getProjectRoot } from '../project.ts'
|
|
11
5
|
import { takePageSnapshot } from '../snapshot.ts'
|
|
12
6
|
import { visServerContext } from '../vis_server_context.ts'
|
|
7
|
+
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
13
8
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
14
|
-
import type { MatchImageSnapshotOptions } from './types.ts'
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Path to the project root.
|
|
19
|
-
*/
|
|
20
|
-
projectRoot: string
|
|
21
|
-
/**
|
|
22
|
-
* Path to the baseline image relative to the project root.
|
|
23
|
-
*/
|
|
24
|
-
baselinePath: string
|
|
25
|
-
/**
|
|
26
|
-
* Path to the result image relative to the project root.
|
|
27
|
-
*/
|
|
28
|
-
resultPath: string
|
|
29
|
-
/**
|
|
30
|
-
* Path to the diff image relative to the project root.
|
|
31
|
-
*/
|
|
32
|
-
diffPath: string
|
|
33
|
-
/**
|
|
34
|
-
* Base64 encoded baseline image.
|
|
35
|
-
*/
|
|
36
|
-
baseline: string
|
|
37
|
-
/**
|
|
38
|
-
* Base64 encoded result image.
|
|
39
|
-
*/
|
|
40
|
-
result: string
|
|
41
|
-
} & ImageSnapshotTimeoutOptions &
|
|
42
|
-
FailureThresholdOptions &
|
|
43
|
-
(SsimComparisonOptions | PixelComparisonOptions)
|
|
44
|
-
|
|
45
|
-
export interface PreparePageImageSnapshotComparisonCommand {
|
|
46
|
-
preparePageImageSnapshotComparison: (
|
|
47
|
-
taskId: string,
|
|
48
|
-
options?: MatchImageSnapshotOptions | undefined,
|
|
49
|
-
) => Promise<ImageSnapshotComparisonInfo | undefined>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const preparePageImageSnapshotComparison: BrowserCommand<
|
|
10
|
+
export const preparePageImageSnapshotComparison: ExtendedBrowserCommand<
|
|
53
11
|
Parameters<PreparePageImageSnapshotComparisonCommand['preparePageImageSnapshotComparison']>
|
|
54
12
|
> = async (context, taskId, options) => {
|
|
55
13
|
assertTestPathDefined(context, 'preparePageImageSnapshotComparison')
|
|
@@ -1,32 +1,8 @@
|
|
|
1
|
-
import type { Pick } from 'type-plus'
|
|
2
|
-
import type { BrowserCommand } from 'vitest/node'
|
|
3
|
-
import type { VisOptions } from '../../config/types.ts'
|
|
4
1
|
import { setupSuite } from '../suite.ts'
|
|
2
|
+
import type { ExtendedBrowserCommand, ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
|
|
5
3
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
6
4
|
|
|
7
|
-
export
|
|
8
|
-
/**
|
|
9
|
-
* Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
|
|
10
|
-
* When this command is run for the first time,
|
|
11
|
-
* it will remove the results and diffs directory of all suites.
|
|
12
|
-
*
|
|
13
|
-
* In subsequent runs, it will only remove the results and diffs directory of the current suite.
|
|
14
|
-
*/
|
|
15
|
-
setupVisSuite: () => Promise<
|
|
16
|
-
Pick<
|
|
17
|
-
VisOptions,
|
|
18
|
-
| 'comparisonMethod'
|
|
19
|
-
| 'diffOptions'
|
|
20
|
-
| 'failureThreshold'
|
|
21
|
-
| 'failureThresholdType'
|
|
22
|
-
| 'snapshotKey'
|
|
23
|
-
| 'subject'
|
|
24
|
-
| 'timeout'
|
|
25
|
-
>
|
|
26
|
-
>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const setupVisSuite: BrowserCommand<[]> = async (context): Promise<{ subject: string | undefined }> => {
|
|
5
|
+
export const setupVisSuite: ExtendedBrowserCommand<[]> = async (context): Promise<{ subject: string | undefined }> => {
|
|
30
6
|
assertTestPathDefined(context, 'setupVisSuite')
|
|
31
|
-
return setupSuite(context)
|
|
7
|
+
return setupSuite(context as unknown as ExtendedBrowserCommandContext)
|
|
32
8
|
}
|