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
package/src/server/project.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
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
|
-
|
|
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
|
|
package/src/server/snapshot.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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 {
|
|
6
|
+
import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
|
|
7
7
|
|
|
8
|
-
export function resolveSnapshotRootDir(browserCommandContext:
|
|
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:
|
|
15
|
+
browserName: config.browser.name,
|
|
15
16
|
providerName: browserCommandContext.provider.name,
|
|
16
17
|
platform,
|
|
17
|
-
screenshotFailures:
|
|
18
|
-
screenshotDirectory:
|
|
18
|
+
screenshotFailures: config.browser.screenshotFailures,
|
|
19
|
+
screenshotDirectory: config.browser.screenshotDirectory,
|
|
19
20
|
})
|
|
20
21
|
}
|
|
21
22
|
|
package/src/server/suite.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
4
|
-
import type {
|
|
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<
|
|
10
|
-
partialBrowserCommandContext: RecursivePartial<
|
|
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<
|
|
18
|
+
requiredDeep<RecursivePartial<ExtendedBrowserCommandContext>>(
|
|
19
19
|
{
|
|
20
20
|
project: {
|
|
21
21
|
config: { root },
|
|
22
|
-
|
|
22
|
+
runner: {
|
|
23
23
|
config: {
|
|
24
|
-
|
|
25
|
-
name: partialUserConfig.test?.name,
|
|
26
|
-
},
|
|
24
|
+
name: partialUserConfig.test?.name as string | undefined,
|
|
27
25
|
},
|
|
28
26
|
},
|
|
29
27
|
},
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import type {
|
|
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?:
|
|
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:
|
|
22
|
+
export function getVisOption(context: ExtendedBrowserCommandContext) {
|
|
23
23
|
const id = getProjectName(context) ?? DEFAULT_PROJECT_NAME
|
|
24
|
-
|
|
25
24
|
return visOptions[id] ?? {}
|
|
26
25
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { basename, join, resolve } from 'pathe'
|
|
2
2
|
import { pick } from 'type-plus'
|
|
3
3
|
import type { ImageSnapshotKeyOptions } from '../client-api.ts'
|
|
4
|
-
import type { ImageSnapshotResult } from '
|
|
4
|
+
import type { ImageSnapshotResult } from '../shared/commands.types.ts'
|
|
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 {
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { shouldTakeSnapshot } from '../should_take_snapshot.ts'
|
|
8
|
-
import type { SnapshotMeta } from '../snapshot_meta.ts'
|
|
9
|
-
import { toTaskId } from '../task_id.ts'
|
|
1
|
+
import { afterEach, beforeAll, expect } from 'vitest'
|
|
2
|
+
import { autoSnapshotMatcher } from '../client/suite/auto_snapshot_matcher.ts'
|
|
3
|
+
import { setAutoSnapshotOptions } from '../client/task/auto_snapshot_options.ts'
|
|
4
|
+
import type { SnapshotMeta } from '../client/task/snapshot_meta.ts'
|
|
5
|
+
import type { SetupVisSuiteCommand } from '../shared/commands.types.ts'
|
|
6
|
+
import type { ComparisonMethod, SetupVisOptions } from '../shared/types.ts'
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Visual test configuration on the client side.
|
|
@@ -40,20 +37,7 @@ export type VisClientConfigurator<GM extends Record<string, any> | unknown = unk
|
|
|
40
37
|
* })
|
|
41
38
|
* ```
|
|
42
39
|
*/
|
|
43
|
-
setup(options?:
|
|
44
|
-
auto?:
|
|
45
|
-
| boolean
|
|
46
|
-
| (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
|
|
47
|
-
options: SnapshotMeta<C> & M & GM,
|
|
48
|
-
) => Promise<boolean> | Promise<void> | boolean | void)
|
|
49
|
-
| Record<
|
|
50
|
-
string,
|
|
51
|
-
| boolean
|
|
52
|
-
| (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
|
|
53
|
-
options: SnapshotMeta<C> & M & GM,
|
|
54
|
-
) => Promise<boolean> | Promise<void> | boolean | void)
|
|
55
|
-
>
|
|
56
|
-
}): void
|
|
40
|
+
setup(options?: SetupVisOptions<GM>): void
|
|
57
41
|
/**
|
|
58
42
|
* @deprecated Use `vis.setup()` instead.
|
|
59
43
|
*/
|
|
@@ -122,106 +106,67 @@ export type VisClientConfigurator<GM extends Record<string, any> | unknown = unk
|
|
|
122
106
|
}
|
|
123
107
|
|
|
124
108
|
export function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand) {
|
|
125
|
-
|
|
109
|
+
const matcher = autoSnapshotMatcher(commands, expect)
|
|
126
110
|
|
|
127
111
|
const vis: VisClientConfigurator<GM> = {
|
|
128
112
|
setup(options) {
|
|
129
113
|
if (!options || options.auto === false) {
|
|
130
|
-
beforeAll(
|
|
114
|
+
beforeAll(matcher.setup)
|
|
131
115
|
} else {
|
|
132
116
|
beforeAll(async () => {
|
|
133
|
-
await
|
|
117
|
+
await matcher.setup()
|
|
134
118
|
setAutoSnapshotOptions(true)
|
|
135
119
|
})
|
|
136
120
|
}
|
|
137
121
|
|
|
138
122
|
if (typeof options?.auto === 'function') {
|
|
139
123
|
afterEach(
|
|
140
|
-
|
|
124
|
+
matcher.createMatcher({
|
|
141
125
|
auto: options.auto,
|
|
142
126
|
}),
|
|
143
127
|
)
|
|
144
128
|
} else if (typeof options?.auto === 'object') {
|
|
145
|
-
afterEach(
|
|
129
|
+
afterEach(matcher.createMatcher(options.auto))
|
|
146
130
|
} else {
|
|
147
|
-
afterEach(
|
|
131
|
+
afterEach(matcher.createMatcher({ async auto() {} }))
|
|
148
132
|
}
|
|
149
133
|
},
|
|
150
134
|
presets: {
|
|
151
135
|
enable() {
|
|
152
|
-
beforeAll(
|
|
153
|
-
afterEach(
|
|
136
|
+
beforeAll(matcher.setup)
|
|
137
|
+
afterEach(matcher.createMatcher({ async auto() {} }))
|
|
154
138
|
},
|
|
155
139
|
manual() {
|
|
156
|
-
beforeAll(
|
|
140
|
+
beforeAll(matcher.setup)
|
|
157
141
|
},
|
|
158
142
|
auto() {
|
|
159
143
|
beforeAll(async () => {
|
|
160
|
-
await
|
|
144
|
+
await matcher.setup()
|
|
161
145
|
setAutoSnapshotOptions(true)
|
|
162
146
|
})
|
|
163
|
-
afterEach(
|
|
147
|
+
afterEach(matcher.createMatcher({ async auto() {} }))
|
|
164
148
|
},
|
|
165
149
|
theme(themes) {
|
|
166
150
|
beforeAll(async () => {
|
|
167
|
-
await
|
|
151
|
+
await matcher.setup()
|
|
168
152
|
setAutoSnapshotOptions(true)
|
|
169
153
|
})
|
|
170
|
-
afterEach(
|
|
154
|
+
afterEach(matcher.createMatcher(themes))
|
|
171
155
|
},
|
|
172
156
|
},
|
|
173
157
|
beforeAll: {
|
|
174
158
|
async setup() {
|
|
175
|
-
|
|
159
|
+
await matcher.setup()
|
|
176
160
|
},
|
|
177
161
|
},
|
|
178
162
|
afterEach: {
|
|
179
163
|
async matchImageSnapshot() {
|
|
180
|
-
return
|
|
164
|
+
return matcher.createMatcher({ async auto() {} })()
|
|
181
165
|
},
|
|
182
166
|
matchPerTheme(themes) {
|
|
183
|
-
return
|
|
184
|
-
const test = ctx.getCurrentTest()
|
|
185
|
-
if ((test?.result?.errors?.length ?? 0) > 0) return
|
|
186
|
-
|
|
187
|
-
const meta = extractAutoSnapshotOptions(test)
|
|
188
|
-
if (!shouldTakeSnapshot(meta)) return
|
|
189
|
-
const errors: Array<[string, Error]> = []
|
|
190
|
-
for (const themeId in themes) {
|
|
191
|
-
try {
|
|
192
|
-
await new Promise((a) => setTimeout(a, 10))
|
|
193
|
-
const theme = themes[themeId]
|
|
194
|
-
const r = typeof theme === 'function' ? await theme(meta! as any) : theme
|
|
195
|
-
if (r === false) continue
|
|
196
|
-
await test!.context.expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
|
|
197
|
-
...meta,
|
|
198
|
-
snapshotKey: meta?.snapshotKey ?? themeId,
|
|
199
|
-
})
|
|
200
|
-
} catch (error) {
|
|
201
|
-
errors.push([themeId, error as Error])
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (errors.length > 0) {
|
|
205
|
-
if (errors.length === 1) throw errors[0]![1]
|
|
206
|
-
const taskId = toTaskId(test!)
|
|
207
|
-
throw new AggregateError(
|
|
208
|
-
errors,
|
|
209
|
-
dedent`Snapshot \`${taskId}\` mismatched
|
|
210
|
-
|
|
211
|
-
${errors
|
|
212
|
-
.map(([themeId, error]) => {
|
|
213
|
-
return `Theme \`${themeId}\` failed: ${error.message}`
|
|
214
|
-
})
|
|
215
|
-
.join('\n\n')}`,
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
167
|
+
return matcher.createMatcher(themes)
|
|
219
168
|
},
|
|
220
169
|
},
|
|
221
170
|
}
|
|
222
171
|
return vis
|
|
223
172
|
}
|
|
224
|
-
|
|
225
|
-
function getSubject(selectors: string | undefined) {
|
|
226
|
-
return selectors ? (document.querySelector(selectors) ?? document.body) : document.body
|
|
227
|
-
}
|
package/src/setup.ts
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Pick } from 'type-plus'
|
|
2
|
+
import type { VisOptions } from '../config/types.ts'
|
|
3
|
+
import type { ImageSnapshotComparisonInfo, MatchImageSnapshotOptions } from './types.ts'
|
|
4
|
+
|
|
5
|
+
export interface PrepareImageSnapshotComparisonCommand {
|
|
6
|
+
prepareImageSnapshotComparison: (
|
|
7
|
+
taskId: string,
|
|
8
|
+
subject: string,
|
|
9
|
+
options?: MatchImageSnapshotOptions | undefined,
|
|
10
|
+
) => Promise<ImageSnapshotComparisonInfo | undefined>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PreparePageImageSnapshotComparisonCommand {
|
|
14
|
+
preparePageImageSnapshotComparison: (
|
|
15
|
+
taskId: string,
|
|
16
|
+
options?: MatchImageSnapshotOptions | undefined,
|
|
17
|
+
) => Promise<ImageSnapshotComparisonInfo | undefined>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SetupVisSuiteCommand {
|
|
21
|
+
/**
|
|
22
|
+
* Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
|
|
23
|
+
* When this command is run for the first time,
|
|
24
|
+
* it will remove the results and diffs directory of all suites.
|
|
25
|
+
*
|
|
26
|
+
* In subsequent runs, it will only remove the results and diffs directory of the current suite.
|
|
27
|
+
*/
|
|
28
|
+
setupVisSuite: () => Promise<
|
|
29
|
+
Pick<
|
|
30
|
+
VisOptions,
|
|
31
|
+
| 'comparisonMethod'
|
|
32
|
+
| 'diffOptions'
|
|
33
|
+
| 'failureThreshold'
|
|
34
|
+
| 'failureThresholdType'
|
|
35
|
+
| 'snapshotKey'
|
|
36
|
+
| 'subject'
|
|
37
|
+
| 'timeout'
|
|
38
|
+
>
|
|
39
|
+
>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface LoadImageSnapshotResultsCommand {
|
|
43
|
+
loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ImageSnapshotResult {
|
|
47
|
+
filename: string
|
|
48
|
+
/**
|
|
49
|
+
* The base64 encoded image of the baseline snapshot.
|
|
50
|
+
*/
|
|
51
|
+
baseline?: string | undefined
|
|
52
|
+
/**
|
|
53
|
+
* The base64 encoded image of the result snapshot.
|
|
54
|
+
*/
|
|
55
|
+
result?: string | undefined
|
|
56
|
+
/**
|
|
57
|
+
* The base64 encoded image of the diff snapshot.
|
|
58
|
+
*/
|
|
59
|
+
diff?: string | undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface HasImageSnapshotCommand {
|
|
63
|
+
hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ImageSnapshotNextIndexCommand {
|
|
67
|
+
/**
|
|
68
|
+
* Get the index of the snapshot image to be created.
|
|
69
|
+
*/
|
|
70
|
+
imageSnapshotNextIndex(taskId: string): Promise<number>
|
|
71
|
+
}
|