vitest-plugin-vis 2.4.3 → 3.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/esm/client/actions/has_image_snapshot_action.d.ts +4 -0
- package/esm/client/actions/has_image_snapshot_action.d.ts.map +1 -0
- package/esm/client/actions/has_image_snapshot_action.js +6 -0
- package/esm/client/actions/load_image_snapshot_results_action.d.ts +3 -0
- package/esm/client/actions/load_image_snapshot_results_action.d.ts.map +1 -0
- package/esm/client/actions/load_image_snapshot_results_action.js +3 -0
- package/esm/client/actions/match_image_snapshot_action.d.ts +6 -0
- package/esm/client/actions/match_image_snapshot_action.d.ts.map +1 -0
- package/esm/client/actions/match_image_snapshot_action.js +20 -0
- package/esm/client/actions/match_page_image_snapshot_action.d.ts +6 -0
- package/esm/client/actions/match_page_image_snapshot_action.d.ts.map +1 -0
- package/esm/client/actions/match_page_image_snapshot_action.js +9 -0
- package/esm/client/auto_snapshot_options.d.ts +29 -0
- package/esm/client/auto_snapshot_options.d.ts.map +1 -0
- package/esm/client/auto_snapshot_options.js +49 -0
- package/esm/client/compare_image_snapshot.d.ts +6 -0
- package/esm/client/compare_image_snapshot.d.ts.map +1 -0
- package/esm/client/compare_image_snapshot.js +52 -0
- package/esm/client/{image_snapshot_matcher.logic.d.ts → compare_image_snapshot.logic.d.ts} +1 -1
- package/esm/client/compare_image_snapshot.logic.d.ts.map +1 -0
- package/esm/client/expect/to_match_image_snapshot.d.ts.map +1 -1
- package/esm/client/expect/to_match_image_snapshot.js +4 -3
- package/esm/client/image_resizer.d.ts.map +1 -1
- package/esm/client/image_snapshot_options.d.ts +2 -0
- package/esm/client/image_snapshot_options.d.ts.map +1 -0
- package/esm/client/image_snapshot_options.js +6 -0
- package/esm/client/page/augment.d.ts +2 -1
- package/esm/client/page/augment.d.ts.map +1 -1
- package/esm/client/page/extend.js +2 -1
- package/esm/client/page/has_image_snapshot.d.ts +6 -6
- package/esm/client/page/has_image_snapshot.d.ts.map +1 -1
- package/esm/client/page/has_image_snapshot.js +2 -11
- package/esm/client/page/to_match_image_snapshot.d.ts +8 -0
- package/esm/client/page/to_match_image_snapshot.d.ts.map +1 -0
- package/esm/client/page/to_match_image_snapshot.js +15 -0
- package/esm/client/setup/create_vis.d.ts +96 -0
- package/esm/client/setup/create_vis.d.ts.map +1 -0
- package/esm/{setup → client/setup}/create_vis.js +43 -31
- package/esm/client/setup/vis.ctx.d.ts +12 -0
- package/esm/client/setup/vis.ctx.d.ts.map +1 -0
- package/esm/client/setup/vis.ctx.js +32 -0
- package/esm/client/setup/vis.d.ts +5 -0
- package/esm/client/setup/vis.d.ts.map +1 -0
- package/esm/client/should_take_snapshot.d.ts +2 -9
- package/esm/client/should_take_snapshot.d.ts.map +1 -1
- package/esm/client/should_take_snapshot.js +1 -11
- package/esm/client/snapshot_meta.d.ts +6 -0
- package/esm/client/snapshot_meta.d.ts.map +1 -0
- package/esm/client/task_id.d.ts +0 -3
- package/esm/client/task_id.d.ts.map +1 -1
- package/esm/client/task_id.js +0 -3
- package/esm/client/vitest_suite_proxy.d.ts +2 -9
- package/esm/client/vitest_suite_proxy.d.ts.map +1 -1
- package/esm/client-api.d.ts +11 -0
- package/esm/client-api.d.ts.map +1 -0
- package/esm/client-api.js +8 -0
- package/esm/commands.d.ts +0 -1
- package/esm/commands.d.ts.map +1 -1
- package/esm/commands.js +0 -1
- package/esm/config/types.d.ts +22 -22
- package/esm/config/types.d.ts.map +1 -1
- package/esm/config/vis.d.ts +4 -3
- package/esm/config/vis.d.ts.map +1 -1
- package/esm/config/vis.js +3 -4
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/presets/auto.d.ts +1 -2
- package/esm/presets/auto.d.ts.map +1 -1
- package/esm/presets/auto.js +8 -4
- package/esm/presets/enable.d.ts +1 -2
- package/esm/presets/enable.d.ts.map +1 -1
- package/esm/presets/enable.js +4 -4
- package/esm/presets/manual.d.ts +1 -2
- package/esm/presets/manual.d.ts.map +1 -1
- package/esm/presets/manual.js +3 -4
- package/esm/server/browser_provider/playwright.d.ts.map +1 -1
- package/esm/server/browser_provider/playwright.js +9 -3
- package/esm/server/browser_provider/types.d.ts +5 -1
- package/esm/server/browser_provider/types.d.ts.map +1 -1
- package/esm/server/browser_provider/webdriverio.d.ts.map +1 -1
- package/esm/server/browser_provider/webdriverio.js +7 -4
- package/esm/server/commands/augment.d.ts +11 -0
- package/esm/server/commands/augment.d.ts.map +1 -0
- package/esm/server/commands/augment.js +1 -0
- package/esm/server/commands/commands.d.ts +9 -0
- package/esm/server/commands/commands.d.ts.map +1 -0
- package/esm/server/commands/commands.js +14 -0
- package/esm/server/commands/has_image_snapshot.d.ts +2 -6
- package/esm/server/commands/has_image_snapshot.d.ts.map +1 -1
- package/esm/server/commands/has_image_snapshot.js +3 -3
- package/esm/server/commands/image_snapshot_next_index.d.ts +1 -1
- package/esm/server/commands/image_snapshot_next_index.d.ts.map +1 -1
- package/esm/server/commands/image_snapshot_next_index.js +2 -2
- package/esm/server/commands/load_image_snapshot_results.d.ts +21 -0
- package/esm/server/commands/load_image_snapshot_results.d.ts.map +1 -0
- package/esm/server/commands/load_image_snapshot_results.js +6 -0
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +8 -10
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.js +11 -9
- package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts +35 -0
- package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts.map +1 -0
- package/esm/server/commands/prepare_page_image_snapshot_comparison.js +27 -0
- package/esm/server/commands/setup_vis_suite.d.ts +3 -3
- package/esm/server/commands/setup_vis_suite.d.ts.map +1 -1
- package/esm/server/commands/setup_vis_suite.js +2 -3
- package/esm/server/commands/types.d.ts +3 -0
- package/esm/server/commands/types.d.ts.map +1 -0
- package/esm/server/commands/types.js +1 -0
- package/esm/server/externals/file.d.ts +10 -0
- package/esm/server/externals/file.d.ts.map +1 -0
- package/esm/server/{file.js → externals/file.js} +12 -4
- package/esm/server/{commands/browser_command_context.d.ts → project.d.ts} +8 -3
- package/esm/server/project.d.ts.map +1 -0
- package/esm/server/{commands/browser_command_context.js → project.js} +2 -2
- package/esm/server/snapshot.d.ts +4 -5
- package/esm/server/snapshot.d.ts.map +1 -1
- package/esm/server/snapshot.js +15 -13
- package/esm/server/snapshot_path.d.ts +3 -3
- package/esm/server/snapshot_path.d.ts.map +1 -1
- package/esm/server/snapshot_path.js +12 -11
- package/esm/server/snapshot_writer.d.ts +13 -0
- package/esm/server/snapshot_writer.d.ts.map +1 -0
- package/esm/server/snapshot_writer.js +15 -0
- package/esm/server/suite.d.ts +53 -0
- package/esm/server/suite.d.ts.map +1 -0
- package/esm/server/suite.js +73 -0
- package/esm/server/vis_options.d.ts +18 -0
- package/esm/server/vis_options.d.ts.map +1 -0
- package/esm/server/vis_options.js +14 -0
- package/esm/server/vis_server_context.d.ts +50 -0
- package/esm/server/vis_server_context.d.ts.map +1 -0
- package/esm/server/{vis_context.ctx.d.ts → vis_server_context.deps.d.ts} +2 -2
- package/esm/server/vis_server_context.deps.d.ts.map +1 -0
- package/esm/server/{vis_context.ctx.js → vis_server_context.deps.js} +1 -1
- package/esm/server/vis_server_context.js +2 -0
- package/esm/server/{vis_context.logic.d.ts → vis_server_context.logic.d.ts} +12 -32
- package/esm/server/vis_server_context.logic.d.ts.map +1 -0
- package/esm/server/vis_server_context.logic.js +79 -0
- package/esm/server/{vis_context.types.d.ts → vis_server_context.types.d.ts} +6 -6
- package/esm/server/vis_server_context.types.d.ts.map +1 -0
- package/esm/server/vis_server_context.types.js +1 -0
- package/esm/server-utils.d.ts +3 -0
- package/esm/server-utils.d.ts.map +1 -0
- package/esm/server-utils.js +2 -0
- package/esm/setup.d.ts +2 -2
- package/esm/setup.d.ts.map +1 -1
- package/esm/setup.js +2 -2
- package/esm/shared/asserts.d.ts +2 -0
- package/esm/shared/asserts.d.ts.map +1 -0
- package/esm/shared/asserts.js +5 -0
- package/esm/shared/types.d.ts +22 -21
- package/esm/shared/types.d.ts.map +1 -1
- package/esm/testing/stubBrowserCommandContext.d.ts +1 -1
- package/esm/testing/stubBrowserCommandContext.d.ts.map +1 -1
- package/esm/testing/stubBrowserCommandContext.js +3 -13
- package/esm/testing/stubSuite.d.ts +10 -0
- package/esm/testing/stubSuite.d.ts.map +1 -0
- package/esm/testing/stubSuite.js +27 -0
- package/esm/testing/stubUserConfig.d.ts +7 -0
- package/esm/testing/stubUserConfig.d.ts.map +1 -0
- package/esm/testing/stubUserConfig.js +4 -0
- package/package.json +29 -28
- package/readme.md +409 -110
- package/src/client/actions/has_image_snapshot_action.ts +14 -0
- package/src/client/actions/load_image_snapshot_results_action.ts +5 -0
- package/src/client/actions/match_image_snapshot_action.ts +32 -0
- package/src/client/actions/match_page_image_snapshot_action.ts +20 -0
- package/src/client/auto_snapshot_options.ts +71 -0
- package/src/client/compare_image_snapshot.ts +84 -0
- package/src/client/expect/to_match_image_snapshot.ts +4 -3
- package/src/client/image_snapshot_options.ts +6 -0
- package/src/client/page/augment.ts +2 -1
- package/src/client/page/extend.ts +2 -1
- package/src/client/page/has_image_snapshot.ts +8 -21
- package/src/client/page/to_match_image_snapshot.ts +27 -0
- package/src/client/setup/create_vis.ts +227 -0
- package/src/client/setup/vis.ctx.ts +33 -0
- package/src/client/should_take_snapshot.ts +3 -13
- package/src/client/snapshot_meta.ts +7 -0
- package/src/client/task_id.ts +0 -3
- package/src/client/vitest_suite_proxy.ts +2 -5
- package/src/client-api.ts +11 -0
- package/src/commands.ts +0 -1
- package/src/config/types.ts +32 -27
- package/src/config/vis.ts +3 -5
- package/src/index.ts +1 -1
- package/src/presets/auto.ts +8 -4
- package/src/presets/enable.ts +4 -4
- package/src/presets/manual.ts +3 -4
- package/src/server/browser_provider/playwright.ts +9 -3
- package/src/server/browser_provider/types.ts +12 -1
- package/src/server/browser_provider/webdriverio.ts +7 -4
- package/src/server/commands/augment.ts +16 -0
- package/src/server/commands/commands.ts +15 -0
- package/src/server/commands/has_image_snapshot.ts +8 -6
- package/src/server/commands/image_snapshot_next_index.ts +5 -3
- package/src/server/commands/load_image_snapshot_results.ts +32 -0
- package/src/server/commands/prepare_image_snapshot_comparison.ts +20 -14
- package/src/server/commands/prepare_page_image_snapshot_comparison.ts +75 -0
- package/src/server/commands/setup_vis_suite.ts +17 -7
- package/src/server/commands/types.ts +9 -0
- package/src/server/externals/file.ts +21 -0
- package/src/server/{commands/browser_command_context.ts → project.ts} +2 -4
- package/src/server/snapshot.ts +23 -14
- package/src/server/snapshot_path.ts +15 -13
- package/src/server/snapshot_writer.ts +22 -0
- package/src/server/suite.ts +96 -0
- package/src/server/vis_options.ts +27 -0
- package/src/server/{vis_context.ctx.ts → vis_server_context.deps.ts} +1 -1
- package/src/server/vis_server_context.logic.ts +112 -0
- package/src/server/vis_server_context.ts +3 -0
- package/src/server/{vis_context.types.ts → vis_server_context.types.ts} +5 -5
- package/src/server-utils.ts +2 -0
- package/src/setup.ts +2 -2
- package/src/shared/asserts.ts +5 -0
- package/src/shared/types.ts +25 -23
- package/src/testing/stubBrowserCommandContext.ts +4 -14
- package/src/testing/stubSuite.ts +38 -0
- package/src/testing/stubUserConfig.ts +6 -0
- package/esm/client/image_snapshot_matcher.d.ts +0 -11
- package/esm/client/image_snapshot_matcher.d.ts.map +0 -1
- package/esm/client/image_snapshot_matcher.js +0 -80
- package/esm/client/image_snapshot_matcher.logic.d.ts.map +0 -1
- package/esm/client/snapshot_options.d.ts +0 -33
- package/esm/client/snapshot_options.d.ts.map +0 -1
- package/esm/client/snapshot_options.js +0 -37
- package/esm/client.d.ts +0 -8
- package/esm/client.d.ts.map +0 -1
- package/esm/client.js +0 -5
- package/esm/server/commands/browser_command_context.d.ts.map +0 -1
- package/esm/server/commands/extend.d.ts +0 -17
- package/esm/server/commands/extend.d.ts.map +0 -1
- package/esm/server/commands/extend.js +0 -12
- package/esm/server/commands/match_image_snapshot.d.ts +0 -18
- package/esm/server/commands/match_image_snapshot.d.ts.map +0 -1
- package/esm/server/commands/match_image_snapshot.js +0 -81
- package/esm/server/file.d.ts +0 -7
- package/esm/server/file.d.ts.map +0 -1
- package/esm/server/vis_context.ctx.d.ts.map +0 -1
- package/esm/server/vis_context.d.ts +0 -56
- package/esm/server/vis_context.d.ts.map +0 -1
- package/esm/server/vis_context.js +0 -2
- package/esm/server/vis_context.logic.d.ts.map +0 -1
- package/esm/server/vis_context.logic.js +0 -135
- package/esm/server/vis_context.types.d.ts.map +0 -1
- package/esm/setup/create_vis.d.ts +0 -53
- package/esm/setup/create_vis.d.ts.map +0 -1
- package/esm/setup/vis.d.ts +0 -5
- package/esm/setup/vis.d.ts.map +0 -1
- package/src/client/image_snapshot_matcher.ts +0 -121
- package/src/client/snapshot_options.ts +0 -82
- package/src/client.ts +0 -7
- package/src/server/commands/extend.ts +0 -25
- package/src/server/commands/match_image_snapshot.ts +0 -128
- package/src/server/file.ts +0 -13
- package/src/server/vis_context.logic.ts +0 -198
- package/src/server/vis_context.ts +0 -3
- package/src/setup/create_vis.ts +0 -154
- /package/esm/client/{image_snapshot_matcher.logic.js → compare_image_snapshot.logic.js} +0 -0
- /package/esm/{setup → client/setup}/vis.js +0 -0
- /package/esm/{server/vis_context.types.js → client/snapshot_meta.js} +0 -0
- /package/src/client/{image_snapshot_matcher.logic.ts → compare_image_snapshot.logic.ts} +0 -0
- /package/src/{setup → client/setup}/vis.ts +0 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HasImageSnapshotCommand, ImageSnapshotNextIndexCommand } from '../../commands.ts';
|
|
2
|
+
import type { ImageSnapshotKeyOptions } from '../../shared/types.ts';
|
|
3
|
+
export declare function hasImageSnapshotAction(commands: ImageSnapshotNextIndexCommand & HasImageSnapshotCommand, taskId: string, options?: ImageSnapshotKeyOptions | undefined): Promise<boolean>;
|
|
4
|
+
//# sourceMappingURL=has_image_snapshot_action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has_image_snapshot_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/has_image_snapshot_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,wBAAgB,sBAAsB,CACrC,QAAQ,EAAE,6BAA6B,GAAG,uBAAuB,EACjE,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,uBAAuB,GAAG,SAAS,oBAO7C"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LoadImageSnapshotResultsCommand } from '../../server/commands/load_image_snapshot_results.ts';
|
|
2
|
+
export declare function loadImageSnapshotResultsAction(commands: LoadImageSnapshotResultsCommand, taskId: string): Promise<import("../../server/commands/load_image_snapshot_results.ts").ImageSnapshotResult[]>;
|
|
3
|
+
//# sourceMappingURL=load_image_snapshot_results_action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load_image_snapshot_results_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/load_image_snapshot_results_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,sDAAsD,CAAA;AAE3G,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,+BAA+B,EAAE,MAAM,EAAE,MAAM,iGAEvG"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BrowserCommands } from '@vitest/browser/context';
|
|
2
|
+
import type { ImageSnapshotNextIndexCommand } from '../../commands.ts';
|
|
3
|
+
import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts';
|
|
4
|
+
import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts';
|
|
5
|
+
export declare function matchImageSnapshotAction(commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand, taskId: string, subject: any, options?: ToMatchImageSnapshotOptions<any>): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=match_image_snapshot_action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match_image_snapshot_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/match_image_snapshot_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,4DAA4D,CAAA;AAGvH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAIxE,wBAAsB,wBAAwB,CAC7C,QAAQ,EAAE,eAAe,GAAG,qCAAqC,GAAG,6BAA6B,EACjG,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,2BAA2B,CAAC,GAAG,CAAC,iBAS1C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assertSnapshotKeyWithoutDash } from "../../shared/asserts.js";
|
|
2
|
+
import { isBase64String } from "../../shared/base64.js";
|
|
3
|
+
import { compareImageSnapshot } from "../compare_image_snapshot.js";
|
|
4
|
+
import { convertElementToCssSelector } from "../selector.js";
|
|
5
|
+
export async function matchImageSnapshotAction(commands, taskId, subject, options) {
|
|
6
|
+
assertSnapshotKeyWithoutDash(options?.snapshotKey);
|
|
7
|
+
const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options);
|
|
8
|
+
if (!info)
|
|
9
|
+
return;
|
|
10
|
+
return compareImageSnapshot(commands, taskId, info, options);
|
|
11
|
+
}
|
|
12
|
+
function parseImageSnapshotSubject(subject) {
|
|
13
|
+
if (subject instanceof Element)
|
|
14
|
+
return convertElementToCssSelector(subject);
|
|
15
|
+
if (subject?.['selector'])
|
|
16
|
+
return subject['selector'];
|
|
17
|
+
if (isBase64String(subject))
|
|
18
|
+
return subject;
|
|
19
|
+
throw new Error(`'toMatchImageSnapshot()' expects the subject to be an element, locator, or image encoded in base64 string, but got: ${subject}`);
|
|
20
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BrowserCommands } from '@vitest/browser/context';
|
|
2
|
+
import type { ImageSnapshotNextIndexCommand } from '../../commands.ts';
|
|
3
|
+
import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts';
|
|
4
|
+
import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts';
|
|
5
|
+
export declare function matchPageImageSnapshotAction(commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand, taskId: string, options?: ToMatchImageSnapshotOptions<any>): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=match_page_image_snapshot_action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match_page_image_snapshot_action.d.ts","sourceRoot":"","sources":["../../../src/client/actions/match_page_image_snapshot_action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,4DAA4D,CAAA;AAEvH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAGxE,wBAAsB,4BAA4B,CACjD,QAAQ,EAAE,eAAe,GAAG,qCAAqC,GAAG,6BAA6B,EACjG,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,2BAA2B,CAAC,GAAG,CAAC,iBAS1C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { assertSnapshotKeyWithoutDash } from "../../shared/asserts.js";
|
|
2
|
+
import { compareImageSnapshot } from "../compare_image_snapshot.js";
|
|
3
|
+
export async function matchPageImageSnapshotAction(commands, taskId, options) {
|
|
4
|
+
assertSnapshotKeyWithoutDash(options?.snapshotKey);
|
|
5
|
+
const info = await commands.preparePageImageSnapshotComparison(taskId, options);
|
|
6
|
+
if (!info)
|
|
7
|
+
return;
|
|
8
|
+
return compareImageSnapshot(commands, taskId, info, options);
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ComparisonMethod } from '../shared/types.ts';
|
|
2
|
+
import type { SnapshotMeta } from './snapshot_meta.ts';
|
|
3
|
+
type Suite = {
|
|
4
|
+
meta: Record<string, any>;
|
|
5
|
+
suite?: Suite | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type MetaTask = {
|
|
8
|
+
file?: {
|
|
9
|
+
meta: Record<string, any>;
|
|
10
|
+
} | undefined;
|
|
11
|
+
suite?: Suite | undefined;
|
|
12
|
+
meta: Record<string, any>;
|
|
13
|
+
} | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Set the snapshot options for auto snapshot.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* beforeAll(() => setAutoSnapshotOptions(...))
|
|
19
|
+
* beforeEach(() => setAutoSnapshotOptions(...))
|
|
20
|
+
*
|
|
21
|
+
* it('...', () => {
|
|
22
|
+
* setAutoSnapshotOptions(...)
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: SnapshotMeta<M> | boolean): void;
|
|
27
|
+
export declare function extractAutoSnapshotOptions<M extends SnapshotMeta<any> = SnapshotMeta<any>>(task: MetaTask): M | undefined;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=auto_snapshot_options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto_snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/auto_snapshot_options.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,CAAA;AAErE,MAAM,MAAM,QAAQ,GACjB;IACA,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,SAAS,CAAA;IAChD,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACxB,GACD,SAAS,CAAA;AAEZ;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,CAYxG;AAUD,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,EACzF,IAAI,EAAE,QAAQ,GACZ,CAAC,GAAG,SAAS,CAkBf"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { assertSnapshotKeyWithoutDash } from "../shared/asserts.js";
|
|
2
|
+
import { NAME } from "../shared/constants.js";
|
|
3
|
+
import { ctx } from "./ctx.js";
|
|
4
|
+
/**
|
|
5
|
+
* Set the snapshot options for auto snapshot.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* beforeAll(() => setAutoSnapshotOptions(...))
|
|
9
|
+
* beforeEach(() => setAutoSnapshotOptions(...))
|
|
10
|
+
*
|
|
11
|
+
* it('...', () => {
|
|
12
|
+
* setAutoSnapshotOptions(...)
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function setAutoSnapshotOptions(meta) {
|
|
17
|
+
if (typeof meta === 'object') {
|
|
18
|
+
assertSnapshotKeyWithoutDash(meta.snapshotKey);
|
|
19
|
+
}
|
|
20
|
+
const task = getTask();
|
|
21
|
+
if (!task)
|
|
22
|
+
return;
|
|
23
|
+
task.meta[NAME] = {
|
|
24
|
+
...task.meta[NAME],
|
|
25
|
+
...parseMeta(meta),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function getTask() {
|
|
29
|
+
return ctx.getCurrentTest() ?? ctx.getCurrentSuite()?.tasks?.[0]?.file;
|
|
30
|
+
}
|
|
31
|
+
function parseMeta(meta) {
|
|
32
|
+
return typeof meta === 'boolean' ? { enable: meta } : { enable: true, ...meta };
|
|
33
|
+
}
|
|
34
|
+
export function extractAutoSnapshotOptions(task) {
|
|
35
|
+
if (!task)
|
|
36
|
+
return;
|
|
37
|
+
const list = [];
|
|
38
|
+
let current = task;
|
|
39
|
+
while (current?.suite) {
|
|
40
|
+
list.unshift(current.suite.meta);
|
|
41
|
+
current = current.suite;
|
|
42
|
+
}
|
|
43
|
+
list.unshift(task.file?.meta);
|
|
44
|
+
list.push(task.meta);
|
|
45
|
+
return list.reduce((acc, cur) => {
|
|
46
|
+
const meta = cur?.[NAME];
|
|
47
|
+
return meta ? Object.assign({}, acc, meta) : acc;
|
|
48
|
+
}, { enable: false });
|
|
49
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BrowserCommands } from '@vitest/browser/context';
|
|
2
|
+
import type { ImageSnapshotNextIndexCommand } from '../commands.ts';
|
|
3
|
+
import type { ImageSnapshotComparisonInfo, PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts';
|
|
4
|
+
import type { ToMatchImageSnapshotOptions } from '../shared/types.ts';
|
|
5
|
+
export declare function compareImageSnapshot(commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand, taskId: string, info: ImageSnapshotComparisonInfo, options?: ToMatchImageSnapshotOptions<any>): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=compare_image_snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare_image_snapshot.d.ts","sourceRoot":"","sources":["../../src/client/compare_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAG9D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EACX,2BAA2B,EAC3B,qCAAqC,EACrC,MAAM,yDAAyD,CAAA;AAEhE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAMrE,wBAAsB,oBAAoB,CACzC,QAAQ,EAAE,eAAe,GAAG,qCAAqC,GAAG,6BAA6B,EACjG,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,2BAA2B,EACjC,OAAO,CAAC,EAAE,2BAA2B,CAAC,GAAG,CAAC,iBA2D1C"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import dedent from 'dedent';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
import { compareImage } from "../shared/compare_image.js";
|
|
4
|
+
import { alignImagesToSameSize } from "./align_images.js";
|
|
5
|
+
import { prettifyOptions } from "./compare_image_snapshot.logic.js";
|
|
6
|
+
import { toDataURL, toImageData } from "./image_data.js";
|
|
7
|
+
import { server } from "./vitest_browser_context_proxy.js";
|
|
8
|
+
export async function compareImageSnapshot(commands, taskId, info, options) {
|
|
9
|
+
options = { ...info, ...options };
|
|
10
|
+
const baselineImage = await toImageData(info.baseline);
|
|
11
|
+
const resultImage = await toImageData(info.result);
|
|
12
|
+
const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage);
|
|
13
|
+
const { width, height } = baselineAlignedImage;
|
|
14
|
+
const diffImage = new ImageData(width, height);
|
|
15
|
+
const { pass, diffAmount } = compareImage(baselineAlignedImage.data, resultAlignedImage.data, diffImage.data, width, height, options);
|
|
16
|
+
if (pass) {
|
|
17
|
+
if (options?.expectToFail) {
|
|
18
|
+
throw new Error(dedent `Snapshot \`${taskId}\` matched but expected to fail.
|
|
19
|
+
|
|
20
|
+
Options: ${prettifyOptions(options)}
|
|
21
|
+
Diff: ${options.failureThresholdType === 'percent' ? `${diffAmount}%` : `${diffAmount} pixels`}
|
|
22
|
+
|
|
23
|
+
Expected: ${resolve(info.projectRoot, info.baselinePath)}
|
|
24
|
+
Actual: ${resolve(info.projectRoot, info.resultPath)}`);
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (server.config.snapshotOptions.updateSnapshot === 'all' && !options?.expectToFail) {
|
|
29
|
+
await writeSnapshot(commands, resolve(info.projectRoot, info.baselinePath), resultImage);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
await writeSnapshot(commands, resolve(info.projectRoot, info.diffPath), diffImage);
|
|
33
|
+
throw new Error(dedent `Snapshot \`${taskId}\` mismatched
|
|
34
|
+
|
|
35
|
+
${options?.failureThreshold
|
|
36
|
+
? options?.failureThresholdType === 'percent'
|
|
37
|
+
? `Expected image to match within ${options.failureThreshold}% but was differ by ${diffAmount}%.`
|
|
38
|
+
: `Expected image to match within ${options.failureThreshold} pixels but was differ by ${diffAmount} pixels.`
|
|
39
|
+
: `Expected image to match but was differ by ${options?.failureThresholdType === 'percent' ? `${diffAmount}%` : `${diffAmount} pixels`}.`}${baselineImage.width !== resultImage.width || baselineImage.height !== resultImage.height
|
|
40
|
+
? `\nThe image size changed from ${baselineImage.width}x${baselineImage.height} to ${resultImage.width}x${resultImage.height}.`
|
|
41
|
+
: ''}
|
|
42
|
+
|
|
43
|
+
Options: ${prettifyOptions(options)}
|
|
44
|
+
|
|
45
|
+
Expected: ${resolve(info.projectRoot, info.baselinePath)}
|
|
46
|
+
Actual: ${resolve(info.projectRoot, info.resultPath)}
|
|
47
|
+
Difference: ${resolve(info.projectRoot, info.diffPath)}`);
|
|
48
|
+
}
|
|
49
|
+
async function writeSnapshot(commands, path, image) {
|
|
50
|
+
const content = (await toDataURL(image)).split(',')[1];
|
|
51
|
+
return commands.writeFile(path, content, { encoding: 'base64' });
|
|
52
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ToMatchImageSnapshotOptions } from '../shared/types.ts';
|
|
2
2
|
export declare function prettifyOptions(options: ToMatchImageSnapshotOptions<any> | undefined): string;
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=compare_image_snapshot.logic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare_image_snapshot.logic.d.ts","sourceRoot":"","sources":["../../src/client/compare_image_snapshot.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAErE,wBAAgB,eAAe,CAAC,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,GAAG,SAAS,UAWpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAMxE,wBAAgB,oBAAoB;AACnC;;;GAGG;AACH,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,GAC/C,sBAAsB,CAcxB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { commands } from '@vitest/browser/context';
|
|
2
|
+
import { matchImageSnapshotAction } from "../actions/match_image_snapshot_action.js";
|
|
2
3
|
import { ctx } from "../ctx.js";
|
|
3
|
-
import {
|
|
4
|
+
import { toTaskId } from "../task_id.js";
|
|
4
5
|
import { success } from "./expectation_result.js";
|
|
5
6
|
export function toMatchImageSnapshot(
|
|
6
7
|
/**
|
|
@@ -14,7 +15,7 @@ subject, options) {
|
|
|
14
15
|
}
|
|
15
16
|
if (test.concurrent) {
|
|
16
17
|
throw new Error('`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +
|
|
17
|
-
"concurrent tests run at the same time in the same iframe and affect each other's environment.
|
|
18
|
+
"concurrent tests run at the same time in the same iframe and affect each other's environment.");
|
|
18
19
|
}
|
|
19
|
-
return
|
|
20
|
+
return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success);
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image_resizer.d.ts","sourceRoot":"","sources":["../../src/client/image_resizer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"image_resizer.d.ts","sourceRoot":"","sources":["../../src/client/image_resizer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,GAC7B,mBAAmB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,MACpD,OAAO,SAAS,cA2BhB,CAAA;AAGF,eAAO,MAAM,mBAAmB,GAC9B,mBAAmB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,MACpD,OAAO,SAAS,cAsBhB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image_snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// import type { ToMatchImageSnapshotOptions } from '../shared/types.ts'
|
|
2
|
+
export {};
|
|
3
|
+
// export function parseImageSnapshotOptions(taskId: string, options: ToMatchImageSnapshotOptions<any> | undefined) {
|
|
4
|
+
// const { snapshotKey, ...rest } = options ?? {}
|
|
5
|
+
// return snapshotKey ? { ...options, snapshotFileId: `${taskId}-${snapshotKey}` } : rest
|
|
6
|
+
// }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { HasImageSnapshotAction } from './has_image_snapshot.ts';
|
|
2
|
+
import type { ToMatchImageSnapshotAction } from './to_match_image_snapshot.ts';
|
|
2
3
|
declare module '@vitest/browser/context' {
|
|
3
|
-
interface BrowserPage extends HasImageSnapshotAction {
|
|
4
|
+
interface BrowserPage extends HasImageSnapshotAction, ToMatchImageSnapshotAction {
|
|
4
5
|
}
|
|
5
6
|
}
|
|
6
7
|
//# sourceMappingURL=augment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"augment.d.ts","sourceRoot":"","sources":["../../../src/client/page/augment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"augment.d.ts","sourceRoot":"","sources":["../../../src/client/page/augment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AAE9E,OAAO,QAAQ,yBAAyB,CAAC;IACxC,UAAU,WAAY,SAAQ,sBAAsB,EAAE,0BAA0B;KAAG;CACnF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { page } from '@vitest/browser/context';
|
|
2
2
|
import "./augment.js";
|
|
3
3
|
import { hasImageSnapshot } from "./has_image_snapshot.js";
|
|
4
|
-
|
|
4
|
+
import { toMatchImageSnapshot } from "./to_match_image_snapshot.js";
|
|
5
|
+
page.extend({ hasImageSnapshot, toMatchImageSnapshot });
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type BrowserPage } from '@vitest/browser/context';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ImageSnapshotKeyOptions } from '../../shared/types.ts';
|
|
3
3
|
export interface HasImageSnapshotAction {
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Check if the snapshot image exists.
|
|
6
|
+
*/
|
|
7
|
+
hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOptions | undefined): Promise<boolean>;
|
|
5
8
|
}
|
|
6
|
-
|
|
7
|
-
* Check if the snapshot image exists.
|
|
8
|
-
*/
|
|
9
|
-
export declare function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotIdOptions | undefined): Promise<boolean>;
|
|
9
|
+
export declare function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOptions | undefined): Promise<boolean>;
|
|
10
10
|
//# sourceMappingURL=has_image_snapshot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAKpE,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACpG;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,SAAS,oBAahG"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { commands } from '@vitest/browser/context';
|
|
2
|
+
import { hasImageSnapshotAction } from "../actions/has_image_snapshot_action.js";
|
|
2
3
|
import { ctx } from "../ctx.js";
|
|
3
4
|
import { toTaskId } from "../task_id.js";
|
|
4
|
-
/**
|
|
5
|
-
* Check if the snapshot image exists.
|
|
6
|
-
*/
|
|
7
5
|
export function hasImageSnapshot(options) {
|
|
8
6
|
const test = ctx.getCurrentTest();
|
|
9
7
|
if (!test) {
|
|
@@ -13,12 +11,5 @@ export function hasImageSnapshot(options) {
|
|
|
13
11
|
throw new Error('`hasImageSnapshot()` cannot be called in a concurrent test because ' +
|
|
14
12
|
"concurrent tests run at the same time in the same iframe and affect each other's environment. ");
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot;
|
|
18
|
-
if (options?.customizeSnapshotId) {
|
|
19
|
-
return commands
|
|
20
|
-
.imageSnapshotNextIndex(taskId)
|
|
21
|
-
.then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot }), isAutoSnapshot));
|
|
22
|
-
}
|
|
23
|
-
return commands.hasImageSnapshot(taskId, undefined, isAutoSnapshot);
|
|
14
|
+
return hasImageSnapshotAction(commands, toTaskId(test), options);
|
|
24
15
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PageImageSnapshotOptions, ToMatchImageSnapshotOptions } from '../../shared/types.ts';
|
|
2
|
+
export interface ToMatchPageImageSnapshotOptions extends ToMatchImageSnapshotOptions, PageImageSnapshotOptions {
|
|
3
|
+
}
|
|
4
|
+
export interface ToMatchImageSnapshotAction {
|
|
5
|
+
toMatchImageSnapshot(options?: ToMatchPageImageSnapshotOptions | undefined): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export declare function toMatchImageSnapshot(options?: ToMatchPageImageSnapshotOptions | undefined): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=to_match_image_snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAKlG,MAAM,WAAW,+BAAgC,SAAQ,2BAA2B,EAAE,wBAAwB;CAAG;AAEjH,MAAM,WAAW,0BAA0B;IAC1C,oBAAoB,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1F;AAED,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,SAAS,iBAczF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { commands } from '@vitest/browser/context';
|
|
2
|
+
import { matchPageImageSnapshotAction } from "../actions/match_page_image_snapshot_action.js";
|
|
3
|
+
import { ctx } from "../ctx.js";
|
|
4
|
+
import { toTaskId } from "../task_id.js";
|
|
5
|
+
export function toMatchImageSnapshot(options) {
|
|
6
|
+
const test = ctx.getCurrentTest();
|
|
7
|
+
if (!test) {
|
|
8
|
+
throw new Error('`toMatchImageSnapshot()` must be called in a test.');
|
|
9
|
+
}
|
|
10
|
+
if (test.concurrent) {
|
|
11
|
+
throw new Error('`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +
|
|
12
|
+
"concurrent tests run at the same time in the same iframe and affect each other's environment.");
|
|
13
|
+
}
|
|
14
|
+
return matchPageImageSnapshotAction(commands, toTaskId(test), options);
|
|
15
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { SetupVisSuiteCommand } from '../../server/commands/setup_vis_suite.ts';
|
|
2
|
+
import type { ComparisonMethod } from '../../shared/types.ts';
|
|
3
|
+
import type { SnapshotMeta } from '../snapshot_meta.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Visual test configuration on the client side.
|
|
6
|
+
*/
|
|
7
|
+
export type VisClientConfigurator<GM extends Record<string, any> | unknown = unknown> = {
|
|
8
|
+
/**
|
|
9
|
+
* Setup the visual test configuration.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Setup with auto snapshot enabled
|
|
14
|
+
* vis().setup({ auto: true })
|
|
15
|
+
*
|
|
16
|
+
* // Setup with auto snapshot disabled
|
|
17
|
+
* vis().setup({ auto: false })
|
|
18
|
+
*
|
|
19
|
+
* // Same as `vis.setup({ auto: false })`
|
|
20
|
+
* vis.setup()
|
|
21
|
+
*
|
|
22
|
+
* // Setup with auto snapshot determined by the test meta
|
|
23
|
+
* vis.setup({
|
|
24
|
+
* auto: async ({ meta }) => meta['darkOnly'],
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* // Setup with multiple auto snapshots
|
|
28
|
+
* vis.setup({
|
|
29
|
+
* auto: {
|
|
30
|
+
* async light() { document.body.classList.remove('dark') },
|
|
31
|
+
* async dark() { document.body.classList.add('dark') },
|
|
32
|
+
* }
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
setup(options?: {
|
|
37
|
+
auto?: boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => boolean | Promise<boolean>) | Record<string, boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => boolean | Promise<boolean>)>;
|
|
38
|
+
}): void;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use `vis.setup()` instead.
|
|
41
|
+
*/
|
|
42
|
+
presets: {
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use `vis.setup()` instead.
|
|
45
|
+
*
|
|
46
|
+
* Enable visual testing.
|
|
47
|
+
*
|
|
48
|
+
* auto snapshot is turned off by default.
|
|
49
|
+
* You can specify the test to take a snapshot during `afterEach()` hook with `setAutoSnapshotOptions()`.
|
|
50
|
+
*/
|
|
51
|
+
enable(): void;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use `vis.setup()` instead.
|
|
54
|
+
*
|
|
55
|
+
* Enable visual testing.
|
|
56
|
+
*
|
|
57
|
+
* `setAutoSnapshotOptions` will have no effect in this preset.
|
|
58
|
+
*/
|
|
59
|
+
manual(): void;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use `vis.setup()` instead.
|
|
62
|
+
*
|
|
63
|
+
* Enable automatic visual testing.
|
|
64
|
+
*
|
|
65
|
+
* This will take a snapshot after each test.
|
|
66
|
+
*/
|
|
67
|
+
auto(): void;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use `vis.setup()` instead.
|
|
70
|
+
*
|
|
71
|
+
* Enable automatic visual testing with multiple themes.
|
|
72
|
+
*
|
|
73
|
+
* This will take a snapshot after each test for each theme.
|
|
74
|
+
*
|
|
75
|
+
* @param themes A record of theme names and their setup functions.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* vis().presets.theme({
|
|
80
|
+
* light() { document.body.classList.add('light') },
|
|
81
|
+
* dark() { document.body.classList.add('dark') },
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
theme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(themes: Record<string, boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>): void;
|
|
86
|
+
};
|
|
87
|
+
beforeAll: {
|
|
88
|
+
setup(): Promise<void>;
|
|
89
|
+
};
|
|
90
|
+
afterEach: {
|
|
91
|
+
matchImageSnapshot(): Promise<void>;
|
|
92
|
+
matchPerTheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(themes: Record<string, boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>): () => Promise<void>;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
export declare function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand): VisClientConfigurator<GM>;
|
|
96
|
+
//# sourceMappingURL=create_vis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_vis.d.ts","sourceRoot":"","sources":["../../../src/client/setup/create_vis.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAA;AACpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAI7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGvD;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,IAAI;IACvF;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QACf,IAAI,CAAC,EACF,OAAO,GACP,CAAC,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAC/E,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAC5B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAChC,MAAM,CACN,MAAM,EACJ,OAAO,GACP,CAAC,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAC/E,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAC5B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CACjC,CAAA;KACJ,GAAG,IAAI,CAAA;IACR;;OAEG;IACH,OAAO,EAAE;QACR;;;;;;;WAOG;QACH,MAAM,IAAI,IAAI,CAAA;QACd;;;;;;WAMG;QACH,MAAM,IAAI,IAAI,CAAA;QACd;;;;;;WAMG;QACH,IAAI,IAAI,IAAI,CAAA;QACZ;;;;;;;;;;;;;;;;WAgBG;QACH,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAClF,MAAM,EAAE,MAAM,CACb,MAAM,EACN,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,CACpG,GACC,IAAI,CAAA;KACP,CAAA;IACD,SAAS,EAAE;QACV,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;KACtB,CAAA;IACD,SAAS,EAAE;QACV,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;QACnC,aAAa,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAC1F,MAAM,EAAE,MAAM,CACb,MAAM,EACN,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,CACpG,GACC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;KACtB,CAAA;CACD,CAAA;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,oBAAoB,6BAmG3G"}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import dedent from 'dedent';
|
|
2
2
|
import { afterEach, beforeAll } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
import { ctx } from "../
|
|
5
|
-
import { shouldTakeSnapshot } from "../
|
|
6
|
-
import {
|
|
3
|
+
import { extractAutoSnapshotOptions, setAutoSnapshotOptions } from "../auto_snapshot_options.js";
|
|
4
|
+
import { ctx } from "../ctx.js";
|
|
5
|
+
import { shouldTakeSnapshot } from "../should_take_snapshot.js";
|
|
6
|
+
import { toTaskId } from "../task_id.js";
|
|
7
7
|
export function createVis(commands) {
|
|
8
|
-
let
|
|
8
|
+
let subject;
|
|
9
9
|
const vis = {
|
|
10
|
+
setup(options) {
|
|
11
|
+
if (!options || options.auto === false) {
|
|
12
|
+
beforeAll(vis.beforeAll.setup);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
beforeAll(async () => {
|
|
16
|
+
await vis.beforeAll.setup();
|
|
17
|
+
setAutoSnapshotOptions(true);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (typeof options?.auto === 'function') {
|
|
21
|
+
afterEach(vis.afterEach.matchPerTheme({
|
|
22
|
+
auto: options.auto,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
else if (typeof options?.auto === 'object') {
|
|
26
|
+
afterEach(vis.afterEach.matchPerTheme(options.auto));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
afterEach(vis.afterEach.matchImageSnapshot);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
10
32
|
presets: {
|
|
11
33
|
enable() {
|
|
12
34
|
beforeAll(vis.beforeAll.setup);
|
|
@@ -16,30 +38,28 @@ export function createVis(commands) {
|
|
|
16
38
|
beforeAll(vis.beforeAll.setup);
|
|
17
39
|
},
|
|
18
40
|
auto() {
|
|
19
|
-
beforeAll(
|
|
41
|
+
beforeAll(async () => {
|
|
42
|
+
await vis.beforeAll.setup();
|
|
43
|
+
setAutoSnapshotOptions(true);
|
|
44
|
+
});
|
|
20
45
|
afterEach(vis.afterEach.matchImageSnapshot);
|
|
21
|
-
enableAuto();
|
|
22
46
|
},
|
|
23
47
|
theme(themes) {
|
|
24
|
-
beforeAll(
|
|
48
|
+
beforeAll(async () => {
|
|
49
|
+
await vis.beforeAll.setup();
|
|
50
|
+
setAutoSnapshotOptions(true);
|
|
51
|
+
});
|
|
25
52
|
afterEach(vis.afterEach.matchPerTheme(themes));
|
|
26
53
|
},
|
|
27
54
|
},
|
|
28
55
|
beforeAll: {
|
|
29
56
|
async setup() {
|
|
30
|
-
|
|
57
|
+
subject = (await commands.setupVisSuite()).subject;
|
|
31
58
|
},
|
|
32
59
|
},
|
|
33
60
|
afterEach: {
|
|
34
61
|
async matchImageSnapshot() {
|
|
35
|
-
|
|
36
|
-
if ((test?.result?.errors?.length ?? 0) > 0)
|
|
37
|
-
return;
|
|
38
|
-
const meta = extractAutoSnapshotOptions(test);
|
|
39
|
-
if (!shouldTakeSnapshot(meta))
|
|
40
|
-
return;
|
|
41
|
-
test.meta.vis = { ...test.meta.vis, isAutoSnapshot: true };
|
|
42
|
-
await test.context.expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta);
|
|
62
|
+
return vis.afterEach.matchPerTheme({ async auto() { } })();
|
|
43
63
|
},
|
|
44
64
|
matchPerTheme(themes) {
|
|
45
65
|
return async function matchImageSnapshot() {
|
|
@@ -53,16 +73,13 @@ export function createVis(commands) {
|
|
|
53
73
|
for (const themeId in themes) {
|
|
54
74
|
try {
|
|
55
75
|
await new Promise((a) => setTimeout(a, 10));
|
|
56
|
-
const
|
|
76
|
+
const theme = themes[themeId];
|
|
77
|
+
const r = typeof theme === 'function' ? await theme(meta) : theme;
|
|
57
78
|
if (r === false)
|
|
58
79
|
continue;
|
|
59
|
-
await test.context
|
|
60
|
-
.expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId))
|
|
61
|
-
.toMatchImageSnapshot({
|
|
80
|
+
await test.context.expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
|
|
62
81
|
...meta,
|
|
63
|
-
|
|
64
|
-
? ({ id, index }) => `${meta.customizeSnapshotId({ id, index, isAutoSnapshot: true })}-${themeId}`
|
|
65
|
-
: ({ id }) => `${id}-${themeId}`,
|
|
82
|
+
snapshotKey: meta?.snapshotKey ?? themeId,
|
|
66
83
|
});
|
|
67
84
|
}
|
|
68
85
|
catch (error) {
|
|
@@ -87,11 +104,6 @@ export function createVis(commands) {
|
|
|
87
104
|
};
|
|
88
105
|
return vis;
|
|
89
106
|
}
|
|
90
|
-
function getSubject(
|
|
91
|
-
|
|
92
|
-
const subject = document.querySelector(`[data-testid="${subjectDataTestId}"]`);
|
|
93
|
-
if (subject)
|
|
94
|
-
return subject;
|
|
95
|
-
}
|
|
96
|
-
return document.body;
|
|
107
|
+
function getSubject(selectors) {
|
|
108
|
+
return selectors ? (document.querySelector(selectors) ?? document.body) : document.body;
|
|
97
109
|
}
|