vitest-plugin-vis 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{augment-BJmy1S7i.d.mts → augment-C1tjdh5B.d.mts} +5 -3
- package/dist/augment-C1tjdh5B.d.mts.map +1 -0
- package/dist/{task_id-DnS9_4Ub.mjs → auto_snapshot_matcher-C0y6mAeS.mjs} +172 -107
- package/dist/auto_snapshot_matcher-C0y6mAeS.mjs.map +1 -0
- package/dist/{auto_snapshot_options-CaQCXDdi.d.mts → auto_snapshot_options-BMRtKmod.d.mts} +3 -3
- package/dist/auto_snapshot_options-BMRtKmod.d.mts.map +1 -0
- package/dist/{auto_snapshot_options-CAD43Zkp.mjs → auto_snapshot_options-DUOTpF2N.mjs} +5 -7
- package/dist/auto_snapshot_options-DUOTpF2N.mjs.map +1 -0
- package/dist/client-api.d.mts +13 -110
- package/dist/client-api.d.mts.map +1 -1
- package/dist/client-api.mjs +3 -3
- package/dist/client-api.mjs.map +1 -1
- package/dist/commands.types-BVhcnnHw.d.mts +51 -0
- package/dist/commands.types-BVhcnnHw.d.mts.map +1 -0
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +1 -1
- package/dist/presets/auto.mjs +3 -3
- package/dist/presets/enable.mjs +3 -3
- package/dist/presets/manual.mjs +3 -3
- package/dist/server-utils.d.mts +4 -4
- package/dist/setup-DCytWz48.mjs +124 -0
- package/dist/setup-DCytWz48.mjs.map +1 -0
- package/dist/setup.d.mts +8 -12
- package/dist/setup.d.mts.map +1 -1
- package/dist/setup.mjs +3 -3
- package/dist/{to_match_image_snapshot.types-p-zilA_M.d.mts → to_match_image_snapshot.types--tTmHoRA.d.mts} +2 -2
- package/dist/{to_match_image_snapshot.types-p-zilA_M.d.mts.map → to_match_image_snapshot.types--tTmHoRA.d.mts.map} +1 -1
- package/dist/{trim_common_folder-ModiubEJ.d.mts → trim_common_folder-DBThLerp.d.mts} +1 -1
- package/dist/trim_common_folder-DBThLerp.d.mts.map +1 -0
- package/dist/{types-DFb23VE1.d.mts → types-CEmjj-A9.d.mts} +37 -3
- package/dist/types-CEmjj-A9.d.mts.map +1 -0
- package/dist/{types-Do1N7g4c.d.mts → types-DJYCbyT8.d.mts} +2 -2
- package/dist/{types-Do1N7g4c.d.mts.map → types-DJYCbyT8.d.mts.map} +1 -1
- package/package.json +5 -5
- package/src/client/actions/has_image_snapshot_action.ts +1 -1
- package/src/client/actions/load_image_snapshot_results_action.ts +1 -1
- package/src/client/actions/match_image_snapshot_action.ts +6 -4
- package/src/client/actions/match_page_image_snapshot_action.ts +5 -3
- package/src/client/expect/_ctx.ts +10 -0
- package/src/client/expect/to_match_image_snapshot.ts +3 -4
- package/src/client/external/browser/has_render_content.ts +3 -0
- package/src/client/{image_resizer.ts → external/browser/image_resizer.ts} +1 -1
- package/src/client/{vitest_suite_proxy.ts → external/vitest/vitest_suite_proxy.ts} +1 -1
- package/src/client/{align_images.ts → image/align_images.ts} +3 -3
- package/src/client/page/_ctx.ts +12 -0
- package/src/client/page/has_image_snapshot.ts +4 -4
- package/src/client/page/to_match_image_snapshot.ts +3 -4
- package/src/client/{compare_image_snapshot.logic.ts → snapshot/compare_image_snapshot.logic.ts} +1 -1
- package/src/client/{compare_image_snapshot.ts → snapshot/compare_image_snapshot.ts} +8 -9
- package/src/client/snapshot/should_take_snapshot.ts +6 -0
- package/src/client/suite/_ctx.ts +8 -0
- package/src/client/suite/auto_snapshot_matcher.ts +68 -0
- package/src/client/{ctx.ts → task/_ctx.ts} +1 -3
- package/src/client/{auto_snapshot_options.ts → task/auto_snapshot_options.ts} +4 -4
- package/src/client/{snapshot_meta.ts → task/snapshot_meta.ts} +1 -1
- package/src/client-api.ts +3 -2
- package/src/index.ts +1 -1
- package/src/server/commands/augment.ts +8 -6
- package/src/server/commands/has_image_snapshot.ts +1 -4
- package/src/server/commands/image_snapshot_next_index.ts +1 -7
- package/src/server/commands/load_image_snapshot_results.ts +1 -20
- package/src/server/commands/prepare_image_snapshot_comparison.ts +2 -48
- package/src/server/commands/prepare_page_image_snapshot_comparison.ts +1 -43
- package/src/server/commands/setup_vis_suite.ts +0 -24
- package/src/server/vis_server_context.logic.ts +1 -1
- package/src/{client/setup → setup}/create_vis.ts +22 -79
- package/src/setup/readme.md +5 -0
- package/src/setup.ts +2 -2
- package/src/shared/commands.types.ts +71 -0
- package/src/shared/types.ts +53 -1
- package/dist/augment-BJmy1S7i.d.mts.map +0 -1
- package/dist/auto_snapshot_options-CAD43Zkp.mjs.map +0 -1
- package/dist/auto_snapshot_options-CaQCXDdi.d.mts.map +0 -1
- package/dist/setup-BWgIDtv-.mjs +0 -141
- package/dist/setup-BWgIDtv-.mjs.map +0 -1
- package/dist/setup_vis_suite-C6JGGT7B.d.mts +0 -17
- package/dist/setup_vis_suite-C6JGGT7B.d.mts.map +0 -1
- package/dist/task_id-DnS9_4Ub.mjs.map +0 -1
- package/dist/trim_common_folder-ModiubEJ.d.mts.map +0 -1
- package/dist/types-DFb23VE1.d.mts.map +0 -1
- package/dist/vis_server_context.types-Ce1f9vOO.d.mts +0 -1
- package/src/client/image_snapshot_options.ts +0 -6
- package/src/client/setup/vis.ctx.ts +0 -34
- package/src/client/should_take_snapshot.ts +0 -5
- package/src/server/commands/types.ts +0 -9
- /package/src/client/{image_data.ts → external/browser/image_data.ts} +0 -0
- /package/src/client/{selector.ts → external/browser/selector.ts} +0 -0
- /package/src/client/{vitest_browser_context_proxy.ts → external/vitest/vitest_browser_context_proxy.ts} +0 -0
- /package/src/client/{auto_snapshot_options.mdx → task/auto_snapshot_options.mdx} +0 -0
- /package/src/client/{task_id.ts → task/task_id.ts} +0 -0
- /package/src/{client/setup → setup}/vis.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pixelMatch from "pixelmatch";
|
|
2
2
|
import { Options as SsimDiffOptions } from "ssim.js";
|
|
3
3
|
|
|
4
|
-
//#region src/client/snapshot_meta.d.ts
|
|
4
|
+
//#region src/client/task/snapshot_meta.d.ts
|
|
5
5
|
type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions & {
|
|
6
6
|
/**
|
|
7
7
|
* Whether to enable the snapshot.
|
|
@@ -105,6 +105,40 @@ type SnapshotTestMeta = {
|
|
|
105
105
|
[NAME]?: SnapshotMeta<ComparisonMethod>;
|
|
106
106
|
};
|
|
107
107
|
};
|
|
108
|
+
type ImageSnapshotComparisonInfo = {
|
|
109
|
+
/**
|
|
110
|
+
* Path to the project root.
|
|
111
|
+
*/
|
|
112
|
+
projectRoot: string;
|
|
113
|
+
/**
|
|
114
|
+
* Path to the baseline image relative to the project root.
|
|
115
|
+
*/
|
|
116
|
+
baselinePath: string;
|
|
117
|
+
/**
|
|
118
|
+
* Path to the result image relative to the project root.
|
|
119
|
+
*/
|
|
120
|
+
resultPath: string;
|
|
121
|
+
/**
|
|
122
|
+
* Path to the diff image relative to the project root.
|
|
123
|
+
*/
|
|
124
|
+
diffPath: string;
|
|
125
|
+
/**
|
|
126
|
+
* Base64 encoded baseline image.
|
|
127
|
+
*/
|
|
128
|
+
baseline: string;
|
|
129
|
+
/**
|
|
130
|
+
* Base64 encoded result image.
|
|
131
|
+
*/
|
|
132
|
+
result: string;
|
|
133
|
+
/**
|
|
134
|
+
* Base64 encoded diff image.
|
|
135
|
+
*/
|
|
136
|
+
diff?: string | undefined;
|
|
137
|
+
} & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions);
|
|
138
|
+
type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotCompareOptions<any> & ImageSnapshotKeyOptions;
|
|
139
|
+
type SetupVisOptions<GM extends Record<string, any> | unknown = unknown> = {
|
|
140
|
+
auto?: boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void) | Record<string, boolean | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)>;
|
|
141
|
+
};
|
|
108
142
|
//#endregion
|
|
109
|
-
export {
|
|
110
|
-
//# sourceMappingURL=types-
|
|
143
|
+
export { SNAPSHOT_ROOT_DIR as C, RESULT_DIR as S, ToMatchImageSnapshotOptions as _, ImageSnapshotComparisonInfo as a, DIFF_DIR as b, ImageSnapshotTimeoutOptions as c, PixelComparisonOptions as d, PixelDiffOptions as f, SsimDiffOptions as g, SsimComparisonOptions as h, ImageSnapshotCompareOptions as i, MatchImageSnapshotOptions as l, SnapshotTestMeta as m, ComparisonMethod as n, ImageSnapshotKeyOptions as o, SetupVisOptions as p, FailureThresholdOptions as r, ImageSnapshotSubjectOptions as s, Awaitable as t, PageImageSnapshotOptions as u, ToMatchPageImageSnapshotOptions as v, SnapshotMeta as w, NAME as x, BASELINE_DIR as y };
|
|
144
|
+
//# sourceMappingURL=types-CEmjj-A9.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CEmjj-A9.d.mts","names":[],"sources":["../src/client/task/snapshot_meta.ts","../src/shared/constants.ts","../src/shared/types.ts"],"sourcesContent":[],"mappings":";;;;KAEY,uBAAuB,oBAAoB,4BAA4B,KAClF;;;AADD;;;EAAuD,MAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EACtD,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;CAA2B;;;cCHf,IAAA;cACA,iBAAA;cACA,YAAA;cACA,UAAA;ADDD,cCEC,QAAA,GDFW,WAAA;;;AAAZ,KEGA,SFHY,CAAA,CAAA,CAAA,GEGG,CFHH,GEGO,WFHP,CEGmB,CFHnB,CAAA;AAAW,UEKlB,2BAAA,CFLkB;EAAgD;;;;;;;ACFtE,UCgBI,uBAAA,CDhBA;EACJ;AACb;AACA;EACa,WAAQ,CAAA,EAAA,MAAA,GAAA,SAAA;;KCmBT,gBAAA;KAEA,uBAAA;EApBA;;;;;EAEK,oBAAA,CAAA,EAAA,OAA2B,GAAA,SAAA,GAAA,SAAA;EAS3B;AAOjB;AAEA;AA6BA;;;;;AAUA;AAQA;AAEA;;;;;;;;;EAKY,gBAAA,CAAA,EAAA,MAAA,GAAA,SAA2B;AASvC,CAAA;AAAkD,KAlCtC,qBAkCsC,CAAA,IAAA,MAAA,CAAA,GAAA;EAA8B,gBAAA,EAjC7D,CAiC6D;EAC/E;;;EAC2B,WAAA,CAAA,EA/Bb,OA+Ba,CA/BL,eA+BK,CAAA,GAAA,SAAA;AAQ5B,CAAA;AAIsD,KAtC1C,sBAsC0C,CAAA,IAAA,OAAA,CAAA,GAAA;EAA0D,gBAAA,CAAA,EArC5F,CAqC4F,GAAA,SAAA;EAA5B;;;EAGxE,WAAA,CAAA,EApCG,gBAoCa,GAAA,SAAA;CAEJ;AAAb,KAnCC,gBAAA,GAAmB,UAmCpB,CAAA,OAnCsC,UAmCtC,CAAA,CAAA,CAAA,CAAA;AAAR,KAjCS,2BAiCT,CAAA,UAjC+C,gBAiC/C,GAAA,OAAA,CAAA,GAAA,CAjC8E,CAiC9E,SAAA,MAAA,GAhCA,qBAgCA,CAhCsB,CAgCtB,CAAA,GA/BA,sBA+BA,CA/BuB,CA+BvB,CAAA,CAAA,GA9BF,uBA8BE;AAAI,KA5BK,2BAAA,GA4BL;EAIK;;;;;;EAiCA,OAAA,CAAA,EAAA,MAAA,GAAA,SAAyB;CAAG;AACvC,KAzDW,2BAyDX,CAAA,UAzDiD,gBAyDjD,GAAA,OAAA,CAAA,GAzD+E,2BAyD/E,GAxDA,uBAwDA,GAvDA,2BAuDA,CAvD4B,CAuD5B,CAAA,GAAA;EACA;;AAED;;EAGgB,YAAA,CAAA,EAAA,OAAA,GAAA,SAAA;CAA4B;AAClB,UAtDT,wBAAA,CAsDS;EAAb,QAAA,CAAA,EAAA,OAAA,GAAA,SAAA;;AAAsB,KAlDvB,+BAkDuB,CAAA,UAlDmB,gBAkDnB,GAAA,OAAA,CAAA,GAlDiD,2BAkDjD,CAlD6E,CAkD7E,CAAA,GAjDlC,wBAiDkC;AAC1B,KAhDG,gBAAA,GAgDH;EAAmB,IAAA,EAAA;IAIV,CAlDf,IAAA,EAkDe,EAlDP,YAkDO,CAlDM,gBAkDN,CAAA;EAA4B,CAAA;CAClB;AAAb,KA/CH,2BAAA,GA+CG;EAAkB;;;EACH,WAAA,EAAA,MAAA;EAL1B;;;;;;;;;;;;;;;;;;;;;;;;IAdA,8BACH,2BACC,wBAAwB;KAEd,yBAAA,GAA4B,8BACvC,mCACA;KAEW,2BAA2B;+BAGvB,4BAA4B,kDAC/B,aAAa,KAAK,IAAI,OAC1B,mBAAmB,kCACxB,qCAGc,4BAA4B,kDAC/B,aAAa,KAAK,IAAI,OAC1B,mBAAmB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as ImageSnapshotTimeoutOptions, f as PixelDiffOptions, g as SsimDiffOptions, n as ComparisonMethod, o as ImageSnapshotKeyOptions, r as FailureThresholdOptions, s as ImageSnapshotSubjectOptions } from "./types-CEmjj-A9.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/config/types.d.ts
|
|
4
4
|
type VisOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? {
|
|
@@ -60,4 +60,4 @@ type VisOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? {
|
|
|
60
60
|
};
|
|
61
61
|
//#endregion
|
|
62
62
|
export { VisOptions as t };
|
|
63
|
-
//# sourceMappingURL=types-
|
|
63
|
+
//# sourceMappingURL=types-DJYCbyT8.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-DJYCbyT8.d.mts","names":[],"sources":["../src/config/types.ts"],"sourcesContent":[],"mappings":";;;KAcY,qBAAqB,+BAA+B;EAApD,gBAAU,EAED,CAFC;EAAW;;;EAMR,WAAA,CAAA,EAAR,OAAQ,CAAA,eAAA,CAAA,GAAA,SAAA;CAAR,GAAA;EAGK,gBAAA,CAAA,EAAA,CAAA,GAAA,SAAA;EAIL;;;EAIhB,WAAA,CAAA,EAJgB,gBAIhB,GAAA,SAAA;CACA,CAAA,GAHA,uBAGA,GAFA,2BAEA,GADA,uBACA,GAAA,2BAAA,GAAA;EAA2B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-plugin-vis",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Vitest visual testing plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image-snapshot",
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"@repobuddy/storybook": "^2.1.2",
|
|
85
85
|
"@repobuddy/typescript": "^2.1.0",
|
|
86
86
|
"@storybook-community/storybook-dark-mode": "^7.0.3",
|
|
87
|
-
"@storybook/addon-docs": "^10.1
|
|
88
|
-
"@storybook/addon-vitest": "^10.1
|
|
89
|
-
"@storybook/react-vite": "^10.1
|
|
87
|
+
"@storybook/addon-docs": "^10.2.0-alpha.1",
|
|
88
|
+
"@storybook/addon-vitest": "^10.2.0-alpha.1",
|
|
89
|
+
"@storybook/react-vite": "^10.2.0-alpha.1",
|
|
90
90
|
"@tailwindcss/vite": "^4.1.14",
|
|
91
91
|
"@types/is-ci": "^3.0.4",
|
|
92
92
|
"@types/pngjs": "^6.0.5",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"npm-run-all2": "^8.0.0",
|
|
104
104
|
"react": "^19.0.0",
|
|
105
105
|
"react-dom": "^19.0.0",
|
|
106
|
-
"storybook": "^10.1
|
|
106
|
+
"storybook": "^10.2.0-alpha.1",
|
|
107
107
|
"storybook-addon-tag-badges": "^3.0.2",
|
|
108
108
|
"tailwindcss": "^4.1.14",
|
|
109
109
|
"tsdown": "^0.16.6",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HasImageSnapshotCommand, ImageSnapshotNextIndexCommand } from '../../commands.ts'
|
|
1
|
+
import type { HasImageSnapshotCommand, ImageSnapshotNextIndexCommand } from '../../shared/commands.types.ts'
|
|
2
2
|
import type { ImageSnapshotKeyOptions } from '../../shared/types.ts'
|
|
3
3
|
|
|
4
4
|
export function hasImageSnapshotAction(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LoadImageSnapshotResultsCommand } from '../../
|
|
1
|
+
import type { LoadImageSnapshotResultsCommand } from '../../shared/commands.types.ts'
|
|
2
2
|
|
|
3
3
|
export function loadImageSnapshotResultsAction(commands: LoadImageSnapshotResultsCommand, taskId: string) {
|
|
4
4
|
return commands.loadImageSnapshotResults(taskId)
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { BrowserCommands } from 'vitest/browser'
|
|
2
|
-
import type { ImageSnapshotNextIndexCommand } from '../../commands.ts'
|
|
3
|
-
import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts'
|
|
4
2
|
import { assertSnapshotKeyWithoutDash } from '../../shared/asserts.ts'
|
|
5
3
|
import { isBase64String } from '../../shared/base64.ts'
|
|
4
|
+
import type {
|
|
5
|
+
ImageSnapshotNextIndexCommand,
|
|
6
|
+
PrepareImageSnapshotComparisonCommand,
|
|
7
|
+
} from '../../shared/commands.types.ts'
|
|
6
8
|
import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
+
import { convertElementToCssSelector } from '../external/browser/selector.ts'
|
|
10
|
+
import { compareImageSnapshot } from '../snapshot/compare_image_snapshot.ts'
|
|
9
11
|
|
|
10
12
|
export async function matchImageSnapshotAction(
|
|
11
13
|
commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { BrowserCommands } from 'vitest/browser'
|
|
2
|
-
import type { ImageSnapshotNextIndexCommand } from '../../commands.ts'
|
|
3
|
-
import type { PrepareImageSnapshotComparisonCommand } from '../../server/commands/prepare_image_snapshot_comparison.ts'
|
|
4
2
|
import { assertSnapshotKeyWithoutDash } from '../../shared/asserts.ts'
|
|
3
|
+
import type {
|
|
4
|
+
ImageSnapshotNextIndexCommand,
|
|
5
|
+
PrepareImageSnapshotComparisonCommand,
|
|
6
|
+
} from '../../shared/commands.types.ts'
|
|
5
7
|
import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'
|
|
6
|
-
import { compareImageSnapshot } from '../compare_image_snapshot.ts'
|
|
8
|
+
import { compareImageSnapshot } from '../snapshot/compare_image_snapshot.ts'
|
|
7
9
|
|
|
8
10
|
export async function matchPageImageSnapshotAction(
|
|
9
11
|
commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { commands } from 'vitest/browser'
|
|
2
1
|
import type { AsyncExpectationResult } from '@vitest/expect'
|
|
3
2
|
import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'
|
|
4
3
|
import { matchImageSnapshotAction } from '../actions/match_image_snapshot_action.ts'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { toTaskId } from '../task/task_id.ts'
|
|
5
|
+
import { ctx } from './_ctx.ts'
|
|
7
6
|
import { success } from './expectation_result.ts'
|
|
8
7
|
|
|
9
8
|
export function toMatchImageSnapshot(
|
|
@@ -26,5 +25,5 @@ export function toMatchImageSnapshot(
|
|
|
26
25
|
)
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)
|
|
28
|
+
return matchImageSnapshotAction(ctx.commands, toTaskId(test), subject, options).then(() => success)
|
|
30
29
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getMaxSize } from '
|
|
2
|
-
import { isSameSize } from '
|
|
3
|
-
import { createImageResizer } from '
|
|
1
|
+
import { getMaxSize } from '../../shared/get_max_size.ts'
|
|
2
|
+
import { isSameSize } from '../../shared/is_same_size.ts'
|
|
3
|
+
import { createImageResizer } from '../external/browser/image_resizer.ts'
|
|
4
4
|
|
|
5
5
|
export function alignImagesToSameSize(image1: ImageData, image2: ImageData): [image1: ImageData, image2: ImageData] {
|
|
6
6
|
if (isSameSize(image1, image2)) return [image1, image2] as const
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type BrowserPage, commands } from 'vitest/browser'
|
|
2
|
+
import { getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
|
|
3
|
+
|
|
4
|
+
export type { BrowserPage }
|
|
5
|
+
|
|
6
|
+
export const ctx = {
|
|
7
|
+
commands,
|
|
8
|
+
getCurrentTest,
|
|
9
|
+
__test__reset() {
|
|
10
|
+
ctx.getCurrentTest = getCurrentTest
|
|
11
|
+
},
|
|
12
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type BrowserPage, commands } from 'vitest/browser'
|
|
2
1
|
import type { ImageSnapshotKeyOptions } from '../../shared/types.ts'
|
|
3
2
|
import { hasImageSnapshotAction } from '../actions/has_image_snapshot_action.ts'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { toTaskId } from '../task/task_id.ts'
|
|
4
|
+
import type { BrowserPage } from './_ctx.ts'
|
|
5
|
+
import { ctx } from './_ctx.ts'
|
|
6
6
|
|
|
7
7
|
export interface HasImageSnapshotAction {
|
|
8
8
|
/**
|
|
@@ -23,5 +23,5 @@ export function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOp
|
|
|
23
23
|
"concurrent tests run at the same time in the same iframe and affect each other's environment. ",
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
|
-
return hasImageSnapshotAction(commands, toTaskId(test), options)
|
|
26
|
+
return hasImageSnapshotAction(ctx.commands, toTaskId(test), options)
|
|
27
27
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { commands } from 'vitest/browser'
|
|
2
1
|
import type { ComparisonMethod, ToMatchPageImageSnapshotOptions } from '../../shared/types.ts'
|
|
3
2
|
import { matchPageImageSnapshotAction } from '../actions/match_page_image_snapshot_action.ts'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { toTaskId } from '../task/task_id.ts'
|
|
4
|
+
import { ctx } from './_ctx.ts'
|
|
6
5
|
|
|
7
6
|
export interface ToMatchImageSnapshotAction {
|
|
8
7
|
toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(
|
|
@@ -25,5 +24,5 @@ export function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(
|
|
|
25
24
|
)
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
return matchPageImageSnapshotAction(commands, toTaskId(test), options)
|
|
27
|
+
return matchPageImageSnapshotAction(ctx.commands, toTaskId(test), options)
|
|
29
28
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { BrowserCommands } from 'vitest/browser'
|
|
2
1
|
import dedent from 'dedent'
|
|
3
2
|
import { resolve } from 'pathe'
|
|
4
|
-
import type {
|
|
3
|
+
import type { BrowserCommands } from 'vitest/browser'
|
|
5
4
|
import type {
|
|
6
|
-
|
|
5
|
+
ImageSnapshotNextIndexCommand,
|
|
7
6
|
PrepareImageSnapshotComparisonCommand,
|
|
8
|
-
} from '
|
|
9
|
-
import { compareImage } from '
|
|
10
|
-
import type { ToMatchImageSnapshotOptions } from '
|
|
11
|
-
import {
|
|
7
|
+
} from '../../shared/commands.types.ts'
|
|
8
|
+
import { compareImage } from '../../shared/compare_image.ts'
|
|
9
|
+
import type { ImageSnapshotComparisonInfo, ToMatchImageSnapshotOptions } from '../../shared/types.ts'
|
|
10
|
+
import { toDataURL, toImageData } from '../external/browser/image_data.ts'
|
|
11
|
+
import { server } from '../external/vitest/vitest_browser_context_proxy.ts'
|
|
12
|
+
import { alignImagesToSameSize } from '../image/align_images.ts'
|
|
12
13
|
import { prettifyOptions } from './compare_image_snapshot.logic.ts'
|
|
13
|
-
import { toDataURL, toImageData } from './image_data.ts'
|
|
14
|
-
import { server } from './vitest_browser_context_proxy.ts'
|
|
15
14
|
|
|
16
15
|
export async function compareImageSnapshot(
|
|
17
16
|
commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import dedent from 'dedent'
|
|
2
|
+
import type { SetupVisSuiteCommand } from '../../shared/commands.types.ts'
|
|
3
|
+
import type { ComparisonMethod } from '../../shared/types.ts'
|
|
4
|
+
import { shouldTakeSnapshot } from '../snapshot/should_take_snapshot.ts'
|
|
5
|
+
import { extractAutoSnapshotOptions } from '../task/auto_snapshot_options.ts'
|
|
6
|
+
import type { SnapshotMeta } from '../task/snapshot_meta.ts'
|
|
7
|
+
import { toTaskId } from '../task/task_id.ts'
|
|
8
|
+
import { ctx } from './_ctx.ts'
|
|
9
|
+
|
|
10
|
+
export function autoSnapshotMatcher<GM extends Record<string, any> | unknown = unknown>(
|
|
11
|
+
commands: SetupVisSuiteCommand,
|
|
12
|
+
expect: any,
|
|
13
|
+
) {
|
|
14
|
+
let subject: string | undefined
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
async setup() {
|
|
18
|
+
subject = (await commands.setupVisSuite()).subject
|
|
19
|
+
},
|
|
20
|
+
createMatcher<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
|
|
21
|
+
themes: Record<
|
|
22
|
+
string,
|
|
23
|
+
boolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)
|
|
24
|
+
>,
|
|
25
|
+
) {
|
|
26
|
+
return async function matchImageSnapshot() {
|
|
27
|
+
const test = ctx.getCurrentTest()
|
|
28
|
+
if ((test?.result?.errors?.length ?? 0) > 0) return
|
|
29
|
+
|
|
30
|
+
const meta = extractAutoSnapshotOptions(test)
|
|
31
|
+
if (!shouldTakeSnapshot(meta)) return
|
|
32
|
+
const errors: Array<[string, Error]> = []
|
|
33
|
+
for (const themeId in themes) {
|
|
34
|
+
try {
|
|
35
|
+
await new Promise((a) => setTimeout(a, 10))
|
|
36
|
+
const theme = themes[themeId]
|
|
37
|
+
const r = typeof theme === 'function' ? await theme(meta! as any) : theme
|
|
38
|
+
if (r === false) continue
|
|
39
|
+
await expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
|
|
40
|
+
...meta,
|
|
41
|
+
snapshotKey: meta?.snapshotKey ?? themeId,
|
|
42
|
+
})
|
|
43
|
+
} catch (error) {
|
|
44
|
+
errors.push([themeId, error as Error])
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
if (errors.length === 1) throw errors[0]![1]
|
|
49
|
+
const taskId = toTaskId(test!)
|
|
50
|
+
throw new AggregateError(
|
|
51
|
+
errors,
|
|
52
|
+
dedent`Snapshot \`${taskId}\` mismatched
|
|
53
|
+
|
|
54
|
+
${errors
|
|
55
|
+
.map(([themeId, error]) => {
|
|
56
|
+
return `Theme \`${themeId}\` failed: ${error.message}`
|
|
57
|
+
})
|
|
58
|
+
.join('\n\n')}`,
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getSubject(selectors: string | undefined) {
|
|
67
|
+
return selectors ? (document.querySelector(selectors) ?? document.body) : document.body
|
|
68
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { getCurrentSuite, getCurrentTest } from '
|
|
1
|
+
import { getCurrentSuite, getCurrentTest } from '../external/vitest/vitest_suite_proxy.ts'
|
|
2
2
|
|
|
3
3
|
export const ctx = {
|
|
4
|
-
autoEnabled: undefined as boolean | undefined,
|
|
5
4
|
getCurrentTest,
|
|
6
5
|
getCurrentSuite,
|
|
7
6
|
__test__reset() {
|
|
8
7
|
ctx.getCurrentTest = getCurrentTest
|
|
9
8
|
ctx.getCurrentSuite = getCurrentSuite
|
|
10
|
-
ctx.autoEnabled = undefined
|
|
11
9
|
},
|
|
12
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { assertSnapshotKeyWithoutDash } from '
|
|
2
|
-
import { NAME } from '
|
|
3
|
-
import type { ComparisonMethod } from '
|
|
4
|
-
import { ctx } from './
|
|
1
|
+
import { assertSnapshotKeyWithoutDash } from '../../shared/asserts.ts'
|
|
2
|
+
import { NAME } from '../../shared/constants.ts'
|
|
3
|
+
import type { ComparisonMethod } from '../../shared/types.ts'
|
|
4
|
+
import { ctx } from './_ctx.ts'
|
|
5
5
|
import type { SnapshotMeta } from './snapshot_meta.ts'
|
|
6
6
|
|
|
7
7
|
type Suite = { meta: Record<string, any>; suite?: Suite | undefined }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComparisonMethod, ImageSnapshotSubjectOptions, ToMatchImageSnapshotOptions } from '
|
|
1
|
+
import type { ComparisonMethod, ImageSnapshotSubjectOptions, ToMatchImageSnapshotOptions } from '../../shared/types.ts'
|
|
2
2
|
|
|
3
3
|
export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> &
|
|
4
4
|
ImageSnapshotSubjectOptions & {
|
package/src/client-api.ts
CHANGED
|
@@ -4,9 +4,10 @@ export * from './client/actions/has_image_snapshot_action.ts'
|
|
|
4
4
|
export * from './client/actions/load_image_snapshot_results_action.ts'
|
|
5
5
|
export * from './client/actions/match_image_snapshot_action.ts'
|
|
6
6
|
export * from './client/actions/match_page_image_snapshot_action.ts'
|
|
7
|
-
export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts'
|
|
8
7
|
export * from './client/expect/expectation_result.ts'
|
|
9
8
|
export type * from './client/expect/to_match_image_snapshot.types.ts'
|
|
10
|
-
export * from './client/
|
|
9
|
+
export * from './client/suite/auto_snapshot_matcher.ts'
|
|
10
|
+
export { setAutoSnapshotOptions, type MetaTask } from './client/task/auto_snapshot_options.ts'
|
|
11
|
+
export * from './client/task/task_id.ts'
|
|
11
12
|
export * from './shared/constants.ts'
|
|
12
13
|
export type * from './shared/types.ts'
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
import './client/expect/augment.ts'
|
|
3
3
|
import './client/page/augment.ts'
|
|
4
4
|
|
|
5
|
-
export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts'
|
|
5
|
+
export { setAutoSnapshotOptions, type MetaTask } from './client/task/auto_snapshot_options.ts'
|
|
6
6
|
export type * from './shared/types.ts'
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type {
|
|
2
|
+
HasImageSnapshotCommand,
|
|
3
|
+
ImageSnapshotNextIndexCommand,
|
|
4
|
+
LoadImageSnapshotResultsCommand,
|
|
5
|
+
PrepareImageSnapshotComparisonCommand,
|
|
6
|
+
PreparePageImageSnapshotComparisonCommand,
|
|
7
|
+
SetupVisSuiteCommand,
|
|
8
|
+
} from '../../shared/commands.types.ts'
|
|
7
9
|
|
|
8
10
|
declare module 'vitest/browser' {
|
|
9
11
|
interface BrowserCommands
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import type { HasImageSnapshotCommand } from '../../shared/commands.types.ts'
|
|
1
2
|
import { visServerContext } from '../vis_server_context.ts'
|
|
2
3
|
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
3
4
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
5
|
|
|
5
|
-
export interface HasImageSnapshotCommand {
|
|
6
|
-
hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
6
|
export const hasImageSnapshot: ExtendedBrowserCommand<Parameters<HasImageSnapshotCommand['hasImageSnapshot']>> = async (
|
|
10
7
|
context,
|
|
11
8
|
taskId,
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
+
import type { ImageSnapshotNextIndexCommand } from '../../shared/commands.types.ts'
|
|
1
2
|
import { visServerContext } from '../vis_server_context.ts'
|
|
2
3
|
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
3
4
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
5
|
|
|
5
|
-
export interface ImageSnapshotNextIndexCommand {
|
|
6
|
-
/**
|
|
7
|
-
* Get the index of the snapshot image to be created.
|
|
8
|
-
*/
|
|
9
|
-
imageSnapshotNextIndex(taskId: string): Promise<number>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
6
|
export const imageSnapshotNextIndex: ExtendedBrowserCommand<
|
|
13
7
|
Parameters<ImageSnapshotNextIndexCommand['imageSnapshotNextIndex']>
|
|
14
8
|
> = async (context, taskId) => {
|
|
@@ -1,27 +1,8 @@
|
|
|
1
|
+
import type { ImageSnapshotResult } from '../../shared/commands.types.ts'
|
|
1
2
|
import { visServerContext } from '../vis_server_context.ts'
|
|
2
3
|
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
3
4
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
5
|
|
|
5
|
-
export interface ImageSnapshotResult {
|
|
6
|
-
filename: string
|
|
7
|
-
/**
|
|
8
|
-
* The base64 encoded image of the baseline snapshot.
|
|
9
|
-
*/
|
|
10
|
-
baseline?: string | undefined
|
|
11
|
-
/**
|
|
12
|
-
* The base64 encoded image of the result snapshot.
|
|
13
|
-
*/
|
|
14
|
-
result?: string | undefined
|
|
15
|
-
/**
|
|
16
|
-
* The base64 encoded image of the diff snapshot.
|
|
17
|
-
*/
|
|
18
|
-
diff?: string | undefined
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface LoadImageSnapshotResultsCommand {
|
|
22
|
-
loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
6
|
export const loadImageSnapshotResults: ExtendedBrowserCommand<[taskId: string]> = async (
|
|
26
7
|
context,
|
|
27
8
|
taskId,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { resolve } from 'pathe'
|
|
2
2
|
import { isBase64String } from '../../shared/base64.ts'
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
ImageSnapshotTimeoutOptions,
|
|
6
|
-
PixelComparisonOptions,
|
|
7
|
-
SsimComparisonOptions,
|
|
8
|
-
} from '../../shared/types.ts'
|
|
3
|
+
import type { PrepareImageSnapshotComparisonCommand } from '../../shared/commands.types.ts'
|
|
4
|
+
import type { ImageSnapshotComparisonInfo } from '../../shared/types.ts'
|
|
9
5
|
import { file } from '../externals/file.ts'
|
|
10
6
|
import { getProjectRoot } from '../project.ts'
|
|
11
7
|
import { takeSnapshot, takeSnapshotByBrowser } from '../snapshot.ts'
|
|
@@ -13,48 +9,6 @@ import { snapshotWriter } from '../snapshot_writer.ts'
|
|
|
13
9
|
import { visServerContext } from '../vis_server_context.ts'
|
|
14
10
|
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
15
11
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
16
|
-
import type { MatchImageSnapshotOptions } from './types.ts'
|
|
17
|
-
|
|
18
|
-
export type ImageSnapshotComparisonInfo = {
|
|
19
|
-
/**
|
|
20
|
-
* Path to the project root.
|
|
21
|
-
*/
|
|
22
|
-
projectRoot: string
|
|
23
|
-
/**
|
|
24
|
-
* Path to the baseline image relative to the project root.
|
|
25
|
-
*/
|
|
26
|
-
baselinePath: string
|
|
27
|
-
/**
|
|
28
|
-
* Path to the result image relative to the project root.
|
|
29
|
-
*/
|
|
30
|
-
resultPath: string
|
|
31
|
-
/**
|
|
32
|
-
* Path to the diff image relative to the project root.
|
|
33
|
-
*/
|
|
34
|
-
diffPath: string
|
|
35
|
-
/**
|
|
36
|
-
* Base64 encoded baseline image.
|
|
37
|
-
*/
|
|
38
|
-
baseline: string
|
|
39
|
-
/**
|
|
40
|
-
* Base64 encoded result image.
|
|
41
|
-
*/
|
|
42
|
-
result: string
|
|
43
|
-
/**
|
|
44
|
-
* Base64 encoded diff image.
|
|
45
|
-
*/
|
|
46
|
-
diff?: string | undefined
|
|
47
|
-
} & ImageSnapshotTimeoutOptions &
|
|
48
|
-
FailureThresholdOptions &
|
|
49
|
-
(SsimComparisonOptions | PixelComparisonOptions)
|
|
50
|
-
|
|
51
|
-
export interface PrepareImageSnapshotComparisonCommand {
|
|
52
|
-
prepareImageSnapshotComparison: (
|
|
53
|
-
taskId: string,
|
|
54
|
-
subject: string,
|
|
55
|
-
options?: MatchImageSnapshotOptions | undefined,
|
|
56
|
-
) => Promise<ImageSnapshotComparisonInfo | undefined>
|
|
57
|
-
}
|
|
58
12
|
|
|
59
13
|
export const prepareImageSnapshotComparison: ExtendedBrowserCommand<
|
|
60
14
|
Parameters<PrepareImageSnapshotComparisonCommand['prepareImageSnapshotComparison']>
|