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.
- package/dist/asserts--HSSlgPD.mjs +8 -0
- package/dist/asserts--HSSlgPD.mjs.map +1 -0
- package/dist/augment-BJmy1S7i.d.mts +31 -0
- package/dist/augment-BJmy1S7i.d.mts.map +1 -0
- package/dist/auto_snapshot_options-CAD43Zkp.mjs +90 -0
- package/dist/auto_snapshot_options-CAD43Zkp.mjs.map +1 -0
- package/dist/auto_snapshot_options-CaQCXDdi.d.mts +45 -0
- package/dist/auto_snapshot_options-CaQCXDdi.d.mts.map +1 -0
- package/dist/base64-CHSENEAO.mjs +8 -0
- package/dist/base64-CHSENEAO.mjs.map +1 -0
- package/dist/client-api.d.mts +141 -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/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-BWgIDtv-.mjs +141 -0
- package/dist/setup-BWgIDtv-.mjs.map +1 -0
- package/dist/setup.d.mts +110 -0
- package/dist/setup.d.mts.map +1 -0
- package/dist/setup.mjs +8 -0
- package/dist/setup_vis_suite-C6JGGT7B.d.mts +17 -0
- package/dist/setup_vis_suite-C6JGGT7B.d.mts.map +1 -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/task_id-DnS9_4Ub.mjs +316 -0
- package/dist/task_id-DnS9_4Ub.mjs.map +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-p-zilA_M.d.mts +9 -0
- package/dist/to_match_image_snapshot.types-p-zilA_M.d.mts.map +1 -0
- package/dist/trim_common_folder-ModiubEJ.d.mts +9 -0
- package/dist/trim_common_folder-ModiubEJ.d.mts.map +1 -0
- package/dist/types-DFb23VE1.d.mts +110 -0
- package/dist/types-DFb23VE1.d.mts.map +1 -0
- package/dist/types-Do1N7g4c.d.mts +63 -0
- package/dist/types-Do1N7g4c.d.mts.map +1 -0
- package/dist/vis_server_context.types-Ce1f9vOO.d.mts +1 -0
- package/package.json +55 -39
- package/readme.md +58 -6
- package/src/client/actions/match_image_snapshot_action.ts +1 -1
- package/src/client/actions/match_page_image_snapshot_action.ts +1 -1
- package/src/client/auto_snapshot_options.ts +16 -1
- package/src/client/compare_image_snapshot.ts +1 -1
- package/src/client/expect/to_match_image_snapshot.ts +1 -1
- 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 +1 -1
- package/src/client/page/to_match_image_snapshot.mdx +1 -1
- package/src/client/page/to_match_image_snapshot.ts +1 -1
- package/src/client/setup/create_vis.ts +16 -14
- package/src/client/setup/vis.ctx.ts +4 -3
- package/src/client/setup/vis.ts +1 -1
- package/src/client/snapshot_meta.ts +5 -0
- package/src/client/vitest_browser_context_proxy.ts +3 -3
- package/src/config/vis.ts +4 -4
- 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 +1 -1
- package/src/server/commands/has_image_snapshot.ts +2 -2
- package/src/server/commands/image_snapshot_next_index.ts +2 -2
- package/src/server/commands/load_image_snapshot_results.ts +2 -3
- package/src/server/commands/prepare_image_snapshot_comparison.ts +2 -2
- package/src/server/commands/prepare_page_image_snapshot_comparison.ts +2 -2
- package/src/server/commands/setup_vis_suite.ts +3 -3
- 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 +7 -7
- package/src/server/vis_server_context.types.ts +31 -26
- package/src/shared/types.ts +2 -0
- 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/testing/stubBrowserCommandContext.ts +0 -16
- package/src/testing/stubUserConfig.ts +0 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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<
|
|
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)
|
package/src/client/setup/vis.ts
CHANGED
|
@@ -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('
|
|
4
|
+
let ctx: Awaited<typeof import('vitest/browser')>
|
|
5
5
|
|
|
6
6
|
if ((globalThis as any).__vitest_browser__) {
|
|
7
|
-
import('
|
|
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 {
|
|
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
|
}
|
|
@@ -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
|
}
|
|
@@ -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 '
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
}
|
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
|
}
|
|
@@ -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 {
|
|
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
|
}
|
package/src/shared/types.ts
CHANGED
|
@@ -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.
|