vitest-plugin-vis 1.4.0 → 1.5.1
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/image_snapshot_matcher.d.ts.map +1 -1
- package/esm/client/image_snapshot_matcher.js +1 -0
- package/esm/client/image_snapshot_matcher.logic.d.ts.map +1 -1
- package/esm/client/image_snapshot_matcher.logic.js +3 -2
- package/esm/config/types.d.ts +10 -3
- package/esm/config/types.d.ts.map +1 -1
- package/esm/server/commands/match_image_snapshot.d.ts.map +1 -1
- package/esm/server/commands/match_image_snapshot.js +6 -7
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +2 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.js +2 -3
- package/esm/server/vis_context.ctx.d.ts.map +1 -1
- package/esm/server/vis_context.ctx.js +0 -1
- package/esm/server/vis_context.d.ts +14 -0
- package/esm/server/vis_context.d.ts.map +1 -1
- package/esm/server/vis_context.logic.d.ts +14 -0
- package/esm/server/vis_context.logic.d.ts.map +1 -1
- package/esm/server/vis_context.logic.js +3 -1
- package/esm/setup/create_vis.js +1 -1
- package/esm/shared/types.d.ts +12 -20
- package/esm/shared/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/readme.md +8 -5
- package/src/client/image_snapshot_matcher.logic.ts +3 -2
- package/src/client/image_snapshot_matcher.ts +3 -0
- package/src/config/types.ts +49 -35
- package/src/server/commands/match_image_snapshot.ts +6 -7
- package/src/server/commands/prepare_image_snapshot_comparison.ts +11 -4
- package/src/server/vis_context.ctx.ts +0 -1
- package/src/server/vis_context.logic.ts +7 -2
- package/src/setup/create_vis.ts +1 -1
- package/src/shared/types.ts +35 -40
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image_snapshot_matcher.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAA;AACpH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;
|
|
1
|
+
{"version":3,"file":"image_snapshot_matcher.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAA;AACpH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AAK3F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAO5F,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,qCAAqC,GAAG,yBAAyB,GAAG,6BAA6B,UAE5D,IAAI,WAAW,GAAG,YAAY,2BAA2B,CAAC,GAAG,CAAC,mBAgE7G;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
|
|
@@ -14,6 +14,7 @@ export function imageSnapshotMatcher(commands) {
|
|
|
14
14
|
const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options?.customizeSnapshotId ? await parseImageSnapshotOptions(commands, taskId, options) : options);
|
|
15
15
|
if (!info)
|
|
16
16
|
return;
|
|
17
|
+
options = { ...info, ...options };
|
|
17
18
|
const baselineImage = await toImageData(info.baseline);
|
|
18
19
|
const resultImage = await toImageData(info.result);
|
|
19
20
|
const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image_snapshot_matcher.logic.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAE5F,wBAAgB,eAAe,CAAC,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"image_snapshot_matcher.logic.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAE5F,wBAAgB,eAAe,CAAC,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,GAAG,SAAS,UAWpF"}
|
|
@@ -3,9 +3,10 @@ export function prettifyOptions(options) {
|
|
|
3
3
|
return 'none';
|
|
4
4
|
return [
|
|
5
5
|
`failureThreshold: ${options.failureThreshold ?? 0} ${options.failureThresholdType ?? 'pixels'}`,
|
|
6
|
-
options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
|
|
7
6
|
options.timeout ? `timeout: ${options.timeout} ms` : '',
|
|
7
|
+
`comparisonMethod: ${options.comparisonMethod ?? 'pixel'}`,
|
|
8
|
+
options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
|
|
8
9
|
]
|
|
9
10
|
.filter(Boolean)
|
|
10
|
-
.join('
|
|
11
|
+
.join('\n ');
|
|
11
12
|
}
|
package/esm/config/types.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ComparisonMethod } from '../shared/types.ts';
|
|
1
|
+
import type { ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../shared/types.ts';
|
|
3
2
|
export type { ComparisonMethod };
|
|
4
|
-
export type VisOptions<M extends ComparisonMethod = 'pixel'> =
|
|
3
|
+
export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & {
|
|
5
4
|
/**
|
|
6
5
|
* Loads the `test.setupFiles` of the specified preset.
|
|
7
6
|
*/
|
|
8
7
|
preset?: 'manual' | 'auto' | 'none' | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* The name of the subdirectory that the baseline snapshots get saved in.
|
|
10
|
+
*
|
|
11
|
+
* <snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png
|
|
12
|
+
*
|
|
13
|
+
* Default: undefined
|
|
14
|
+
*/
|
|
15
|
+
platform?: string | undefined;
|
|
9
16
|
/**
|
|
10
17
|
* The snapshot folder relative to the root of the project.
|
|
11
18
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,GACzF,sBAAsB,GACtB,2BAA2B,CAAC,CAAC,CAAC,GAAG;IAChC;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/match_image_snapshot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/match_image_snapshot.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAKjD,OAAO,KAAK,EACX,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAM9B,MAAM,WAAW,yBAAyB;IACzC,kBAAkB,EAAE,CACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,IAAI,CAAC,CAAA;CAClB;AAED,MAAM,MAAM,yBAAyB,GAAG,2BAA2B,GAClE,sBAAsB,GACtB,2BAA2B,CAAC,GAAG,CAAC,GAAG;IAClC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC,CAAA;AAEF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAC9C;IAAC,MAAM,EAAE,MAAM;IAAE,OAAO,EAAE,MAAM;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CAuElF,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import dedent from 'dedent';
|
|
2
|
-
import ci from 'is-ci';
|
|
3
2
|
import { resolve } from 'pathe';
|
|
4
3
|
import { PNG } from 'pngjs';
|
|
5
4
|
import { isBase64String } from "../../shared/base64.js";
|
|
@@ -15,7 +14,7 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
|
|
|
15
14
|
// vitest:browser passes in `null` when not defined
|
|
16
15
|
if (!options)
|
|
17
16
|
options = {};
|
|
18
|
-
options.timeout = options.timeout ??
|
|
17
|
+
options.timeout = options.timeout ?? 30000;
|
|
19
18
|
const info = visContext.getSnapshotInfo(context.testPath, taskId, options);
|
|
20
19
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
21
20
|
if (!baselineBuffer) {
|
|
@@ -42,8 +41,8 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
|
|
|
42
41
|
|
|
43
42
|
The image size changed form ${baselineImage.width}x${baselineImage.height} to ${resultImage.width}x${resultImage.height}
|
|
44
43
|
|
|
45
|
-
Expected: ${resolve(context.project.
|
|
46
|
-
Actual: ${resolve(context.project.
|
|
44
|
+
Expected: ${resolve(context.project.config.root, info.baselinePath)}
|
|
45
|
+
Actual: ${resolve(context.project.config.root, info.resultPath)}`);
|
|
47
46
|
}
|
|
48
47
|
if (context.project.config.snapshotOptions.updateSnapshot === 'all') {
|
|
49
48
|
await writeSnapshotBuffer(info.baselinePath, resultImage.data);
|
|
@@ -60,9 +59,9 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
|
|
|
60
59
|
|
|
61
60
|
Options: ${JSON.stringify(options)}
|
|
62
61
|
|
|
63
|
-
Expected: ${resolve(context.project.
|
|
64
|
-
Actual: ${resolve(context.project.
|
|
65
|
-
Difference: ${resolve(context.project.
|
|
62
|
+
Expected: ${resolve(context.project.config.root, info.baselinePath)}
|
|
63
|
+
Actual: ${resolve(context.project.config.root, info.resultPath)}
|
|
64
|
+
Difference: ${resolve(context.project.config.root, info.diffPath)}`);
|
|
66
65
|
};
|
|
67
66
|
function alignImageSizes(baseline, result) {
|
|
68
67
|
if (isSameSize(baseline, result))
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BrowserCommand } from 'vitest/node';
|
|
2
|
+
import type { FailureThresholdOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions } from '../../shared/types.ts';
|
|
2
3
|
import type { MatchImageSnapshotOptions } from './match_image_snapshot.ts';
|
|
3
4
|
type ImageSnapshotComparisonInfo = {
|
|
4
5
|
projectRoot: string;
|
|
@@ -7,7 +8,7 @@ type ImageSnapshotComparisonInfo = {
|
|
|
7
8
|
diffPath: string;
|
|
8
9
|
baseline: string;
|
|
9
10
|
result: string;
|
|
10
|
-
};
|
|
11
|
+
} & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions);
|
|
11
12
|
export interface PrepareImageSnapshotComparisonCommand {
|
|
12
13
|
prepareImageSnapshotComparison: (taskId: string | undefined, subject: string, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo | undefined>;
|
|
13
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepare_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAE1E,KAAK,2BAA2B,GAAG;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACd,GAAG,2BAA2B,GAC9B,uBAAuB,GACvB,CAAC,qBAAqB,GAAG,sBAAsB,CAAC,CAAA;AAEjD,MAAM,WAAW,qCAAqC;IACrD,8BAA8B,EAAE,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAAA;CACrD;AAED,eAAO,MAAM,8BAA8B,EAAE,cAAc,CAC1D;IAAC,MAAM,EAAE,MAAM;IAAE,UAAU,EAAE,MAAM;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CA0BrF,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import ci from 'is-ci';
|
|
2
1
|
import { isBase64String } from "../../shared/base64.js";
|
|
3
2
|
import { file } from "../file.js";
|
|
4
3
|
import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from "../snapshot.js";
|
|
@@ -9,7 +8,7 @@ export const prepareImageSnapshotComparison = async (context, taskId, subject, o
|
|
|
9
8
|
// vitest:browser passes in `null` when not defined
|
|
10
9
|
if (!options)
|
|
11
10
|
options = {};
|
|
12
|
-
options.timeout = options.timeout ??
|
|
11
|
+
options.timeout = options.timeout ?? 30000;
|
|
13
12
|
const info = visContext.getSnapshotInfo(context.testPath, taskId, options);
|
|
14
13
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
15
14
|
if (!baselineBuffer) {
|
|
@@ -24,7 +23,7 @@ export const prepareImageSnapshotComparison = async (context, taskId, subject, o
|
|
|
24
23
|
const resultBuffer = await takeSnapshot(context, info.resultPath, subject, options);
|
|
25
24
|
return {
|
|
26
25
|
...info,
|
|
27
|
-
projectRoot: context.project.
|
|
26
|
+
projectRoot: context.project.config.root,
|
|
28
27
|
baseline: baselineBuffer.toString('base64'),
|
|
29
28
|
result: resultBuffer.toString('base64'),
|
|
30
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vis_context.ctx.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ctx.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,GAAG;;
|
|
1
|
+
{"version":3,"file":"vis_context.ctx.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ctx.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,GAAG;;6CAOksD,CAAC;2CAAkF,CAAC;iDAA8E,CAAC;8CAA2E,CAAC;+CAA0F,CAAC;;iDAAqF,CAAC;8CAA2E,CAAC;+CAA0F,CAAC;;iDAAqF,CAAC;6CAA0E,CAAC;+CAA0F,CAAC;;gDAAoF,CAAC;+CAA4E,CAAC;+CAA0F,CAAC;;kDAAsF,CAAC;kDAA+E,CAAC;+CAA0F,CAAC;;qDAAyF,CAAC;;;CAF7mG,CAAA"}
|
|
@@ -10,6 +10,20 @@ export declare const visContext: {
|
|
|
10
10
|
baselinePath: string;
|
|
11
11
|
resultPath: string;
|
|
12
12
|
diffPath: string;
|
|
13
|
+
timeout?: number | undefined | undefined;
|
|
14
|
+
comparisonMethod: any;
|
|
15
|
+
diffOptions?: Partial<import("ssim.js").Options> | undefined;
|
|
16
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
17
|
+
failureThreshold?: number | undefined | undefined;
|
|
18
|
+
} | {
|
|
19
|
+
baselinePath: string;
|
|
20
|
+
resultPath: string;
|
|
21
|
+
diffPath: string;
|
|
22
|
+
timeout?: number | undefined | undefined;
|
|
23
|
+
comparisonMethod?: any;
|
|
24
|
+
diffOptions?: import("pixelmatch").PixelmatchOptions | undefined;
|
|
25
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
26
|
+
failureThreshold?: number | undefined | undefined;
|
|
13
27
|
};
|
|
14
28
|
getTaskCount(testPath: string, taskId: string): number;
|
|
15
29
|
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;
|
|
1
|
+
{"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBAC2mD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADvlD,CAAA"}
|
|
@@ -30,6 +30,20 @@ export declare function createVisContext(): {
|
|
|
30
30
|
baselinePath: string;
|
|
31
31
|
resultPath: string;
|
|
32
32
|
diffPath: string;
|
|
33
|
+
timeout?: number | undefined | undefined;
|
|
34
|
+
comparisonMethod: any;
|
|
35
|
+
diffOptions?: Partial<import("ssim.js").Options> | undefined;
|
|
36
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
37
|
+
failureThreshold?: number | undefined | undefined;
|
|
38
|
+
} | {
|
|
39
|
+
baselinePath: string;
|
|
40
|
+
resultPath: string;
|
|
41
|
+
diffPath: string;
|
|
42
|
+
timeout?: number | undefined | undefined;
|
|
43
|
+
comparisonMethod?: any;
|
|
44
|
+
diffOptions?: import("pixelmatch").PixelmatchOptions | undefined;
|
|
45
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
46
|
+
failureThreshold?: number | undefined | undefined;
|
|
33
47
|
};
|
|
34
48
|
getTaskCount(testPath: string, taskId: string): number;
|
|
35
49
|
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vis_context.logic.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.logic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vis_context.logic.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.logic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAKpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEtD,MAAM,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE;QACR,MAAM,EAAE;YACP,IAAI,EAAE,MAAM,CAAA;YACZ,eAAe,EAAE;gBAChB,cAAc,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;aACtC,CAAA;YACD,WAAW,EAAE,MAAM,CAAA;YACnB,WAAW,EAAE,MAAM,CAAA;SACnB,CAAA;KACD,CAAA;IACD,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,gBAAgB;eAMnB,CAAC,SAAS,OAAO,GAAG,MAAM,YAAW,UAAU,CAAC,CAAC,CAAC;;;;IAY7D;;;;OAIG;wBACuB,4BAA4B;8BAY5B,MAAM,QAAQ,MAAM,YAAY;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;2BAkB1E,MAAM,UAAU,MAAM;+BAGlB,MAAM,UAAU,MAAM,kBAAkB,MAAM,GAAG,SAAS;8BAI3D;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBAAkB,MAAM,GAAG,SAAS;2BAMlF,MAAM,UAAU,MAAM;;;;;;;;;;EAe9C;AA0BD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC;;;;;;;;EAWnH;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC,UAElH"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join, relative } from 'pathe';
|
|
2
|
+
import { pick } from 'type-plus';
|
|
2
3
|
import { DIFF_DIR, RESULT_DIR } from "../shared/constants.js";
|
|
3
4
|
import { file } from "./file.js";
|
|
4
5
|
import { getSnapshotSubpath, resolveSnapshotRootDir } from "./snapshot_path.js";
|
|
@@ -46,6 +47,7 @@ export function createVisContext() {
|
|
|
46
47
|
const resultPath = join(resultDir, snapshotFilename);
|
|
47
48
|
const diffPath = join(diffDir, snapshotFilename);
|
|
48
49
|
return {
|
|
50
|
+
...pick(visOptions, 'comparisonMethod', 'diffOptions', 'failureThreshold', 'failureThresholdType', 'timeout'),
|
|
49
51
|
baselinePath,
|
|
50
52
|
resultPath,
|
|
51
53
|
diffPath,
|
|
@@ -83,7 +85,7 @@ export function createVisContext() {
|
|
|
83
85
|
async function setupState(suite, visOptions) {
|
|
84
86
|
const snapshotRootDir = resolveSnapshotRootDir(visOptions);
|
|
85
87
|
const projectPath = suite.project.config.root;
|
|
86
|
-
const platform = ctx.getSnapshotPlatform();
|
|
88
|
+
const platform = visOptions.platform ?? ctx.getSnapshotPlatform();
|
|
87
89
|
const state = {
|
|
88
90
|
projectPath,
|
|
89
91
|
platform,
|
package/esm/setup/create_vis.js
CHANGED
package/esm/shared/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface ImageSnapshotTimeoutOptions {
|
|
|
4
4
|
/**
|
|
5
5
|
* Timeout for taking the snapshot.
|
|
6
6
|
*
|
|
7
|
-
* Default:
|
|
7
|
+
* Default: 30000 ms (30 seconds)
|
|
8
8
|
*/
|
|
9
9
|
timeout?: number | undefined;
|
|
10
10
|
}
|
|
@@ -18,12 +18,7 @@ export interface ImageSnapshotIdOptions {
|
|
|
18
18
|
customizeSnapshotId?: (id: string, index: number) => string;
|
|
19
19
|
}
|
|
20
20
|
export type ComparisonMethod = 'pixel' | 'ssim';
|
|
21
|
-
export type
|
|
22
|
-
comparisonMethod: M;
|
|
23
|
-
/**
|
|
24
|
-
* Custom options passed to 'ssim'
|
|
25
|
-
*/
|
|
26
|
-
diffOptions?: Partial<SsimOptions> | undefined;
|
|
21
|
+
export type FailureThresholdOptions = {
|
|
27
22
|
/**
|
|
28
23
|
* Failure threshold should measure in `pixel` or `percent`.
|
|
29
24
|
*
|
|
@@ -36,23 +31,20 @@ export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> =
|
|
|
36
31
|
* Default is `0`.
|
|
37
32
|
*/
|
|
38
33
|
failureThreshold?: number | undefined;
|
|
39
|
-
}
|
|
34
|
+
};
|
|
35
|
+
export type SsimComparisonOptions<M = 'ssim'> = {
|
|
36
|
+
comparisonMethod: M;
|
|
37
|
+
/**
|
|
38
|
+
* Custom options passed to 'ssim'
|
|
39
|
+
*/
|
|
40
|
+
diffOptions?: Partial<SsimOptions> | undefined;
|
|
41
|
+
};
|
|
42
|
+
export type PixelComparisonOptions<M = 'pixel'> = {
|
|
40
43
|
comparisonMethod?: M | undefined;
|
|
41
44
|
/**
|
|
42
45
|
* Custom options passed to 'pixelmatch'
|
|
43
46
|
*/
|
|
44
47
|
diffOptions?: PixelmatchOptions | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* Failure threshold should measure in `pixel` or `percent`.
|
|
47
|
-
*
|
|
48
|
-
* Default is `pixel`.
|
|
49
|
-
*/
|
|
50
|
-
failureThresholdType?: 'pixel' | 'percent' | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Failure tolerance threshold.
|
|
53
|
-
*
|
|
54
|
-
* Default is `0`.
|
|
55
|
-
*/
|
|
56
|
-
failureThreshold?: number | undefined;
|
|
57
48
|
};
|
|
49
|
+
export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions;
|
|
58
50
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;AAErD,MAAM,WAAW,2BAA2B;IAC3C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACtC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CAC3D;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAA;AAE/C,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;AAErD,MAAM,WAAW,2BAA2B;IAC3C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACtC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CAC3D;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAA;AAE/C,MAAM,MAAM,uBAAuB,GAAG;IACrC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAA;IACtD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,MAAM,IAAI;IAC/C,gBAAgB,EAAE,CAAC,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;CAC9C,CAAA;AACD,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAAI;IACjD,gBAAgB,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAA;CAC3C,CAAA;AAED,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,CAAC,CAAC,SAAS,MAAM,GAC9F,qBAAqB,CAAC,CAAC,CAAC,GACxB,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAC5B,uBAAuB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-plugin-vis",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Vitest visual testing plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image-snapshot",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"./package.json": "./package.json"
|
|
56
56
|
},
|
|
57
|
+
"types": "./esm/index.d.ts",
|
|
57
58
|
"files": [
|
|
58
59
|
"esm",
|
|
59
60
|
"src",
|
package/readme.md
CHANGED
|
@@ -60,14 +60,16 @@ export default defineConfig({
|
|
|
60
60
|
plugins: [
|
|
61
61
|
vis({
|
|
62
62
|
preset: 'auto',
|
|
63
|
-
comparisonMethod: 'pixel',
|
|
64
63
|
snapshotRootDir: '__vis__',
|
|
64
|
+
platform: '...', // {process.platform} or `local`
|
|
65
65
|
customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
|
|
66
66
|
customizeSnapshotId: (id, index) => `${id}-${index}`,
|
|
67
|
-
|
|
67
|
+
comparisonMethod: 'pixel',
|
|
68
|
+
// pixelmatch or ssim.js options, depending on `comparisonMethod`.
|
|
69
|
+
diffOptions: undefined,
|
|
68
70
|
failureThresholdType: 'pixel',
|
|
69
71
|
failureThreshold: 0,
|
|
70
|
-
timeout:
|
|
72
|
+
timeout: 30000
|
|
71
73
|
})
|
|
72
74
|
],
|
|
73
75
|
test:{
|
|
@@ -189,7 +191,7 @@ setAutoSnapshotOptions({
|
|
|
189
191
|
diffOptions: { threshold: 0.01 },
|
|
190
192
|
failureThreshold: 0.01,
|
|
191
193
|
failureThresholdType: 'percent',
|
|
192
|
-
timeout:
|
|
194
|
+
timeout: 60000
|
|
193
195
|
})
|
|
194
196
|
```
|
|
195
197
|
|
|
@@ -242,7 +244,7 @@ it('manual snapshot with options', async () => {
|
|
|
242
244
|
diffOptions: {
|
|
243
245
|
threshold: 0.1
|
|
244
246
|
},
|
|
245
|
-
timeout:
|
|
247
|
+
timeout: 60000
|
|
246
248
|
})
|
|
247
249
|
})
|
|
248
250
|
```
|
|
@@ -286,6 +288,7 @@ Please follow its guide to set up your environment.
|
|
|
286
288
|
|
|
287
289
|
Bonus note, if you want to install [Firefox] on WSL,
|
|
288
290
|
you can follow these steps: [Install Firefox on Ubuntu 22.04](https://askubuntu.com/a/1444967).
|
|
291
|
+
Also, you may need to `sudo apt-get install xdg-utils` to fix [`xdg-settings: not found`](https://serverfault.com/questions/1091926/running-chrome-on-ubuntu-server-how-to-solve-xdg-settings-not-found-using).
|
|
289
292
|
|
|
290
293
|
## Running on CI
|
|
291
294
|
|
|
@@ -5,9 +5,10 @@ export function prettifyOptions(options: ToMatchImageSnapshotOptions<any> | unde
|
|
|
5
5
|
|
|
6
6
|
return [
|
|
7
7
|
`failureThreshold: ${options.failureThreshold ?? 0} ${options.failureThresholdType ?? 'pixels'}`,
|
|
8
|
-
options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
|
|
9
8
|
options.timeout ? `timeout: ${options.timeout} ms` : '',
|
|
9
|
+
`comparisonMethod: ${options.comparisonMethod ?? 'pixel'}`,
|
|
10
|
+
options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
|
|
10
11
|
]
|
|
11
12
|
.filter(Boolean)
|
|
12
|
-
.join('
|
|
13
|
+
.join('\n ')
|
|
13
14
|
}
|
|
@@ -6,6 +6,7 @@ import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/p
|
|
|
6
6
|
import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts'
|
|
7
7
|
import { isBase64String } from '../shared/base64.ts'
|
|
8
8
|
import { compareImage } from '../shared/compare_image.ts'
|
|
9
|
+
import type { ComparisonMethod } from '../shared/types.ts'
|
|
9
10
|
import { alignImagesToSameSize } from './align_images.ts'
|
|
10
11
|
import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts'
|
|
11
12
|
import { toDataURL, toImageData } from './image_data.ts'
|
|
@@ -27,6 +28,8 @@ export function imageSnapshotMatcher(
|
|
|
27
28
|
|
|
28
29
|
if (!info) return
|
|
29
30
|
|
|
31
|
+
options = { ...info, ...options } as any
|
|
32
|
+
|
|
30
33
|
const baselineImage = await toImageData(info.baseline)
|
|
31
34
|
const resultImage = await toImageData(info.result)
|
|
32
35
|
const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage)
|
package/src/config/types.ts
CHANGED
|
@@ -1,38 +1,52 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ComparisonMethod,
|
|
3
|
+
ImageSnapshotCompareOptions,
|
|
4
|
+
ImageSnapshotIdOptions,
|
|
5
|
+
ImageSnapshotTimeoutOptions,
|
|
6
|
+
} from '../shared/types.ts'
|
|
3
7
|
|
|
4
8
|
export type { ComparisonMethod }
|
|
5
9
|
|
|
6
|
-
export type VisOptions<M extends ComparisonMethod = 'pixel'> =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
10
|
+
export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions &
|
|
11
|
+
ImageSnapshotIdOptions &
|
|
12
|
+
ImageSnapshotCompareOptions<M> & {
|
|
13
|
+
/**
|
|
14
|
+
* Loads the `test.setupFiles` of the specified preset.
|
|
15
|
+
*/
|
|
16
|
+
preset?: 'manual' | 'auto' | 'none' | undefined
|
|
17
|
+
/**
|
|
18
|
+
* The name of the subdirectory that the baseline snapshots get saved in.
|
|
19
|
+
*
|
|
20
|
+
* <snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png
|
|
21
|
+
*
|
|
22
|
+
* Default: undefined
|
|
23
|
+
*/
|
|
24
|
+
platform?: string | undefined
|
|
25
|
+
/**
|
|
26
|
+
* The snapshot folder relative to the root of the project.
|
|
27
|
+
*
|
|
28
|
+
* Default: `__vis__`
|
|
29
|
+
*/
|
|
30
|
+
snapshotRootDir?: string | undefined
|
|
31
|
+
/**
|
|
32
|
+
* Customize the snapshot subpath.
|
|
33
|
+
*
|
|
34
|
+
* The snapshot subpath is used along with `snapshotRootDir` to determine the folder of the snapshots:
|
|
35
|
+
*
|
|
36
|
+
* - baseline: `<snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png`
|
|
37
|
+
* - result: `<snapshotRootDir>/__results__/<snapshotSubpath>/<snapshotId>.png`
|
|
38
|
+
* - diff: `<snapshotRootDir>/__diffs__/<snapshotSubpath>/<snapshotId>.png`
|
|
39
|
+
*
|
|
40
|
+
* Typically, you place your test files either in a dedicated `tests` folder or in the `src` folder along with your source code.
|
|
41
|
+
* By default, the snapshot subpath is the test file path with that folder removed to reduces nesting of the snapshot folders.
|
|
42
|
+
*
|
|
43
|
+
* If you place your test files in multiple folders,
|
|
44
|
+
* such as in both `tests` and `src` folders,
|
|
45
|
+
* and they might have files with the same name and create conflicting snapshots,
|
|
46
|
+
* you can set this to customize the snapshot subpath.
|
|
47
|
+
*
|
|
48
|
+
* @param subPath - The path of the test file to be used as the snapshot sub path.
|
|
49
|
+
* If you want to keep the full path, you can simply return it.
|
|
50
|
+
*/
|
|
51
|
+
customizeSnapshotSubpath?: (subPath: string) => string
|
|
52
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import dedent from 'dedent'
|
|
2
|
-
import ci from 'is-ci'
|
|
3
2
|
import { resolve } from 'pathe'
|
|
4
3
|
import { PNG } from 'pngjs'
|
|
5
4
|
import type { BrowserCommand } from 'vitest/node'
|
|
@@ -41,7 +40,7 @@ export const matchImageSnapshot: BrowserCommand<
|
|
|
41
40
|
|
|
42
41
|
// vitest:browser passes in `null` when not defined
|
|
43
42
|
if (!options) options = {}
|
|
44
|
-
options.timeout = options.timeout ??
|
|
43
|
+
options.timeout = options.timeout ?? 30000
|
|
45
44
|
|
|
46
45
|
const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
|
|
47
46
|
const baselineBuffer = await file.tryReadFile(info.baselinePath)
|
|
@@ -77,8 +76,8 @@ export const matchImageSnapshot: BrowserCommand<
|
|
|
77
76
|
|
|
78
77
|
The image size changed form ${baselineImage.width}x${baselineImage.height} to ${resultImage.width}x${resultImage.height}
|
|
79
78
|
|
|
80
|
-
Expected: ${resolve(context.project.
|
|
81
|
-
Actual: ${resolve(context.project.
|
|
79
|
+
Expected: ${resolve(context.project.config.root, info.baselinePath)}
|
|
80
|
+
Actual: ${resolve(context.project.config.root, info.resultPath)}`,
|
|
82
81
|
)
|
|
83
82
|
}
|
|
84
83
|
|
|
@@ -102,9 +101,9 @@ export const matchImageSnapshot: BrowserCommand<
|
|
|
102
101
|
|
|
103
102
|
Options: ${JSON.stringify(options)}
|
|
104
103
|
|
|
105
|
-
Expected: ${resolve(context.project.
|
|
106
|
-
Actual: ${resolve(context.project.
|
|
107
|
-
Difference: ${resolve(context.project.
|
|
104
|
+
Expected: ${resolve(context.project.config.root, info.baselinePath)}
|
|
105
|
+
Actual: ${resolve(context.project.config.root, info.resultPath)}
|
|
106
|
+
Difference: ${resolve(context.project.config.root, info.diffPath)}`,
|
|
108
107
|
)
|
|
109
108
|
}
|
|
110
109
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import ci from 'is-ci'
|
|
2
1
|
import type { BrowserCommand } from 'vitest/node'
|
|
3
2
|
import { isBase64String } from '../../shared/base64.ts'
|
|
3
|
+
import type {
|
|
4
|
+
FailureThresholdOptions,
|
|
5
|
+
ImageSnapshotTimeoutOptions,
|
|
6
|
+
PixelComparisonOptions,
|
|
7
|
+
SsimComparisonOptions,
|
|
8
|
+
} from '../../shared/types.ts'
|
|
4
9
|
import { file } from '../file.ts'
|
|
5
10
|
import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from '../snapshot.ts'
|
|
6
11
|
import { visContext } from '../vis_context.ts'
|
|
@@ -14,7 +19,9 @@ type ImageSnapshotComparisonInfo = {
|
|
|
14
19
|
diffPath: string
|
|
15
20
|
baseline: string
|
|
16
21
|
result: string
|
|
17
|
-
}
|
|
22
|
+
} & ImageSnapshotTimeoutOptions &
|
|
23
|
+
FailureThresholdOptions &
|
|
24
|
+
(SsimComparisonOptions | PixelComparisonOptions)
|
|
18
25
|
|
|
19
26
|
export interface PrepareImageSnapshotComparisonCommand {
|
|
20
27
|
prepareImageSnapshotComparison: (
|
|
@@ -31,7 +38,7 @@ export const prepareImageSnapshotComparison: BrowserCommand<
|
|
|
31
38
|
|
|
32
39
|
// vitest:browser passes in `null` when not defined
|
|
33
40
|
if (!options) options = {}
|
|
34
|
-
options.timeout = options.timeout ??
|
|
41
|
+
options.timeout = options.timeout ?? 30000
|
|
35
42
|
|
|
36
43
|
const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
|
|
37
44
|
const baselineBuffer = await file.tryReadFile(info.baselinePath)
|
|
@@ -47,7 +54,7 @@ export const prepareImageSnapshotComparison: BrowserCommand<
|
|
|
47
54
|
const resultBuffer = await takeSnapshot(context, info.resultPath, subject, options)
|
|
48
55
|
return {
|
|
49
56
|
...info,
|
|
50
|
-
projectRoot: context.project.
|
|
57
|
+
projectRoot: context.project.config.root,
|
|
51
58
|
baseline: baselineBuffer.toString('base64'),
|
|
52
59
|
result: resultBuffer.toString('base64'),
|
|
53
60
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join, relative } from 'pathe'
|
|
2
|
+
import { pick } from 'type-plus'
|
|
2
3
|
import type { VisOptions } from '../config/types.ts'
|
|
3
4
|
import { DIFF_DIR, RESULT_DIR } from '../shared/constants.ts'
|
|
4
5
|
import { file } from './file.ts'
|
|
@@ -67,6 +68,7 @@ export function createVisContext() {
|
|
|
67
68
|
const diffPath = join(diffDir, snapshotFilename)
|
|
68
69
|
|
|
69
70
|
return {
|
|
71
|
+
...pick(visOptions, 'comparisonMethod', 'diffOptions', 'failureThreshold', 'failureThresholdType', 'timeout'),
|
|
70
72
|
baselinePath,
|
|
71
73
|
resultPath,
|
|
72
74
|
diffPath,
|
|
@@ -102,10 +104,13 @@ export function createVisContext() {
|
|
|
102
104
|
return context
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
async function setupState(
|
|
107
|
+
async function setupState(
|
|
108
|
+
suite: PartialBrowserCommandContext,
|
|
109
|
+
visOptions: Pick<VisOptions, 'snapshotRootDir' | 'platform'>,
|
|
110
|
+
) {
|
|
106
111
|
const snapshotRootDir = resolveSnapshotRootDir(visOptions)
|
|
107
112
|
const projectPath = suite.project.config.root
|
|
108
|
-
const platform = ctx.getSnapshotPlatform()
|
|
113
|
+
const platform = visOptions.platform ?? ctx.getSnapshotPlatform()
|
|
109
114
|
|
|
110
115
|
const state = {
|
|
111
116
|
projectPath,
|
package/src/setup/create_vis.ts
CHANGED
package/src/shared/types.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface ImageSnapshotTimeoutOptions {
|
|
|
5
5
|
/**
|
|
6
6
|
* Timeout for taking the snapshot.
|
|
7
7
|
*
|
|
8
|
-
* Default:
|
|
8
|
+
* Default: 30000 ms (30 seconds)
|
|
9
9
|
*/
|
|
10
10
|
timeout?: number | undefined
|
|
11
11
|
}
|
|
@@ -22,42 +22,37 @@ export interface ImageSnapshotIdOptions {
|
|
|
22
22
|
|
|
23
23
|
export type ComparisonMethod = 'pixel' | 'ssim'
|
|
24
24
|
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
* Default is `0`.
|
|
61
|
-
*/
|
|
62
|
-
failureThreshold?: number | undefined
|
|
63
|
-
}
|
|
25
|
+
export type FailureThresholdOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* Failure threshold should measure in `pixel` or `percent`.
|
|
28
|
+
*
|
|
29
|
+
* Default is `pixel`.
|
|
30
|
+
*/
|
|
31
|
+
failureThresholdType?: 'pixel' | 'percent' | undefined
|
|
32
|
+
/**
|
|
33
|
+
* Failure tolerance threshold.
|
|
34
|
+
*
|
|
35
|
+
* Default is `0`.
|
|
36
|
+
*/
|
|
37
|
+
failureThreshold?: number | undefined
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type SsimComparisonOptions<M = 'ssim'> = {
|
|
41
|
+
comparisonMethod: M
|
|
42
|
+
/**
|
|
43
|
+
* Custom options passed to 'ssim'
|
|
44
|
+
*/
|
|
45
|
+
diffOptions?: Partial<SsimOptions> | undefined
|
|
46
|
+
}
|
|
47
|
+
export type PixelComparisonOptions<M = 'pixel'> = {
|
|
48
|
+
comparisonMethod?: M | undefined
|
|
49
|
+
/**
|
|
50
|
+
* Custom options passed to 'pixelmatch'
|
|
51
|
+
*/
|
|
52
|
+
diffOptions?: PixelmatchOptions | undefined
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim'
|
|
56
|
+
? SsimComparisonOptions<M>
|
|
57
|
+
: PixelComparisonOptions<M>) &
|
|
58
|
+
FailureThresholdOptions
|