vitest-plugin-vis 4.1.0 → 4.2.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/auto_snapshots/_ctx.mjs +15 -0
- package/dist/auto_snapshots/_ctx.mjs.map +1 -0
- package/dist/auto_snapshots/_extract_auto_snapshot_options.mjs +23 -0
- package/dist/auto_snapshots/_extract_auto_snapshot_options.mjs.map +1 -0
- package/dist/{auto_snapshot_options-BMRtKmod.d.mts → auto_snapshots/auto_snapshot_options.d.mts} +5 -4
- package/dist/auto_snapshots/auto_snapshot_options.d.mts.map +1 -0
- package/dist/{auto_snapshot_options-DUOTpF2N.mjs → auto_snapshots/auto_snapshot_options.mjs} +6 -40
- package/dist/auto_snapshots/auto_snapshot_options.mjs.map +1 -0
- package/dist/auto_snapshots/snapshot_meta.d.mts +15 -0
- package/dist/auto_snapshots/snapshot_meta.d.mts.map +1 -0
- package/dist/client/actions/has_image_snapshot_action.d.mts +8 -0
- package/dist/client/actions/has_image_snapshot_action.d.mts.map +1 -0
- package/dist/client/actions/has_image_snapshot_action.mjs +9 -0
- package/dist/client/actions/has_image_snapshot_action.mjs.map +1 -0
- package/dist/client/actions/load_image_snapshot_results_action.d.mts +7 -0
- package/dist/client/actions/load_image_snapshot_results_action.d.mts.map +1 -0
- package/dist/client/actions/load_image_snapshot_results_action.mjs +8 -0
- package/dist/client/actions/load_image_snapshot_results_action.mjs.map +1 -0
- package/dist/client/actions/match_image_snapshot_action.d.mts +9 -0
- package/dist/client/actions/match_image_snapshot_action.d.mts.map +1 -0
- package/dist/client/actions/match_image_snapshot_action.mjs +20 -0
- package/dist/client/actions/match_image_snapshot_action.mjs.map +1 -0
- package/dist/client/actions/match_page_image_snapshot_action.d.mts +9 -0
- package/dist/client/actions/match_page_image_snapshot_action.d.mts.map +1 -0
- package/dist/client/actions/match_page_image_snapshot_action.mjs +14 -0
- package/dist/client/actions/match_page_image_snapshot_action.mjs.map +1 -0
- package/dist/client/expect/_ctx.mjs +15 -0
- package/dist/client/expect/_ctx.mjs.map +1 -0
- package/dist/client/expect/augment.d.mts +10 -0
- package/dist/client/expect/augment.d.mts.map +1 -0
- package/dist/client/expect/expectation_result.d.mts +7 -0
- package/dist/client/expect/expectation_result.d.mts.map +1 -0
- package/dist/client/expect/expectation_result.mjs +9 -0
- package/dist/client/expect/expectation_result.mjs.map +1 -0
- package/dist/client/expect/extend.d.mts +1 -0
- package/dist/client/expect/extend.mjs +9 -0
- package/dist/client/expect/extend.mjs.map +1 -0
- package/dist/client/expect/to_match_image_snapshot.mjs +16 -0
- package/dist/client/expect/to_match_image_snapshot.mjs.map +1 -0
- package/dist/{to_match_image_snapshot.types--tTmHoRA.d.mts → client/expect/to_match_image_snapshot.types.d.mts} +3 -3
- package/dist/client/expect/to_match_image_snapshot.types.d.mts.map +1 -0
- package/dist/client/external/browser/has_render_content.mjs +8 -0
- package/dist/client/external/browser/has_render_content.mjs.map +1 -0
- package/dist/client/external/browser/image_data.mjs +37 -0
- package/dist/client/external/browser/image_data.mjs.map +1 -0
- package/dist/client/external/browser/image_resizer.mjs +32 -0
- package/dist/client/external/browser/image_resizer.mjs.map +1 -0
- package/dist/client/external/browser/selector.mjs +57 -0
- package/dist/client/external/browser/selector.mjs.map +1 -0
- package/dist/client/external/vitest/vitest_browser_context_proxy.mjs +12 -0
- package/dist/client/external/vitest/vitest_browser_context_proxy.mjs.map +1 -0
- package/dist/client/external/vitest/vitest_suite_proxy.d.mts +3 -0
- package/dist/client/external/vitest/vitest_suite_proxy.mjs +11 -0
- package/dist/client/external/vitest/vitest_suite_proxy.mjs.map +1 -0
- package/dist/client/image/align_images.mjs +14 -0
- package/dist/client/image/align_images.mjs.map +1 -0
- package/dist/client/page/_ctx.d.mts +3 -0
- package/dist/client/page/_ctx.mjs +15 -0
- package/dist/client/page/_ctx.mjs.map +1 -0
- package/dist/client/page/augment.d.mts +9 -0
- package/dist/client/page/augment.d.mts.map +1 -0
- package/dist/client/page/extend.d.mts +1 -0
- package/dist/client/page/extend.mjs +13 -0
- package/dist/client/page/extend.mjs.map +1 -0
- package/dist/client/page/has_image_snapshot.d.mts +13 -0
- package/dist/client/page/has_image_snapshot.d.mts.map +1 -0
- package/dist/client/page/has_image_snapshot.mjs +15 -0
- package/dist/client/page/has_image_snapshot.mjs.map +1 -0
- package/dist/client/page/to_match_image_snapshot.d.mts +9 -0
- package/dist/client/page/to_match_image_snapshot.d.mts.map +1 -0
- package/dist/client/page/to_match_image_snapshot.mjs +15 -0
- package/dist/client/page/to_match_image_snapshot.mjs.map +1 -0
- package/dist/client/snapshot/compare_image_snapshot.logic.mjs +14 -0
- package/dist/client/snapshot/compare_image_snapshot.logic.mjs.map +1 -0
- package/dist/client/snapshot/compare_image_snapshot.mjs +63 -0
- package/dist/client/snapshot/compare_image_snapshot.mjs.map +1 -0
- package/dist/client/snapshot/should_take_snapshot.mjs +10 -0
- package/dist/client/snapshot/should_take_snapshot.mjs.map +1 -0
- package/dist/client/suite/_ctx.mjs +13 -0
- package/dist/client/suite/_ctx.mjs.map +1 -0
- package/dist/client/suite/auto_snapshot_matcher.d.mts +12 -0
- package/dist/client/suite/auto_snapshot_matcher.d.mts.map +1 -0
- package/dist/client/suite/auto_snapshot_matcher.mjs +50 -0
- package/dist/client/suite/auto_snapshot_matcher.mjs.map +1 -0
- package/dist/client/task/task_id.d.mts +9 -0
- package/dist/client/task/task_id.d.mts.map +1 -0
- package/dist/client/task/task_id.mjs +15 -0
- package/dist/client/task/task_id.mjs.map +1 -0
- package/dist/client-api.d.mts +13 -44
- package/dist/client-api.mjs +10 -13
- package/dist/{types-DJYCbyT8.d.mts → config/types.d.mts} +8 -9
- package/dist/config/types.d.mts.map +1 -0
- package/dist/config/vis.d.mts +27 -0
- package/dist/config/vis.d.mts.map +1 -0
- package/dist/config/vis.mjs +31 -0
- package/dist/config/vis.mjs.map +1 -0
- package/dist/config.d.mts +5 -28
- package/dist/config.mjs +3 -411
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +1 -4
- package/dist/presets/auto.mjs +4 -7
- package/dist/presets/auto.mjs.map +1 -1
- package/dist/presets/enable.mjs +2 -6
- package/dist/presets/enable.mjs.map +1 -1
- package/dist/presets/manual.mjs +2 -6
- package/dist/presets/manual.mjs.map +1 -1
- package/dist/server/browser_provider/browser_api.mjs +13 -0
- package/dist/server/browser_provider/browser_api.mjs.map +1 -0
- package/dist/server/browser_provider/playwright.mjs +24 -0
- package/dist/server/browser_provider/playwright.mjs.map +1 -0
- package/dist/server/browser_provider/webdriverio.mjs +16 -0
- package/dist/server/browser_provider/webdriverio.mjs.map +1 -0
- package/dist/server/commands/_assertions.mjs +10 -0
- package/dist/server/commands/_assertions.mjs.map +1 -0
- package/dist/server/commands/augment.d.mts +8 -0
- package/dist/server/commands/augment.d.mts.map +1 -0
- package/dist/server/commands/commands.mjs +20 -0
- package/dist/server/commands/commands.mjs.map +1 -0
- package/dist/server/commands/has_image_snapshot.mjs +12 -0
- package/dist/server/commands/has_image_snapshot.mjs.map +1 -0
- package/dist/server/commands/image_snapshot_next_index.mjs +12 -0
- package/dist/server/commands/image_snapshot_next_index.mjs.map +1 -0
- package/dist/server/commands/load_image_snapshot_results.mjs +12 -0
- package/dist/server/commands/load_image_snapshot_results.mjs.map +1 -0
- package/dist/server/commands/prepare_image_snapshot_comparison.mjs +37 -0
- package/dist/server/commands/prepare_image_snapshot_comparison.mjs.map +1 -0
- package/dist/server/commands/prepare_page_image_snapshot_comparison.mjs +27 -0
- package/dist/server/commands/prepare_page_image_snapshot_comparison.mjs.map +1 -0
- package/dist/server/commands/setup_vis_suite.mjs +12 -0
- package/dist/server/commands/setup_vis_suite.mjs.map +1 -0
- package/dist/server/externals/file.mjs +23 -0
- package/dist/server/externals/file.mjs.map +1 -0
- package/dist/server/project.mjs +13 -0
- package/dist/server/project.mjs.map +1 -0
- package/dist/server/snapshot.mjs +29 -0
- package/dist/server/snapshot.mjs.map +1 -0
- package/dist/server/snapshot_path.d.mts +17 -0
- package/dist/server/snapshot_path.d.mts.map +1 -0
- package/dist/{snapshot_path-7GliOSH_.mjs → server/snapshot_path.mjs} +7 -25
- package/dist/server/snapshot_path.mjs.map +1 -0
- package/dist/server/snapshot_writer.mjs +21 -0
- package/dist/server/snapshot_writer.mjs.map +1 -0
- package/dist/server/suite.mjs +82 -0
- package/dist/server/suite.mjs.map +1 -0
- package/dist/server/vis_options.mjs +19 -0
- package/dist/server/vis_options.mjs.map +1 -0
- package/dist/server/vis_server_context.deps.mjs +16 -0
- package/dist/server/vis_server_context.deps.mjs.map +1 -0
- package/dist/server/vis_server_context.logic.mjs +82 -0
- package/dist/server/vis_server_context.logic.mjs.map +1 -0
- package/dist/server/vis_server_context.mjs +8 -0
- package/dist/server/vis_server_context.mjs.map +1 -0
- package/dist/server/vis_server_context.types.d.mts +2 -0
- package/dist/server-utils.d.mts +4 -19
- package/dist/server-utils.mjs +3 -2
- package/dist/setup/create_vis.d.mts +108 -0
- package/dist/setup/create_vis.d.mts.map +1 -0
- package/dist/setup/create_vis.mjs +58 -0
- package/dist/setup/create_vis.mjs.map +1 -0
- package/dist/setup/vis.d.mts +10 -0
- package/dist/setup/vis.d.mts.map +1 -0
- package/dist/setup/vis.mjs +12 -0
- package/dist/setup/vis.mjs.map +1 -0
- package/dist/setup-api.d.mts +4 -0
- package/dist/setup-api.mjs +5 -0
- package/dist/setup.d.mts +8 -101
- package/dist/setup.d.mts.map +1 -1
- package/dist/setup.mjs +12 -7
- package/dist/setup.mjs.map +1 -0
- package/dist/{asserts--HSSlgPD.mjs → shared/asserts.mjs} +2 -2
- package/dist/shared/asserts.mjs.map +1 -0
- package/dist/{base64-CHSENEAO.mjs → shared/base64.mjs} +2 -2
- package/dist/shared/base64.mjs.map +1 -0
- package/dist/{commands.types-BVhcnnHw.d.mts → shared/commands.types.d.mts} +6 -6
- package/dist/shared/commands.types.d.mts.map +1 -0
- package/dist/shared/compare_image.mjs +46 -0
- package/dist/shared/compare_image.mjs.map +1 -0
- package/dist/shared/constants.d.mts +9 -0
- package/dist/shared/constants.d.mts.map +1 -0
- package/dist/{constants-CTBaz8Ml.mjs → shared/constants.mjs} +2 -2
- package/dist/shared/constants.mjs.map +1 -0
- package/dist/shared/convert_threshold_unit.mjs +12 -0
- package/dist/shared/convert_threshold_unit.mjs.map +1 -0
- package/dist/shared/get_max_size.mjs +11 -0
- package/dist/shared/get_max_size.mjs.map +1 -0
- package/dist/shared/is_same_size.mjs +8 -0
- package/dist/shared/is_same_size.mjs.map +1 -0
- package/dist/{trim_common_folder-DBThLerp.d.mts → shared/trim_common_folder.d.mts} +2 -2
- package/dist/shared/trim_common_folder.d.mts.map +1 -0
- package/dist/shared/trim_common_folder.mjs +23 -0
- package/dist/shared/trim_common_folder.mjs.map +1 -0
- package/dist/{types-CEmjj-A9.d.mts → shared/types.d.mts} +6 -21
- package/dist/shared/types.d.mts.map +1 -0
- package/dist/testing/constants.d.mts +12 -0
- package/dist/testing/constants.d.mts.map +1 -0
- package/dist/testing/constants.mjs +65550 -0
- package/dist/{testing.mjs.map → testing/constants.mjs.map} +1 -1
- package/dist/testing.d.mts +2 -12
- package/dist/testing.mjs +2 -65549
- package/package.json +24 -17
- package/readme.md +48 -3
- package/src/{client/task → auto_snapshots}/_ctx.ts +1 -1
- package/src/auto_snapshots/_extract_auto_snapshot_options.ts +26 -0
- package/src/{client/task → auto_snapshots}/auto_snapshot_options.mdx +1 -2
- package/src/{client/task → auto_snapshots}/auto_snapshot_options.ts +3 -25
- package/src/{client/task → auto_snapshots}/snapshot_meta.ts +1 -1
- package/src/client/actions/match_image_snapshot_action.ts +0 -2
- package/src/client/snapshot/compare_image_snapshot.logic.ts +1 -1
- package/src/client/snapshot/compare_image_snapshot.ts +15 -1
- package/src/client/snapshot/should_take_snapshot.ts +1 -1
- package/src/client/suite/auto_snapshot_matcher.ts +2 -3
- package/src/client-api.ts +1 -1
- package/src/config/overview.mdx +145 -0
- package/src/{shared → config}/trim_common_folder.mdx +1 -1
- package/src/config/types.ts +5 -6
- package/src/config/vis.mdx +313 -0
- package/src/index.ts +1 -1
- package/src/overview.mdx +66 -28
- package/src/server/commands/prepare_image_snapshot_comparison.ts +8 -8
- package/src/server/commands/prepare_page_image_snapshot_comparison.ts +1 -6
- package/src/server/snapshot_path.ts +3 -1
- package/src/{setup.create_vis.mdx → setup/create_vis.mdx} +4 -5
- package/src/setup/create_vis.ts +12 -7
- package/src/setup/overview.mdx +17 -0
- package/src/setup/readme.md +3 -1
- package/src/{setup.vis.mdx → setup/vis.mdx} +15 -18
- package/src/setup-api.ts +5 -0
- package/src/setup.ts +8 -4
- package/src/shared/commands.types.ts +2 -2
- package/src/shared/types.ts +3 -2
- package/dist/asserts--HSSlgPD.mjs.map +0 -1
- package/dist/augment-C1tjdh5B.d.mts +0 -33
- package/dist/augment-C1tjdh5B.d.mts.map +0 -1
- package/dist/auto_snapshot_matcher-C0y6mAeS.mjs +0 -381
- package/dist/auto_snapshot_matcher-C0y6mAeS.mjs.map +0 -1
- package/dist/auto_snapshot_options-BMRtKmod.d.mts.map +0 -1
- package/dist/auto_snapshot_options-DUOTpF2N.mjs.map +0 -1
- package/dist/base64-CHSENEAO.mjs.map +0 -1
- package/dist/client-api.d.mts.map +0 -1
- package/dist/client-api.mjs.map +0 -1
- package/dist/commands.types-BVhcnnHw.d.mts.map +0 -1
- package/dist/config.d.mts.map +0 -1
- package/dist/config.mjs.map +0 -1
- package/dist/constants-CTBaz8Ml.mjs.map +0 -1
- package/dist/server-utils.d.mts.map +0 -1
- package/dist/setup-DCytWz48.mjs +0 -124
- package/dist/setup-DCytWz48.mjs.map +0 -1
- package/dist/snapshot_path-7GliOSH_.mjs.map +0 -1
- package/dist/src-CSQnlFa9.mjs +0 -1
- package/dist/testing.d.mts.map +0 -1
- package/dist/to_match_image_snapshot.types--tTmHoRA.d.mts.map +0 -1
- package/dist/trim_common_folder-DBThLerp.d.mts.map +0 -1
- package/dist/types-CEmjj-A9.d.mts.map +0 -1
- package/dist/types-DJYCbyT8.d.mts.map +0 -1
- package/src/config.vis.mdx +0 -76
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { NAME } from "../shared/constants.mjs";
|
|
2
|
+
import { setVisOption } from "../server/vis_options.mjs";
|
|
3
|
+
import { commands } from "../server/commands/commands.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/config/vis.ts
|
|
6
|
+
/**
|
|
7
|
+
* Create a Vite plugin for visual testing.
|
|
8
|
+
*
|
|
9
|
+
* If options are not provided, the plugin will use the default options,
|
|
10
|
+
* which enables the `auto` preset.
|
|
11
|
+
*/
|
|
12
|
+
function vis(options = { preset: "auto" }) {
|
|
13
|
+
return {
|
|
14
|
+
name: NAME,
|
|
15
|
+
config(userConfig) {
|
|
16
|
+
setVisOption(userConfig, options);
|
|
17
|
+
const preset = options?.preset;
|
|
18
|
+
return { test: {
|
|
19
|
+
browser: {
|
|
20
|
+
name: void 0,
|
|
21
|
+
commands
|
|
22
|
+
},
|
|
23
|
+
setupFiles: preset && preset !== "none" && preset !== "custom" ? [`vitest-plugin-vis/presets/${preset}`] : []
|
|
24
|
+
} };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { vis };
|
|
31
|
+
//# sourceMappingURL=vis.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vis.mjs","names":[],"sources":["../../src/config/vis.ts"],"sourcesContent":["import type { Plugin } from 'vitest/config'\nimport { commands } from '../server/commands/commands.ts'\nimport { setVisOption } from '../server/vis_options.ts'\nimport { NAME } from '../shared/constants.ts'\nimport type { ComparisonMethod } from '../shared/types.ts'\nimport type { VisOptions } from './types.ts'\n\n/**\n * Create a Vite plugin for visual testing.\n *\n * If options are not provided, the plugin will use the default options,\n * which enables the `auto` preset.\n */\nexport function vis<M extends ComparisonMethod = 'pixel'>(options: VisOptions<M> = { preset: 'auto' } as any) {\n\treturn {\n\t\tname: NAME,\n\t\tconfig(this: unknown, userConfig) {\n\t\t\tsetVisOption(userConfig, options)\n\t\t\tconst preset = options?.preset\n\t\t\treturn {\n\t\t\t\ttest: {\n\t\t\t\t\tbrowser: {\n\t\t\t\t\t\tname: undefined,\n\t\t\t\t\t\tcommands: commands as any,\n\t\t\t\t\t},\n\t\t\t\t\tsetupFiles: preset && preset !== 'none' && preset !== 'custom' ? [`vitest-plugin-vis/presets/${preset}`] : [],\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t} satisfies Plugin\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,IAA0C,UAAyB,EAAE,QAAQ,QAAQ,EAAS;AAC7G,QAAO;EACN,MAAM;EACN,OAAsB,YAAY;AACjC,gBAAa,YAAY,QAAQ;GACjC,MAAM,SAAS,SAAS;AACxB,UAAO,EACN,MAAM;IACL,SAAS;KACR,MAAM;KACI;KACV;IACD,YAAY,UAAU,WAAW,UAAU,WAAW,WAAW,CAAC,6BAA6B,SAAS,GAAG,EAAE;IAC7G,EACD;;EAEF"}
|
package/dist/config.d.mts
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
//#region src/config/vis.d.ts
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Create a Vite plugin for visual testing.
|
|
10
|
-
*
|
|
11
|
-
* If options are not provided, the plugin will use the default options,
|
|
12
|
-
* which enables the `auto` preset.
|
|
13
|
-
*/
|
|
14
|
-
declare function vis<M extends ComparisonMethod = 'pixel'>(options?: VisOptions<M>): {
|
|
15
|
-
name: string;
|
|
16
|
-
config(this: unknown, userConfig: vite0.UserConfig): {
|
|
17
|
-
test: {
|
|
18
|
-
browser: {
|
|
19
|
-
name: undefined;
|
|
20
|
-
commands: any;
|
|
21
|
-
};
|
|
22
|
-
setupFiles: string[];
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
//#endregion
|
|
27
|
-
export { ComparisonMethod, PixelComparisonOptions, PixelDiffOptions, SsimComparisonOptions, SsimDiffOptions, VisOptions, trimCommonFolder, vis };
|
|
28
|
-
//# sourceMappingURL=config.d.mts.map
|
|
1
|
+
import { ComparisonMethod, PixelComparisonOptions, PixelDiffOptions, SsimComparisonOptions, SsimDiffOptions } from "./shared/types.mjs";
|
|
2
|
+
import { VisOptions } from "./config/types.mjs";
|
|
3
|
+
import { vis } from "./config/vis.mjs";
|
|
4
|
+
import { trimCommonFolder } from "./shared/trim_common_folder.mjs";
|
|
5
|
+
export { ComparisonMethod, PixelComparisonOptions, PixelDiffOptions, SsimComparisonOptions, SsimDiffOptions, VisOptions, trimCommonFolder, vis };
|
package/dist/config.mjs
CHANGED
|
@@ -1,412 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { i as trimCommonFolder, n as getSnapshotSubpath, r as resolveSnapshotRootDir } from "./snapshot_path-7GliOSH_.mjs";
|
|
4
|
-
import { t as isBase64String } from "./base64-CHSENEAO.mjs";
|
|
5
|
-
import { basename, dirname, join, relative, resolve } from "pathe";
|
|
6
|
-
import { pick } from "type-plus";
|
|
7
|
-
import { glob } from "glob";
|
|
8
|
-
import { mkdirp } from "mkdirp";
|
|
9
|
-
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
10
|
-
import ci from "is-ci";
|
|
11
|
-
import { rimraf } from "rimraf";
|
|
1
|
+
import { trimCommonFolder } from "./shared/trim_common_folder.mjs";
|
|
2
|
+
import { vis } from "./config/vis.mjs";
|
|
12
3
|
|
|
13
|
-
|
|
14
|
-
const file = {
|
|
15
|
-
existFile(filePath) {
|
|
16
|
-
return stat(filePath).then((s) => s.isFile()).catch(() => false);
|
|
17
|
-
},
|
|
18
|
-
glob(pattern, options) {
|
|
19
|
-
return glob(pattern, options);
|
|
20
|
-
},
|
|
21
|
-
mkdirp,
|
|
22
|
-
async tryReadFile(filePath) {
|
|
23
|
-
if (!filePath) return void 0;
|
|
24
|
-
return readFile(filePath).catch(() => void 0);
|
|
25
|
-
},
|
|
26
|
-
writeFile
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/server/project.ts
|
|
31
|
-
function getProjectName(context) {
|
|
32
|
-
const { runner } = context.project;
|
|
33
|
-
const name = runner.config.name;
|
|
34
|
-
if (typeof name === "string") return name;
|
|
35
|
-
}
|
|
36
|
-
function getProjectRoot(context) {
|
|
37
|
-
return context.project.config.root;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/server/vis_options.ts
|
|
42
|
-
const DEFAULT_PROJECT_NAME = "__default";
|
|
43
|
-
const visOptions = {};
|
|
44
|
-
function setVisOption(userConfig, options) {
|
|
45
|
-
assertSnapshotKeyWithoutDash(options?.snapshotKey);
|
|
46
|
-
const name = userConfig.test?.name;
|
|
47
|
-
const id = typeof name === "string" ? name : typeof name === "object" ? name?.label : DEFAULT_PROJECT_NAME;
|
|
48
|
-
visOptions[id] = options;
|
|
49
|
-
}
|
|
50
|
-
function getVisOption(context) {
|
|
51
|
-
return visOptions[getProjectName(context) ?? DEFAULT_PROJECT_NAME] ?? {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/server/vis_server_context.deps.ts
|
|
56
|
-
/* v8 ignore start */
|
|
57
|
-
const deps = {
|
|
58
|
-
rimraf,
|
|
59
|
-
getSnapshotPlatform() {
|
|
60
|
-
return ci ? process.platform : "local";
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
/* v8 ignore end */
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/server/suite.ts
|
|
67
|
-
const suites = {};
|
|
68
|
-
/**
|
|
69
|
-
* Setup suite is called on each test file's beforeAll hook.
|
|
70
|
-
* Test files include vitest test files and storybook story files.
|
|
71
|
-
* It needs to make sure there is no race condition between the test files.
|
|
72
|
-
*/
|
|
73
|
-
async function setupSuite(browserContext) {
|
|
74
|
-
const suiteId = getSuiteId(browserContext);
|
|
75
|
-
const visOptions$1 = getVisOption(browserContext);
|
|
76
|
-
if (!suites[suiteId]) suites[suiteId] = createSuite(browserContext, visOptions$1);
|
|
77
|
-
const suite = await suites[suiteId];
|
|
78
|
-
const { taskSubpath, baselineDir, diffDir, resultDir, tasks } = createModule(suite, browserContext.testPath, visOptions$1);
|
|
79
|
-
suite.modules[taskSubpath] = {
|
|
80
|
-
baselineDir,
|
|
81
|
-
diffDir,
|
|
82
|
-
resultDir,
|
|
83
|
-
tasks
|
|
84
|
-
};
|
|
85
|
-
await Promise.allSettled([deps.rimraf(diffDir), deps.rimraf(resultDir)]);
|
|
86
|
-
return {
|
|
87
|
-
comparisonMethod: visOptions$1.comparisonMethod,
|
|
88
|
-
diffOptions: visOptions$1.diffOptions,
|
|
89
|
-
failureThreshold: visOptions$1.failureThreshold,
|
|
90
|
-
failureThresholdType: visOptions$1.failureThresholdType,
|
|
91
|
-
snapshotKey: visOptions$1.snapshotKey,
|
|
92
|
-
subject: visOptions$1.subject,
|
|
93
|
-
timeout: visOptions$1.timeout
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Suite ID also contains the project name to make it unique
|
|
98
|
-
* across different projects.
|
|
99
|
-
*/
|
|
100
|
-
function getSuiteId(context) {
|
|
101
|
-
return `${getProjectName(context)}/${context.project.config.name}`;
|
|
102
|
-
}
|
|
103
|
-
async function createSuite(browserContext, visOptions$1) {
|
|
104
|
-
const snapshotRootDir = resolveSnapshotRootDir(browserContext, visOptions$1);
|
|
105
|
-
const projectRoot = getProjectRoot(browserContext);
|
|
106
|
-
const state = {
|
|
107
|
-
projectRoot,
|
|
108
|
-
testTimeout: browserContext.project.config.testTimeout,
|
|
109
|
-
hookTimeout: browserContext.project.config.hookTimeout,
|
|
110
|
-
snapshotRootDir,
|
|
111
|
-
snapshotBaselineDir: join(snapshotRootDir, BASELINE_DIR),
|
|
112
|
-
snapshotResultDir: join(snapshotRootDir, RESULT_DIR),
|
|
113
|
-
snapshotDiffDir: join(snapshotRootDir, DIFF_DIR),
|
|
114
|
-
snapshotRootPath: join(projectRoot, snapshotRootDir),
|
|
115
|
-
subject: visOptions$1.subject,
|
|
116
|
-
modules: {}
|
|
117
|
-
};
|
|
118
|
-
await Promise.allSettled([deps.rimraf(join(state.snapshotDiffDir)), deps.rimraf(join(state.snapshotResultDir))]);
|
|
119
|
-
return state;
|
|
120
|
-
}
|
|
121
|
-
function createModule(state, testPath, options) {
|
|
122
|
-
const taskSubpath = getTaskSubpath(state, testPath, options);
|
|
123
|
-
return {
|
|
124
|
-
taskSubpath,
|
|
125
|
-
baselineDir: join(state.snapshotBaselineDir, taskSubpath),
|
|
126
|
-
resultDir: join(state.snapshotResultDir, taskSubpath),
|
|
127
|
-
diffDir: join(state.snapshotDiffDir, taskSubpath),
|
|
128
|
-
tasks: {}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function getTaskSubpath(state, testPath, options) {
|
|
132
|
-
return getSnapshotSubpath(relative(state.projectRoot, testPath), options);
|
|
133
|
-
}
|
|
134
|
-
function getSuite(context) {
|
|
135
|
-
return suites[getSuiteId(context)];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/server/vis_server_context.logic.ts
|
|
140
|
-
function createVisServerContext() {
|
|
141
|
-
const context = {
|
|
142
|
-
async getSnapshotResults(browserContext, taskId) {
|
|
143
|
-
const suiteInfo = await context.getSuiteInfo(browserContext, taskId);
|
|
144
|
-
const baselines = await file.glob(join(suiteInfo.projectRoot, suiteInfo.baselineDir, `${suiteInfo.taskId}-*.png`));
|
|
145
|
-
const results = await file.glob(join(suiteInfo.projectRoot, suiteInfo.resultDir, `${suiteInfo.taskId}-*.png`));
|
|
146
|
-
const diffs = await file.glob(join(suiteInfo.projectRoot, suiteInfo.diffDir, `${suiteInfo.taskId}-*.png`));
|
|
147
|
-
const r = [];
|
|
148
|
-
await Promise.all(baselines.map(async (baselinePath) => {
|
|
149
|
-
const filename = basename(baselinePath);
|
|
150
|
-
const resultPath = results.find((r$1) => r$1.endsWith(filename));
|
|
151
|
-
const diffPath = diffs.find((d) => d.endsWith(filename));
|
|
152
|
-
const baselineBuffer = await file.tryReadFile(baselinePath);
|
|
153
|
-
const resultBuffer = await file.tryReadFile(resultPath);
|
|
154
|
-
const diffBuffer = await file.tryReadFile(diffPath);
|
|
155
|
-
r.push({
|
|
156
|
-
filename,
|
|
157
|
-
baseline: baselineBuffer?.toString("base64"),
|
|
158
|
-
result: resultBuffer?.toString("base64"),
|
|
159
|
-
diff: diffBuffer?.toString("base64")
|
|
160
|
-
});
|
|
161
|
-
}));
|
|
162
|
-
return r;
|
|
163
|
-
},
|
|
164
|
-
async getSnapshotInfo(browserContext, taskId, options) {
|
|
165
|
-
const suiteInfo = await context.getSuiteInfo(browserContext, taskId);
|
|
166
|
-
const snapshotFilename = context.getSnapshotFilename(browserContext, suiteInfo, options?.snapshotKey);
|
|
167
|
-
const { baselineDir, resultDir, diffDir, task } = suiteInfo;
|
|
168
|
-
task.count = task.count + 1;
|
|
169
|
-
const baselinePath = join(baselineDir, snapshotFilename);
|
|
170
|
-
const resultPath = join(resultDir, snapshotFilename);
|
|
171
|
-
const diffPath = join(diffDir, snapshotFilename);
|
|
172
|
-
return {
|
|
173
|
-
...pick(getVisOption(browserContext), "comparisonMethod", "diffOptions", "failureThreshold", "failureThresholdType", "timeout"),
|
|
174
|
-
baselinePath,
|
|
175
|
-
resultPath,
|
|
176
|
-
diffPath
|
|
177
|
-
};
|
|
178
|
-
},
|
|
179
|
-
async getTaskCount(browserContext, taskId) {
|
|
180
|
-
return (await context.getSuiteInfo(browserContext, taskId)).task.count;
|
|
181
|
-
},
|
|
182
|
-
async hasImageSnapshot(browserContext, taskId, snapshotKey) {
|
|
183
|
-
const info = await context.getSuiteInfo(browserContext, taskId);
|
|
184
|
-
return file.existFile(resolve(info.projectRoot, info.baselineDir, context.getSnapshotFilename(browserContext, info, snapshotKey)));
|
|
185
|
-
},
|
|
186
|
-
getSnapshotFilename(browserContext, info, snapshotKey) {
|
|
187
|
-
if (snapshotKey) return `${info.taskId}-${snapshotKey}.png`;
|
|
188
|
-
const visOptions$1 = getVisOption(browserContext);
|
|
189
|
-
if (typeof visOptions$1.snapshotKey === "string") return `${info.taskId}-${visOptions$1.snapshotKey}.png`;
|
|
190
|
-
return `${info.taskId}-${info.task.count}.png`;
|
|
191
|
-
},
|
|
192
|
-
async getSuiteInfo(browserContext, taskId) {
|
|
193
|
-
const projectState = await getSuite(browserContext);
|
|
194
|
-
const visOptions$1 = getVisOption(browserContext);
|
|
195
|
-
const moduleId = getTaskSubpath(projectState, browserContext.testPath, visOptions$1);
|
|
196
|
-
const m = projectState.modules[moduleId];
|
|
197
|
-
const task = m.tasks[taskId] = m.tasks[taskId] ?? { count: 1 };
|
|
198
|
-
return {
|
|
199
|
-
projectRoot: projectState.projectRoot,
|
|
200
|
-
suiteId: moduleId,
|
|
201
|
-
taskId,
|
|
202
|
-
baselineDir: m.baselineDir,
|
|
203
|
-
resultDir: m.resultDir,
|
|
204
|
-
diffDir: m.diffDir,
|
|
205
|
-
task
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
return context;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region src/server/vis_server_context.ts
|
|
214
|
-
const visServerContext = createVisServerContext();
|
|
215
|
-
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/server/commands/_assertions.ts
|
|
218
|
-
function assertTestPathDefined(context, commandName) {
|
|
219
|
-
if (!context.testPath) throw new Error(`'commands.${commandName}' requires testPath to be defined`);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/server/commands/has_image_snapshot.ts
|
|
224
|
-
const hasImageSnapshot = async (context, taskId, snapshotKey) => {
|
|
225
|
-
assertTestPathDefined(context, "hasImageSnapshot");
|
|
226
|
-
return visServerContext.hasImageSnapshot(context, taskId, snapshotKey);
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/server/commands/image_snapshot_next_index.ts
|
|
231
|
-
const imageSnapshotNextIndex = async (context, taskId) => {
|
|
232
|
-
assertTestPathDefined(context, "imageSnapshotNextIndex");
|
|
233
|
-
return visServerContext.getTaskCount(context, taskId);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
//#endregion
|
|
237
|
-
//#region src/server/commands/load_image_snapshot_results.ts
|
|
238
|
-
const loadImageSnapshotResults = async (context, taskId) => {
|
|
239
|
-
assertTestPathDefined(context, "loadImageSnapshotResults");
|
|
240
|
-
return visServerContext.getSnapshotResults(context, taskId);
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/server/browser_provider/playwright.ts
|
|
245
|
-
function playwright(context) {
|
|
246
|
-
const { page, iframe } = context;
|
|
247
|
-
return {
|
|
248
|
-
async takeScreenshot(projectRoot, relativeFilePath, selector, options) {
|
|
249
|
-
return iframe.locator(selector).screenshot({
|
|
250
|
-
path: resolve(projectRoot, relativeFilePath),
|
|
251
|
-
...options
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
async takePageScreenshot(projectRoot, relativeFilePath, options) {
|
|
255
|
-
return page.screenshot({
|
|
256
|
-
path: resolve(projectRoot, relativeFilePath),
|
|
257
|
-
...options
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
//#endregion
|
|
264
|
-
//#region src/server/browser_provider/webdriverio.ts
|
|
265
|
-
function webdriverio(context) {
|
|
266
|
-
const { browser } = context;
|
|
267
|
-
return {
|
|
268
|
-
async takeScreenshot(_projectRoot, relativeFilePath, selector) {
|
|
269
|
-
return (await browser.$(`${selector}`)).saveScreenshot(relativeFilePath);
|
|
270
|
-
},
|
|
271
|
-
async takePageScreenshot(_projectRoot, relativeFilePath, options) {
|
|
272
|
-
return browser.saveScreenshot(relativeFilePath, options);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region src/server/browser_provider/browser_api.ts
|
|
279
|
-
function browserApi(context) {
|
|
280
|
-
if (context.provider.name === "playwright") return playwright(context);
|
|
281
|
-
if (context.provider.name === "webdriverio") return webdriverio(context);
|
|
282
|
-
throw new Error(`Unsupported provider: ${context.provider.name}`);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
//#endregion
|
|
286
|
-
//#region src/server/snapshot_writer.ts
|
|
287
|
-
function createSnapshotWriter({ mkdirp: mkdirp$1, writeFile: writeFile$1 } = file) {
|
|
288
|
-
return {
|
|
289
|
-
async writeBase64(filePath, data) {
|
|
290
|
-
await mkdirp$1(dirname(filePath));
|
|
291
|
-
await writeFile$1(filePath, data, { encoding: "base64" });
|
|
292
|
-
},
|
|
293
|
-
async writeBuffer(filePath, data) {
|
|
294
|
-
await mkdirp$1(dirname(filePath));
|
|
295
|
-
await writeFile$1(filePath, data);
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
const snapshotWriter = createSnapshotWriter();
|
|
300
|
-
|
|
301
|
-
//#endregion
|
|
302
|
-
//#region src/server/snapshot.ts
|
|
303
|
-
async function takeSnapshot(context, projectRoot, relativeFilePath, subject, options) {
|
|
304
|
-
if (isBase64String(subject)) {
|
|
305
|
-
await snapshotWriter.writeBase64(resolve(projectRoot, relativeFilePath), subject);
|
|
306
|
-
return Buffer.from(subject, "base64");
|
|
307
|
-
}
|
|
308
|
-
return takeSnapshotByBrowser(context, projectRoot, relativeFilePath, subject, options);
|
|
309
|
-
}
|
|
310
|
-
async function takeSnapshotByBrowser(context, projectRoot, relativeFilePath, subject, options) {
|
|
311
|
-
await mkdirp(dirname(resolve(projectRoot, relativeFilePath)));
|
|
312
|
-
return browserApi(context).takeScreenshot(projectRoot, relativeFilePath, subject ?? "body", { timeout: options?.timeout });
|
|
313
|
-
}
|
|
314
|
-
async function takePageSnapshot(context, projectRoot, relativeFilePath, options) {
|
|
315
|
-
await mkdirp(dirname(resolve(projectRoot, relativeFilePath)));
|
|
316
|
-
return browserApi(context).takePageScreenshot(projectRoot, relativeFilePath, {
|
|
317
|
-
timeout: options?.timeout,
|
|
318
|
-
fullPage: options?.fullPage
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/server/commands/prepare_image_snapshot_comparison.ts
|
|
324
|
-
const prepareImageSnapshotComparison = async (context, taskId, subject, options) => {
|
|
325
|
-
assertTestPathDefined(context, "prepareImageSnapshotComparison");
|
|
326
|
-
if (!options) options = {};
|
|
327
|
-
options.timeout = options.timeout ?? 3e4;
|
|
328
|
-
const projectRoot = getProjectRoot(context);
|
|
329
|
-
const info = await visServerContext.getSnapshotInfo(context, taskId, options);
|
|
330
|
-
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath));
|
|
331
|
-
if (!baselineBuffer) {
|
|
332
|
-
if (isBase64String(subject)) await snapshotWriter.writeBase64(resolve(projectRoot, info.baselinePath), subject);
|
|
333
|
-
else await takeSnapshotByBrowser(context, projectRoot, info.baselinePath, subject, options);
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const resultBuffer = await takeSnapshot(context, projectRoot, info.resultPath, subject, options);
|
|
337
|
-
return {
|
|
338
|
-
...info,
|
|
339
|
-
projectRoot,
|
|
340
|
-
baseline: baselineBuffer.toString("base64"),
|
|
341
|
-
result: resultBuffer.toString("base64")
|
|
342
|
-
};
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
//#endregion
|
|
346
|
-
//#region src/server/commands/prepare_page_image_snapshot_comparison.ts
|
|
347
|
-
const preparePageImageSnapshotComparison = async (context, taskId, options) => {
|
|
348
|
-
assertTestPathDefined(context, "preparePageImageSnapshotComparison");
|
|
349
|
-
if (!options) options = {};
|
|
350
|
-
options.timeout = options.timeout ?? 3e4;
|
|
351
|
-
const projectRoot = getProjectRoot(context);
|
|
352
|
-
const info = await visServerContext.getSnapshotInfo(context, taskId, options);
|
|
353
|
-
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath));
|
|
354
|
-
if (!baselineBuffer) {
|
|
355
|
-
await takePageSnapshot(context, projectRoot, info.baselinePath, options);
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
const resultBuffer = await takePageSnapshot(context, projectRoot, info.resultPath, options);
|
|
359
|
-
return {
|
|
360
|
-
...info,
|
|
361
|
-
projectRoot,
|
|
362
|
-
baseline: baselineBuffer.toString("base64"),
|
|
363
|
-
result: resultBuffer.toString("base64")
|
|
364
|
-
};
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
//#endregion
|
|
368
|
-
//#region src/server/commands/setup_vis_suite.ts
|
|
369
|
-
const setupVisSuite = async (context) => {
|
|
370
|
-
assertTestPathDefined(context, "setupVisSuite");
|
|
371
|
-
return setupSuite(context);
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
//#endregion
|
|
375
|
-
//#region src/server/commands/commands.ts
|
|
376
|
-
const commands = {
|
|
377
|
-
setupVisSuite,
|
|
378
|
-
imageSnapshotNextIndex,
|
|
379
|
-
hasImageSnapshot,
|
|
380
|
-
preparePageImageSnapshotComparison,
|
|
381
|
-
prepareImageSnapshotComparison,
|
|
382
|
-
loadImageSnapshotResults
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
//#endregion
|
|
386
|
-
//#region src/config/vis.ts
|
|
387
|
-
/**
|
|
388
|
-
* Create a Vite plugin for visual testing.
|
|
389
|
-
*
|
|
390
|
-
* If options are not provided, the plugin will use the default options,
|
|
391
|
-
* which enables the `auto` preset.
|
|
392
|
-
*/
|
|
393
|
-
function vis(options = { preset: "auto" }) {
|
|
394
|
-
return {
|
|
395
|
-
name: NAME,
|
|
396
|
-
config(userConfig) {
|
|
397
|
-
setVisOption(userConfig, options);
|
|
398
|
-
const preset = options?.preset;
|
|
399
|
-
return { test: {
|
|
400
|
-
browser: {
|
|
401
|
-
name: void 0,
|
|
402
|
-
commands
|
|
403
|
-
},
|
|
404
|
-
setupFiles: preset && preset !== "none" && preset !== "custom" ? [`vitest-plugin-vis/presets/${preset}`] : []
|
|
405
|
-
} };
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
//#endregion
|
|
411
|
-
export { trimCommonFolder, vis };
|
|
412
|
-
//# sourceMappingURL=config.mjs.map
|
|
4
|
+
export { trimCommonFolder, vis };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
3
|
-
import
|
|
4
|
-
import "./augment
|
|
5
|
-
export { Awaitable, ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotComparisonInfo, ImageSnapshotKeyOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, MatchImageSnapshotOptions,
|
|
1
|
+
import { Awaitable, ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotComparisonInfo, ImageSnapshotKeyOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, MatchImageSnapshotOptions, PageImageSnapshotOptions, PixelComparisonOptions, PixelDiffOptions, SetupVisOptions, SnapshotTestMeta, SsimComparisonOptions, SsimDiffOptions, ToMatchImageSnapshotOptions, ToMatchPageImageSnapshotOptions } from "./shared/types.mjs";
|
|
2
|
+
import { MetaTask, setAutoSnapshotOptions } from "./auto_snapshots/auto_snapshot_options.mjs";
|
|
3
|
+
import "./client/expect/augment.mjs";
|
|
4
|
+
import "./client/page/augment.mjs";
|
|
5
|
+
export { Awaitable, ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotComparisonInfo, ImageSnapshotKeyOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, MatchImageSnapshotOptions, MetaTask, PageImageSnapshotOptions, PixelComparisonOptions, PixelDiffOptions, SetupVisOptions, SnapshotTestMeta, SsimComparisonOptions, SsimDiffOptions, ToMatchImageSnapshotOptions, ToMatchPageImageSnapshotOptions, setAutoSnapshotOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./constants-CTBaz8Ml.mjs";
|
|
3
|
-
import { n as setAutoSnapshotOptions } from "./auto_snapshot_options-DUOTpF2N.mjs";
|
|
4
|
-
import "./src-CSQnlFa9.mjs";
|
|
1
|
+
import { setAutoSnapshotOptions } from "./auto_snapshots/auto_snapshot_options.mjs";
|
|
5
2
|
|
|
6
3
|
export { setAutoSnapshotOptions };
|
package/dist/presets/auto.mjs
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../
|
|
3
|
-
import {
|
|
4
|
-
import "../
|
|
5
|
-
import "../base64-CHSENEAO.mjs";
|
|
6
|
-
import "../auto_snapshot_matcher-C0y6mAeS.mjs";
|
|
7
|
-
import { t as vis } from "../setup-DCytWz48.mjs";
|
|
1
|
+
import { setAutoSnapshotOptions } from "../auto_snapshots/auto_snapshot_options.mjs";
|
|
2
|
+
import "../index.mjs";
|
|
3
|
+
import { vis } from "../setup/vis.mjs";
|
|
4
|
+
import "../setup.mjs";
|
|
8
5
|
import { afterEach, beforeAll } from "vitest";
|
|
9
6
|
|
|
10
7
|
//#region src/presets/auto.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto.mjs","names":[],"sources":["../../src/presets/auto.ts"],"sourcesContent":["import { afterEach, beforeAll } from 'vitest'\nimport { setAutoSnapshotOptions } from '../index.ts'\nimport { vis } from '../setup.ts'\n\nbeforeAll(async () => {\n\tawait vis.beforeAll.setup()\n\tsetAutoSnapshotOptions(true)\n})\nafterEach(() => vis.afterEach.matchImageSnapshot())\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto.mjs","names":[],"sources":["../../src/presets/auto.ts"],"sourcesContent":["import { afterEach, beforeAll } from 'vitest'\nimport { setAutoSnapshotOptions } from '../index.ts'\nimport { vis } from '../setup.ts'\n\nbeforeAll(async () => {\n\tawait vis.beforeAll.setup()\n\tsetAutoSnapshotOptions(true)\n})\nafterEach(() => vis.afterEach.matchImageSnapshot())\n"],"mappings":";;;;;;;AAIA,UAAU,YAAY;AACrB,OAAM,IAAI,UAAU,OAAO;AAC3B,wBAAuB,KAAK;EAC3B;AACF,gBAAgB,IAAI,UAAU,oBAAoB,CAAC"}
|
package/dist/presets/enable.mjs
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../
|
|
3
|
-
import "../auto_snapshot_options-DUOTpF2N.mjs";
|
|
4
|
-
import "../base64-CHSENEAO.mjs";
|
|
5
|
-
import "../auto_snapshot_matcher-C0y6mAeS.mjs";
|
|
6
|
-
import { t as vis } from "../setup-DCytWz48.mjs";
|
|
1
|
+
import { vis } from "../setup/vis.mjs";
|
|
2
|
+
import "../setup.mjs";
|
|
7
3
|
import { afterEach, beforeAll } from "vitest";
|
|
8
4
|
|
|
9
5
|
//#region src/presets/enable.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enable.mjs","names":[],"sources":["../../src/presets/enable.ts"],"sourcesContent":["import { afterEach, beforeAll } from 'vitest'\nimport { vis } from '../setup.ts'\n\nbeforeAll(() => vis.beforeAll.setup())\nafterEach(() => vis.afterEach.matchImageSnapshot())\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"enable.mjs","names":[],"sources":["../../src/presets/enable.ts"],"sourcesContent":["import { afterEach, beforeAll } from 'vitest'\nimport { vis } from '../setup.ts'\n\nbeforeAll(() => vis.beforeAll.setup())\nafterEach(() => vis.afterEach.matchImageSnapshot())\n"],"mappings":";;;;;AAGA,gBAAgB,IAAI,UAAU,OAAO,CAAC;AACtC,gBAAgB,IAAI,UAAU,oBAAoB,CAAC"}
|
package/dist/presets/manual.mjs
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import "../
|
|
3
|
-
import "../auto_snapshot_options-DUOTpF2N.mjs";
|
|
4
|
-
import "../base64-CHSENEAO.mjs";
|
|
5
|
-
import "../auto_snapshot_matcher-C0y6mAeS.mjs";
|
|
6
|
-
import { t as vis } from "../setup-DCytWz48.mjs";
|
|
1
|
+
import { vis } from "../setup/vis.mjs";
|
|
2
|
+
import "../setup.mjs";
|
|
7
3
|
import { afterEach, beforeAll } from "vitest";
|
|
8
4
|
|
|
9
5
|
//#region src/presets/manual.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manual.mjs","names":[],"sources":["../../src/presets/manual.ts"],"sourcesContent":["import { afterEach, beforeAll } from 'vitest'\nimport { vis } from '../setup.ts'\n\nbeforeAll(() => vis.beforeAll.setup())\nafterEach(() => vis.afterEach.matchImageSnapshot())\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"manual.mjs","names":[],"sources":["../../src/presets/manual.ts"],"sourcesContent":["import { afterEach, beforeAll } from 'vitest'\nimport { vis } from '../setup.ts'\n\nbeforeAll(() => vis.beforeAll.setup())\nafterEach(() => vis.afterEach.matchImageSnapshot())\n"],"mappings":";;;;;AAGA,gBAAgB,IAAI,UAAU,OAAO,CAAC;AACtC,gBAAgB,IAAI,UAAU,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { playwright } from "./playwright.mjs";
|
|
2
|
+
import { webdriverio } from "./webdriverio.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/server/browser_provider/browser_api.ts
|
|
5
|
+
function browserApi(context) {
|
|
6
|
+
if (context.provider.name === "playwright") return playwright(context);
|
|
7
|
+
if (context.provider.name === "webdriverio") return webdriverio(context);
|
|
8
|
+
throw new Error(`Unsupported provider: ${context.provider.name}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { browserApi };
|
|
13
|
+
//# sourceMappingURL=browser_api.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser_api.mjs","names":[],"sources":["../../../src/server/browser_provider/browser_api.ts"],"sourcesContent":["import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'\nimport { playwright } from './playwright.ts'\nimport { webdriverio } from './webdriverio.ts'\n\nexport function browserApi(context: ExtendedBrowserCommandContext) {\n\tif (context.provider.name === 'playwright') {\n\t\treturn playwright(context)\n\t}\n\tif (context.provider.name === 'webdriverio') {\n\t\treturn webdriverio(context)\n\t}\n\tthrow new Error(`Unsupported provider: ${context.provider.name}`)\n}\n"],"mappings":";;;;AAIA,SAAgB,WAAW,SAAwC;AAClE,KAAI,QAAQ,SAAS,SAAS,aAC7B,QAAO,WAAW,QAAQ;AAE3B,KAAI,QAAQ,SAAS,SAAS,cAC7B,QAAO,YAAY,QAAQ;AAE5B,OAAM,IAAI,MAAM,yBAAyB,QAAQ,SAAS,OAAO"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolve } from "pathe";
|
|
2
|
+
|
|
3
|
+
//#region src/server/browser_provider/playwright.ts
|
|
4
|
+
function playwright(context) {
|
|
5
|
+
const { page, iframe } = context;
|
|
6
|
+
return {
|
|
7
|
+
async takeScreenshot(projectRoot, relativeFilePath, selector, options) {
|
|
8
|
+
return iframe.locator(selector).screenshot({
|
|
9
|
+
path: resolve(projectRoot, relativeFilePath),
|
|
10
|
+
...options
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
async takePageScreenshot(projectRoot, relativeFilePath, options) {
|
|
14
|
+
return page.screenshot({
|
|
15
|
+
path: resolve(projectRoot, relativeFilePath),
|
|
16
|
+
...options
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { playwright };
|
|
24
|
+
//# sourceMappingURL=playwright.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.mjs","names":[],"sources":["../../../src/server/browser_provider/playwright.ts"],"sourcesContent":["import { resolve } from 'pathe'\nimport type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'\nimport type { BrowserApi } from './types.ts'\n\nexport function playwright(context: ExtendedBrowserCommandContext): BrowserApi {\n\tconst { page, iframe } = context\n\n\treturn {\n\t\tasync takeScreenshot(projectRoot, relativeFilePath, selector, options) {\n\t\t\tconst subject = iframe.locator(selector)\n\t\t\treturn subject.screenshot({\n\t\t\t\tpath: resolve(projectRoot, relativeFilePath),\n\t\t\t\t...options,\n\t\t\t})\n\t\t},\n\t\tasync takePageScreenshot(projectRoot, relativeFilePath, options) {\n\t\t\treturn page.screenshot({\n\t\t\t\tpath: resolve(projectRoot, relativeFilePath),\n\t\t\t\t...options,\n\t\t\t})\n\t\t},\n\t}\n}\n"],"mappings":";;;AAIA,SAAgB,WAAW,SAAoD;CAC9E,MAAM,EAAE,MAAM,WAAW;AAEzB,QAAO;EACN,MAAM,eAAe,aAAa,kBAAkB,UAAU,SAAS;AAEtE,UADgB,OAAO,QAAQ,SAAS,CACzB,WAAW;IACzB,MAAM,QAAQ,aAAa,iBAAiB;IAC5C,GAAG;IACH,CAAC;;EAEH,MAAM,mBAAmB,aAAa,kBAAkB,SAAS;AAChE,UAAO,KAAK,WAAW;IACtB,MAAM,QAAQ,aAAa,iBAAiB;IAC5C,GAAG;IACH,CAAC;;EAEH"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/server/browser_provider/webdriverio.ts
|
|
2
|
+
function webdriverio(context) {
|
|
3
|
+
const { browser } = context;
|
|
4
|
+
return {
|
|
5
|
+
async takeScreenshot(_projectRoot, relativeFilePath, selector) {
|
|
6
|
+
return (await browser.$(`${selector}`)).saveScreenshot(relativeFilePath);
|
|
7
|
+
},
|
|
8
|
+
async takePageScreenshot(_projectRoot, relativeFilePath, options) {
|
|
9
|
+
return browser.saveScreenshot(relativeFilePath, options);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { webdriverio };
|
|
16
|
+
//# sourceMappingURL=webdriverio.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webdriverio.mjs","names":[],"sources":["../../../src/server/browser_provider/webdriverio.ts"],"sourcesContent":["import type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'\nimport type { BrowserApi } from './types.ts'\n\nexport function webdriverio(context: ExtendedBrowserCommandContext): BrowserApi {\n\tconst { browser } = context\n\treturn {\n\t\tasync takeScreenshot(_projectRoot, relativeFilePath, selector) {\n\t\t\tconst element = await browser.$(`${selector}`)\n\t\t\treturn element.saveScreenshot(relativeFilePath)\n\t\t},\n\t\tasync takePageScreenshot(_projectRoot, relativeFilePath, options) {\n\t\t\treturn browser.saveScreenshot(relativeFilePath, options)\n\t\t},\n\t}\n}\n"],"mappings":";AAGA,SAAgB,YAAY,SAAoD;CAC/E,MAAM,EAAE,YAAY;AACpB,QAAO;EACN,MAAM,eAAe,cAAc,kBAAkB,UAAU;AAE9D,WADgB,MAAM,QAAQ,EAAE,GAAG,WAAW,EAC/B,eAAe,iBAAiB;;EAEhD,MAAM,mBAAmB,cAAc,kBAAkB,SAAS;AACjE,UAAO,QAAQ,eAAe,kBAAkB,QAAQ;;EAEzD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "pathe";
|
|
2
|
+
|
|
3
|
+
//#region src/server/commands/_assertions.ts
|
|
4
|
+
function assertTestPathDefined(context, commandName) {
|
|
5
|
+
if (!context.testPath) throw new Error(`'commands.${commandName}' requires testPath to be defined`);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { assertTestPathDefined };
|
|
10
|
+
//# sourceMappingURL=_assertions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_assertions.mjs","names":[],"sources":["../../../src/server/commands/_assertions.ts"],"sourcesContent":["import { isAbsolute } from 'pathe'\nimport type { RequiredPick } from 'type-plus'\nimport type { ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'\n\nexport function assertTestPathDefined(\n\tcontext: ExtendedBrowserCommandContext,\n\tcommandName: string,\n): asserts context is RequiredPick<ExtendedBrowserCommandContext, 'testPath'> {\n\tif (!context.testPath) {\n\t\tthrow new Error(`'commands.${commandName}' requires testPath to be defined`)\n\t}\n}\n\nexport function assertIsRelativePath(relativeFilePath: string, propName: string) {\n\tif (isAbsolute(relativeFilePath)) {\n\t\tthrow new Error(`'${propName}' must be a relative path`)\n\t}\n}\n"],"mappings":";;;AAIA,SAAgB,sBACf,SACA,aAC6E;AAC7E,KAAI,CAAC,QAAQ,SACZ,OAAM,IAAI,MAAM,aAAa,YAAY,mCAAmC"}
|