vitest-plugin-vis 2.3.0 → 2.3.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/ctx.d.ts +1 -1
- package/esm/client/image_snapshot_matcher.d.ts +2 -1
- package/esm/client/image_snapshot_matcher.d.ts.map +1 -1
- package/esm/client/image_snapshot_matcher.js +2 -1
- package/esm/client/page/has_image_snapshot.d.ts.map +1 -1
- package/esm/client/page/has_image_snapshot.js +3 -2
- package/esm/client/vitest_suite_proxy.d.ts +11 -1
- package/esm/client/vitest_suite_proxy.d.ts.map +1 -1
- package/esm/config/vis.d.ts +3 -3
- package/esm/server/commands/extend.d.ts +3 -3
- package/esm/server/commands/has_image_snapshot.d.ts +6 -2
- package/esm/server/commands/has_image_snapshot.d.ts.map +1 -1
- package/esm/server/commands/has_image_snapshot.js +2 -2
- package/esm/server/commands/match_image_snapshot.d.ts +2 -1
- package/esm/server/commands/match_image_snapshot.d.ts.map +1 -1
- package/esm/server/commands/match_image_snapshot.js +2 -2
- 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 -2
- package/esm/server/vis_context.d.ts +3 -3
- package/esm/server/vis_context.d.ts.map +1 -1
- package/esm/server/vis_context.logic.d.ts +3 -3
- package/esm/server/vis_context.logic.d.ts.map +1 -1
- package/esm/server/vis_context.logic.js +7 -10
- package/esm/shared/types.d.ts +0 -9
- package/esm/shared/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/image_snapshot_matcher.ts +4 -1
- package/src/client/page/has_image_snapshot.ts +4 -2
- package/src/client/vitest_suite_proxy.ts +6 -1
- package/src/server/commands/has_image_snapshot.ts +5 -7
- package/src/server/commands/match_image_snapshot.ts +4 -3
- package/src/server/commands/prepare_image_snapshot_comparison.ts +4 -3
- package/src/server/vis_context.logic.ts +17 -11
- package/src/shared/types.ts +0 -4
package/esm/client/ctx.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const ctx: {
|
|
2
2
|
autoEnabled: boolean | undefined;
|
|
3
|
-
getCurrentTest: () => import("
|
|
3
|
+
getCurrentTest: () => import("./vitest_suite_proxy.ts").CurrentTest;
|
|
4
4
|
getCurrentSuite: () => import("vitest").SuiteCollector<object>;
|
|
5
5
|
__test__reset(): void;
|
|
6
6
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ImageSnapshotNextIndexCommand } from '../commands.ts';
|
|
2
2
|
import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts';
|
|
3
3
|
import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ToMatchImageSnapshotOptions } from '../shared/types.ts';
|
|
5
|
+
import type { CurrentTest } from './vitest_suite_proxy.ts';
|
|
5
6
|
export declare function imageSnapshotMatcher(commands: PrepareImageSnapshotComparisonCommand & WriteImageSnapshotCommand & ImageSnapshotNextIndexCommand): (test: CurrentTest & {}, subject: any, options?: ToMatchImageSnapshotOptions<any>) => Promise<void>;
|
|
6
7
|
/**
|
|
7
8
|
* @deprecated internalized. Use `matchImageSnapshot` directly instead.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image_snapshot_matcher.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image_snapshot_matcher.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.ts"],"names":[],"mappings":"AAGA,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;AAG3F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAOrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,qCAAqC,GAAG,yBAAyB,GAAG,6BAA6B,UAGpG,WAAW,GAAG,EAAE,WACb,GAAG,YACF,2BAA2B,CAAC,GAAG,CAAC,mBAqE3C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isA } from '@vitest/expect';
|
|
1
2
|
import dedent from 'dedent';
|
|
2
3
|
import { resolve } from 'pathe';
|
|
3
4
|
import { isBase64String } from "../shared/base64.js";
|
|
@@ -12,7 +13,7 @@ export function imageSnapshotMatcher(commands) {
|
|
|
12
13
|
return async function matchImageSnapshot(test, subject, options) {
|
|
13
14
|
const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot;
|
|
14
15
|
const taskId = toTaskId(test);
|
|
15
|
-
const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options?.customizeSnapshotId
|
|
16
|
+
const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), isAutoSnapshot, options?.customizeSnapshotId
|
|
16
17
|
? await parseImageSnapshotOptions(commands, taskId, isAutoSnapshot, options)
|
|
17
18
|
: options);
|
|
18
19
|
if (!info)
|
|
@@ -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,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAInE,MAAM,WAAW,sBAAsB;IACtC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACnG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,
|
|
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,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAInE,MAAM,WAAW,sBAAsB;IACtC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACnG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,oBA2B/F"}
|
|
@@ -14,10 +14,11 @@ export function hasImageSnapshot(options) {
|
|
|
14
14
|
"concurrent tests run at the same time in the same iframe and affect each other's environment. ");
|
|
15
15
|
}
|
|
16
16
|
const taskId = toTaskId(test);
|
|
17
|
+
const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot;
|
|
17
18
|
if (options?.customizeSnapshotId) {
|
|
18
19
|
return commands
|
|
19
20
|
.imageSnapshotNextIndex(taskId)
|
|
20
|
-
.then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot
|
|
21
|
+
.then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot }), isAutoSnapshot));
|
|
21
22
|
}
|
|
22
|
-
return commands.hasImageSnapshot(taskId);
|
|
23
|
+
return commands.hasImageSnapshot(taskId, undefined, isAutoSnapshot);
|
|
23
24
|
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NAME } from '../shared/constants.ts';
|
|
2
|
+
import type { SnapshotMeta } from '../shared/types.ts';
|
|
3
|
+
declare let vitestSuite: Awaited<typeof import('vitest/suite')>;
|
|
4
|
+
export type CurrentTest = ReturnType<typeof vitestSuite.getCurrentTest> & {
|
|
5
|
+
meta: {
|
|
6
|
+
[NAME]?: SnapshotMeta<'pixel' | 'ssim'> & {
|
|
7
|
+
isAutoSnapshot?: boolean | undefined;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
2
11
|
export declare const getCurrentTest: () => CurrentTest;
|
|
3
12
|
export declare const getCurrentSuite: () => import("vitest").SuiteCollector<object>;
|
|
13
|
+
export {};
|
|
4
14
|
//# sourceMappingURL=vitest_suite_proxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,QAAA,IAAI,WAAW,EAAE,OAAO,CAAC,cAAc,cAAc,CAAC,CAAC,CAAA;AAQvD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,cAAc,CAAC,GAAG;IACzE,IAAI,EAAE;QAAE,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,GAAG;YAAE,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;SAAE,CAAA;KAAE,CAAA;CAC5F,CAAA;AAED,eAAO,MAAM,cAAc,QAA0C,WAAW,CAAA;AAChF,eAAO,MAAM,eAAe,+CAAuC,CAAA"}
|
package/esm/config/vis.d.ts
CHANGED
|
@@ -15,9 +15,9 @@ export declare function vis<M extends ComparisonMethod = 'pixel'>(options?: VisO
|
|
|
15
15
|
commands: {
|
|
16
16
|
setupVisSuite: import("vitest/node").BrowserCommand<[]>;
|
|
17
17
|
imageSnapshotNextIndex: import("vitest/node").BrowserCommand<[taskId: string]>;
|
|
18
|
-
hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId
|
|
19
|
-
matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
|
|
20
|
-
prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
|
|
18
|
+
hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean]>;
|
|
19
|
+
matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, isAutoSnapshot: boolean, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
|
|
20
|
+
prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, isAutoSnapshot: boolean, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
|
|
21
21
|
writeImageSnapshot: import("vitest/node").BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
|
|
22
22
|
};
|
|
23
23
|
};
|
|
@@ -11,9 +11,9 @@ declare module '@vitest/browser/context' {
|
|
|
11
11
|
export declare const commands: {
|
|
12
12
|
setupVisSuite: import("vitest/node").BrowserCommand<[]>;
|
|
13
13
|
imageSnapshotNextIndex: import("vitest/node").BrowserCommand<[taskId: string]>;
|
|
14
|
-
hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId
|
|
15
|
-
matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
|
|
16
|
-
prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
|
|
14
|
+
hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean]>;
|
|
15
|
+
matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, isAutoSnapshot: boolean, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
|
|
16
|
+
prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, isAutoSnapshot: boolean, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
|
|
17
17
|
writeImageSnapshot: import("vitest/node").BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
|
|
18
18
|
};
|
|
19
19
|
//# sourceMappingURL=extend.d.ts.map
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { BrowserCommand } from 'vitest/node';
|
|
2
2
|
export interface HasImageSnapshotCommand {
|
|
3
|
-
hasImageSnapshot(taskId: string, snapshotId
|
|
3
|
+
hasImageSnapshot(taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>;
|
|
4
4
|
}
|
|
5
|
-
export declare const hasImageSnapshot: BrowserCommand<[
|
|
5
|
+
export declare const hasImageSnapshot: BrowserCommand<[
|
|
6
|
+
taskId: string,
|
|
7
|
+
snapshotId: string | undefined,
|
|
8
|
+
isAutoSnapshot: boolean
|
|
9
|
+
]>;
|
|
6
10
|
//# sourceMappingURL=has_image_snapshot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,uBAAuB;IACvC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,uBAAuB;IACvC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC3G;AAED,eAAO,MAAM,gBAAgB,EAAE,cAAc,CAC5C;IAAC,MAAM,EAAE,MAAM;IAAE,UAAU,EAAE,MAAM,GAAG,SAAS;IAAE,cAAc,EAAE,OAAO;CAAC,CAKzE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { visContext } from "../vis_context.js";
|
|
2
2
|
import { assertTestPathDefined } from "./_assertions.js";
|
|
3
|
-
export const hasImageSnapshot = async (context, taskId, snapshotId) => {
|
|
3
|
+
export const hasImageSnapshot = async (context, taskId, snapshotId, isAutoSnapshot) => {
|
|
4
4
|
assertTestPathDefined(context, 'hasImageSnapshot');
|
|
5
|
-
return visContext.hasImageSnapshot(context.testPath, taskId, snapshotId);
|
|
5
|
+
return visContext.hasImageSnapshot(context.testPath, taskId, snapshotId, isAutoSnapshot);
|
|
6
6
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BrowserCommand } from 'vitest/node';
|
|
2
2
|
import type { ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../../shared/types.ts';
|
|
3
3
|
export interface MatchImageSnapshotCommand {
|
|
4
|
-
matchImageSnapshot: (taskId: string | undefined, subject: string, options?: MatchImageSnapshotOptions | undefined) => Promise<void>;
|
|
4
|
+
matchImageSnapshot: (taskId: string | undefined, subject: string, isAutoSnapshot: boolean, options?: MatchImageSnapshotOptions | undefined) => Promise<void>;
|
|
5
5
|
}
|
|
6
6
|
export type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<any> & {
|
|
7
7
|
/**
|
|
@@ -12,6 +12,7 @@ export type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnaps
|
|
|
12
12
|
export declare const matchImageSnapshot: BrowserCommand<[
|
|
13
13
|
taskId: string,
|
|
14
14
|
subject: string,
|
|
15
|
+
isAutoSnapshot: boolean,
|
|
15
16
|
options?: MatchImageSnapshotOptions | undefined
|
|
16
17
|
]>;
|
|
17
18
|
//# sourceMappingURL=match_image_snapshot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,cAAc,EAAE,OAAO,EACvB,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,cAAc,EAAE,OAAO;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CAuE3G,CAAA"}
|
|
@@ -9,13 +9,13 @@ import { file } from "../file.js";
|
|
|
9
9
|
import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot, writeSnapshotBuffer } from "../snapshot.js";
|
|
10
10
|
import { visContext } from "../vis_context.js";
|
|
11
11
|
import { assertTestPathDefined } from "./_assertions.js";
|
|
12
|
-
export const matchImageSnapshot = async (context, taskId, subject, options) => {
|
|
12
|
+
export const matchImageSnapshot = async (context, taskId, subject, isAutoSnapshot, options) => {
|
|
13
13
|
assertTestPathDefined(context, 'matchImageSnapshot');
|
|
14
14
|
// vitest:browser passes in `null` when not defined
|
|
15
15
|
if (!options)
|
|
16
16
|
options = {};
|
|
17
17
|
options.timeout = options.timeout ?? 30000;
|
|
18
|
-
const info = visContext.getSnapshotInfo(context.testPath, taskId, options);
|
|
18
|
+
const info = visContext.getSnapshotInfo(context.testPath, taskId, isAutoSnapshot, options);
|
|
19
19
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
20
20
|
if (!baselineBuffer) {
|
|
21
21
|
if (isBase64String(subject)) {
|
|
@@ -10,11 +10,12 @@ type ImageSnapshotComparisonInfo = {
|
|
|
10
10
|
result: string;
|
|
11
11
|
} & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions);
|
|
12
12
|
export interface PrepareImageSnapshotComparisonCommand {
|
|
13
|
-
prepareImageSnapshotComparison: (taskId: string | undefined, subject: string, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo | undefined>;
|
|
13
|
+
prepareImageSnapshotComparison: (taskId: string | undefined, subject: string, isAutoSnapshot: boolean, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo | undefined>;
|
|
14
14
|
}
|
|
15
15
|
export declare const prepareImageSnapshotComparison: BrowserCommand<[
|
|
16
16
|
taskId: string,
|
|
17
17
|
snapshotId: string,
|
|
18
|
+
isAutoSnapshot: boolean,
|
|
18
19
|
options?: MatchImageSnapshotOptions | undefined
|
|
19
20
|
]>;
|
|
20
21
|
export {};
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,cAAc,EAAE,OAAO,EACvB,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,cAAc,EAAE,OAAO;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CA0B9G,CAAA"}
|
|
@@ -3,13 +3,13 @@ import { file } from "../file.js";
|
|
|
3
3
|
import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from "../snapshot.js";
|
|
4
4
|
import { visContext } from "../vis_context.js";
|
|
5
5
|
import { assertTestPathDefined } from "./_assertions.js";
|
|
6
|
-
export const prepareImageSnapshotComparison = async (context, taskId, subject, options) => {
|
|
6
|
+
export const prepareImageSnapshotComparison = async (context, taskId, subject, isAutoSnapshot, options) => {
|
|
7
7
|
assertTestPathDefined(context, 'prepareImageSnapshotComparison');
|
|
8
8
|
// vitest:browser passes in `null` when not defined
|
|
9
9
|
if (!options)
|
|
10
10
|
options = {};
|
|
11
11
|
options.timeout = options.timeout ?? 30000;
|
|
12
|
-
const info = visContext.getSnapshotInfo(context.testPath, taskId, options);
|
|
12
|
+
const info = visContext.getSnapshotInfo(context.testPath, taskId, isAutoSnapshot, options);
|
|
13
13
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
14
14
|
if (!baselineBuffer) {
|
|
15
15
|
if (isBase64String(subject)) {
|
|
@@ -4,7 +4,7 @@ export declare const visContext: {
|
|
|
4
4
|
__test__reset(): void;
|
|
5
5
|
__test__getState(): import("./vis_context.types.ts").VisState;
|
|
6
6
|
setupSuite(context: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("type-plus").Pick._<import("./vis_context.types.ts").VisState, "subjectDataTestId">>;
|
|
7
|
-
getSnapshotInfo(testPath: string, name: string, options?: {
|
|
7
|
+
getSnapshotInfo(testPath: string, name: string, isAutoSnapshot: boolean, options?: {
|
|
8
8
|
snapshotFileId?: string | undefined;
|
|
9
9
|
}): {
|
|
10
10
|
baselinePath: string;
|
|
@@ -34,13 +34,13 @@ export declare const visContext: {
|
|
|
34
34
|
} | undefined;
|
|
35
35
|
};
|
|
36
36
|
getTaskCount(testPath: string, taskId: string): number;
|
|
37
|
-
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined): Promise<boolean>;
|
|
37
|
+
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>;
|
|
38
38
|
getSnapshotFilename(info: {
|
|
39
39
|
taskId: string;
|
|
40
40
|
task: {
|
|
41
41
|
count: number;
|
|
42
42
|
};
|
|
43
|
-
}, snapshotFileId: string | undefined): string;
|
|
43
|
+
}, snapshotFileId: string | undefined, isAutoSnapshot: boolean): string;
|
|
44
44
|
getSuiteInfo(testPath: string, taskId: string): {
|
|
45
45
|
suiteId: string;
|
|
46
46
|
taskId: string;
|
|
@@ -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;;;;;;;sBACmgD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAD/+C,CAAA"}
|
|
@@ -11,7 +11,7 @@ export declare function createVisContext(): {
|
|
|
11
11
|
* It needs to make sure there is no race condition between the test files.
|
|
12
12
|
*/
|
|
13
13
|
setupSuite(context: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<VisState, "subjectDataTestId">>;
|
|
14
|
-
getSnapshotInfo(testPath: string, name: string, options?: {
|
|
14
|
+
getSnapshotInfo(testPath: string, name: string, isAutoSnapshot: boolean, options?: {
|
|
15
15
|
snapshotFileId?: string | undefined;
|
|
16
16
|
}): {
|
|
17
17
|
baselinePath: string;
|
|
@@ -41,13 +41,13 @@ export declare function createVisContext(): {
|
|
|
41
41
|
} | undefined;
|
|
42
42
|
};
|
|
43
43
|
getTaskCount(testPath: string, taskId: string): number;
|
|
44
|
-
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined): Promise<boolean>;
|
|
44
|
+
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>;
|
|
45
45
|
getSnapshotFilename(info: {
|
|
46
46
|
taskId: string;
|
|
47
47
|
task: {
|
|
48
48
|
count: number;
|
|
49
49
|
};
|
|
50
|
-
}, snapshotFileId: string | undefined): string;
|
|
50
|
+
}, snapshotFileId: string | undefined, isAutoSnapshot: boolean): string;
|
|
51
51
|
getSuiteInfo(testPath: string, taskId: string): {
|
|
52
52
|
suiteId: string;
|
|
53
53
|
taskId: string;
|
|
@@ -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,4BAA4B,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEpF,wBAAgB,gBAAgB;eAMnB,CAAC,SAAS,OAAO,GAAG,MAAM,YAAW,UAAU,CAAC,CAAC,CAAC;;;;IAY7D;;;;OAIG;wBACuB,4BAA4B;8BAc3C,MAAM,QACV,MAAM,kBACI,OAAO,YACb;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAmB3B,MAAM,UAAU,MAAM;+BAGlB,MAAM,UAAU,MAAM,kBAAkB,MAAM,GAAG,SAAS,kBAAkB,OAAO;8BAKvG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBAEjC,MAAM,GAAG,SAAS,kBAClB,OAAO;2BAUD,MAAM,UAAU,MAAM;;;;;;;;;;EAe9C;AAyBD,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,6 +1,5 @@
|
|
|
1
1
|
import { join, relative } from 'pathe';
|
|
2
2
|
import { pick } from 'type-plus';
|
|
3
|
-
import { getCurrentTest } from 'vitest/suite';
|
|
4
3
|
import { BASELINE_DIR, DIFF_DIR, RESULT_DIR } from "../shared/constants.js";
|
|
5
4
|
import { file } from "./file.js";
|
|
6
5
|
import { getSnapshotSubpath, resolveSnapshotRootDir } from "./snapshot_path.js";
|
|
@@ -40,10 +39,10 @@ export function createVisContext() {
|
|
|
40
39
|
await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)]);
|
|
41
40
|
return pick(state, 'subjectDataTestId');
|
|
42
41
|
},
|
|
43
|
-
getSnapshotInfo(testPath, name, options) {
|
|
44
|
-
const
|
|
45
|
-
const snapshotFilename = context.getSnapshotFilename(
|
|
46
|
-
const { baselineDir, resultDir, diffDir, task } =
|
|
42
|
+
getSnapshotInfo(testPath, name, isAutoSnapshot, options) {
|
|
43
|
+
const suiteInfo = context.getSuiteInfo(testPath, name);
|
|
44
|
+
const snapshotFilename = context.getSnapshotFilename(suiteInfo, options?.snapshotFileId, isAutoSnapshot);
|
|
45
|
+
const { baselineDir, resultDir, diffDir, task } = suiteInfo;
|
|
47
46
|
task.count = task.count + 1;
|
|
48
47
|
const baselinePath = join(baselineDir, snapshotFilename);
|
|
49
48
|
const resultPath = join(resultDir, snapshotFilename);
|
|
@@ -58,15 +57,13 @@ export function createVisContext() {
|
|
|
58
57
|
getTaskCount(testPath, taskId) {
|
|
59
58
|
return context.getSuiteInfo(testPath, taskId).task.count;
|
|
60
59
|
},
|
|
61
|
-
hasImageSnapshot(testPath, taskId, snapshotFileId) {
|
|
60
|
+
hasImageSnapshot(testPath, taskId, snapshotFileId, isAutoSnapshot) {
|
|
62
61
|
const info = context.getSuiteInfo(testPath, taskId);
|
|
63
|
-
return file.existFile(join(info.baselineDir, context.getSnapshotFilename(info, snapshotFileId)));
|
|
62
|
+
return file.existFile(join(info.baselineDir, context.getSnapshotFilename(info, snapshotFileId, isAutoSnapshot)));
|
|
64
63
|
},
|
|
65
|
-
getSnapshotFilename(info, snapshotFileId) {
|
|
64
|
+
getSnapshotFilename(info, snapshotFileId, isAutoSnapshot) {
|
|
66
65
|
if (snapshotFileId)
|
|
67
66
|
return `${snapshotFileId}.png`;
|
|
68
|
-
const test = getCurrentTest();
|
|
69
|
-
const isAutoSnapshot = !!test?.meta.vis?.isAutoSnapshot;
|
|
70
67
|
const customizeSnapshotId = visOptions.customizeSnapshotId ?? (({ id, index }) => `${id}-${index}`);
|
|
71
68
|
return `${customizeSnapshotId({
|
|
72
69
|
id: info.taskId,
|
package/esm/shared/types.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type pixelMatch from 'pixelmatch';
|
|
2
2
|
import type { Options as SsimOptions } from 'ssim.js';
|
|
3
|
-
import type { getCurrentTest } from 'vitest/suite';
|
|
4
|
-
import type { NAME } from './constants.ts';
|
|
5
3
|
export interface ImageSnapshotTimeoutOptions {
|
|
6
4
|
/**
|
|
7
5
|
* Timeout for taking the snapshot.
|
|
@@ -73,11 +71,4 @@ export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptio
|
|
|
73
71
|
enable?: boolean | undefined;
|
|
74
72
|
[key: string]: unknown;
|
|
75
73
|
};
|
|
76
|
-
export type CurrentTest = ReturnType<typeof getCurrentTest> & {
|
|
77
|
-
meta: {
|
|
78
|
-
[NAME]?: SnapshotMeta<'pixel' | 'ssim'> & {
|
|
79
|
-
isAutoSnapshot?: boolean | undefined;
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
74
|
//# 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,UAAU,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;AAIrD,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,OAAO,EAAE;QAC/B,EAAE,EAAE,MAAM,CAAA;QACV,KAAK,EAAE,MAAM,CAAA;QACb,cAAc,EAAE,OAAO,CAAA;KACvB,KAAK,MAAM,CAAA;CACZ;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,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;CAC1D,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;AAExB,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACtC,CAAA;AACD,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,GAC1G,sBAAsB,GACtB,2BAA2B,CAAC,CAAC,CAAC,GAAG;IAChC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAClC,CAAA;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,gBAAgB,IAAI,2BAA2B,CAAC,CAAC,CAAC,GACpF,mBAAmB,GAAG;IACrB,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isA } from '@vitest/expect'
|
|
1
2
|
import dedent from 'dedent'
|
|
2
3
|
import { resolve } from 'pathe'
|
|
3
4
|
import type { ImageSnapshotNextIndexCommand } from '../commands.ts'
|
|
@@ -5,13 +6,14 @@ import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/p
|
|
|
5
6
|
import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts'
|
|
6
7
|
import { isBase64String } from '../shared/base64.ts'
|
|
7
8
|
import { compareImage } from '../shared/compare_image.ts'
|
|
8
|
-
import type {
|
|
9
|
+
import type { ToMatchImageSnapshotOptions } from '../shared/types.ts'
|
|
9
10
|
import { alignImagesToSameSize } from './align_images.ts'
|
|
10
11
|
import { toDataURL, toImageData } from './image_data.ts'
|
|
11
12
|
import { prettifyOptions } from './image_snapshot_matcher.logic.ts'
|
|
12
13
|
import { convertElementToCssSelector } from './selector.ts'
|
|
13
14
|
import { toTaskId } from './task_id.ts'
|
|
14
15
|
import { server } from './vitest_browser_context_proxy.ts'
|
|
16
|
+
import type { CurrentTest } from './vitest_suite_proxy.ts'
|
|
15
17
|
|
|
16
18
|
export function imageSnapshotMatcher(
|
|
17
19
|
commands: PrepareImageSnapshotComparisonCommand & WriteImageSnapshotCommand & ImageSnapshotNextIndexCommand,
|
|
@@ -26,6 +28,7 @@ export function imageSnapshotMatcher(
|
|
|
26
28
|
const info = await commands.prepareImageSnapshotComparison(
|
|
27
29
|
taskId,
|
|
28
30
|
parseImageSnapshotSubject(subject),
|
|
31
|
+
isAutoSnapshot,
|
|
29
32
|
options?.customizeSnapshotId
|
|
30
33
|
? await parseImageSnapshotOptions(commands, taskId, isAutoSnapshot, options)
|
|
31
34
|
: options,
|
|
@@ -23,16 +23,18 @@ export function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotIdOpt
|
|
|
23
23
|
)
|
|
24
24
|
}
|
|
25
25
|
const taskId = toTaskId(test)
|
|
26
|
+
const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot
|
|
26
27
|
if (options?.customizeSnapshotId) {
|
|
27
28
|
return commands
|
|
28
29
|
.imageSnapshotNextIndex(taskId)
|
|
29
30
|
.then((index) =>
|
|
30
31
|
commands.hasImageSnapshot(
|
|
31
32
|
taskId,
|
|
32
|
-
options.customizeSnapshotId!({ id: taskId, index, isAutoSnapshot
|
|
33
|
+
options.customizeSnapshotId!({ id: taskId, index, isAutoSnapshot }),
|
|
34
|
+
isAutoSnapshot,
|
|
33
35
|
),
|
|
34
36
|
)
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
return commands.hasImageSnapshot(taskId)
|
|
39
|
+
return commands.hasImageSnapshot(taskId, undefined, isAutoSnapshot)
|
|
38
40
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NAME } from '../shared/constants.ts'
|
|
2
|
+
import type { SnapshotMeta } from '../shared/types.ts'
|
|
2
3
|
|
|
3
4
|
let vitestSuite: Awaited<typeof import('vitest/suite')>
|
|
4
5
|
|
|
@@ -8,5 +9,9 @@ if ((globalThis as any).__vitest_browser__) {
|
|
|
8
9
|
})
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
export type CurrentTest = ReturnType<typeof vitestSuite.getCurrentTest> & {
|
|
13
|
+
meta: { [NAME]?: SnapshotMeta<'pixel' | 'ssim'> & { isAutoSnapshot?: boolean | undefined } }
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
export const getCurrentTest = () => vitestSuite?.getCurrentTest() as CurrentTest
|
|
12
17
|
export const getCurrentSuite = () => vitestSuite?.getCurrentSuite()
|
|
@@ -3,15 +3,13 @@ import { visContext } from '../vis_context.ts'
|
|
|
3
3
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
4
|
|
|
5
5
|
export interface HasImageSnapshotCommand {
|
|
6
|
-
hasImageSnapshot(taskId: string, snapshotId
|
|
6
|
+
hasImageSnapshot(taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const hasImageSnapshot: BrowserCommand<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
snapshotId,
|
|
13
|
-
) => {
|
|
9
|
+
export const hasImageSnapshot: BrowserCommand<
|
|
10
|
+
[taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean]
|
|
11
|
+
> = async (context, taskId, snapshotId, isAutoSnapshot) => {
|
|
14
12
|
assertTestPathDefined(context, 'hasImageSnapshot')
|
|
15
13
|
|
|
16
|
-
return visContext.hasImageSnapshot(context.testPath, taskId, snapshotId)
|
|
14
|
+
return visContext.hasImageSnapshot(context.testPath, taskId, snapshotId, isAutoSnapshot)
|
|
17
15
|
}
|
|
@@ -20,6 +20,7 @@ export interface MatchImageSnapshotCommand {
|
|
|
20
20
|
matchImageSnapshot: (
|
|
21
21
|
taskId: string | undefined,
|
|
22
22
|
subject: string,
|
|
23
|
+
isAutoSnapshot: boolean,
|
|
23
24
|
options?: MatchImageSnapshotOptions | undefined,
|
|
24
25
|
) => Promise<void>
|
|
25
26
|
}
|
|
@@ -34,15 +35,15 @@ export type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions &
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export const matchImageSnapshot: BrowserCommand<
|
|
37
|
-
[taskId: string, subject: string, options?: MatchImageSnapshotOptions | undefined]
|
|
38
|
-
> = async (context, taskId, subject, options) => {
|
|
38
|
+
[taskId: string, subject: string, isAutoSnapshot: boolean, options?: MatchImageSnapshotOptions | undefined]
|
|
39
|
+
> = async (context, taskId, subject, isAutoSnapshot, options) => {
|
|
39
40
|
assertTestPathDefined(context, 'matchImageSnapshot')
|
|
40
41
|
|
|
41
42
|
// vitest:browser passes in `null` when not defined
|
|
42
43
|
if (!options) options = {}
|
|
43
44
|
options.timeout = options.timeout ?? 30000
|
|
44
45
|
|
|
45
|
-
const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
|
|
46
|
+
const info = visContext.getSnapshotInfo(context.testPath, taskId, isAutoSnapshot, options)
|
|
46
47
|
const baselineBuffer = await file.tryReadFile(info.baselinePath)
|
|
47
48
|
if (!baselineBuffer) {
|
|
48
49
|
if (isBase64String(subject)) {
|
|
@@ -27,20 +27,21 @@ export interface PrepareImageSnapshotComparisonCommand {
|
|
|
27
27
|
prepareImageSnapshotComparison: (
|
|
28
28
|
taskId: string | undefined,
|
|
29
29
|
subject: string,
|
|
30
|
+
isAutoSnapshot: boolean,
|
|
30
31
|
options?: MatchImageSnapshotOptions | undefined,
|
|
31
32
|
) => Promise<ImageSnapshotComparisonInfo | undefined>
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export const prepareImageSnapshotComparison: BrowserCommand<
|
|
35
|
-
[taskId: string, snapshotId: string, options?: MatchImageSnapshotOptions | undefined]
|
|
36
|
-
> = async (context, taskId, subject, options) => {
|
|
36
|
+
[taskId: string, snapshotId: string, isAutoSnapshot: boolean, options?: MatchImageSnapshotOptions | undefined]
|
|
37
|
+
> = async (context, taskId, subject, isAutoSnapshot, options) => {
|
|
37
38
|
assertTestPathDefined(context, 'prepareImageSnapshotComparison')
|
|
38
39
|
|
|
39
40
|
// vitest:browser passes in `null` when not defined
|
|
40
41
|
if (!options) options = {}
|
|
41
42
|
options.timeout = options.timeout ?? 30000
|
|
42
43
|
|
|
43
|
-
const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
|
|
44
|
+
const info = visContext.getSnapshotInfo(context.testPath, taskId, isAutoSnapshot, options)
|
|
44
45
|
const baselineBuffer = await file.tryReadFile(info.baselinePath)
|
|
45
46
|
if (!baselineBuffer) {
|
|
46
47
|
if (isBase64String(subject)) {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { join, relative } from 'pathe'
|
|
2
2
|
import { pick } from 'type-plus'
|
|
3
|
-
import { getCurrentTest } from 'vitest/suite'
|
|
4
3
|
import type { VisOptions } from '../config/types.ts'
|
|
5
4
|
import { BASELINE_DIR, DIFF_DIR, RESULT_DIR } from '../shared/constants.ts'
|
|
6
|
-
import type { CurrentTest } from '../shared/types.ts'
|
|
7
5
|
import { file } from './file.ts'
|
|
8
6
|
import { getSnapshotSubpath, resolveSnapshotRootDir } from './snapshot_path.ts'
|
|
9
7
|
import { ctx } from './vis_context.ctx.ts'
|
|
@@ -45,11 +43,16 @@ export function createVisContext() {
|
|
|
45
43
|
await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)])
|
|
46
44
|
return pick(state, 'subjectDataTestId')
|
|
47
45
|
},
|
|
48
|
-
getSnapshotInfo(
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
getSnapshotInfo(
|
|
47
|
+
testPath: string,
|
|
48
|
+
name: string,
|
|
49
|
+
isAutoSnapshot: boolean,
|
|
50
|
+
options?: { snapshotFileId?: string | undefined },
|
|
51
|
+
) {
|
|
52
|
+
const suiteInfo = context.getSuiteInfo(testPath, name)
|
|
53
|
+
const snapshotFilename = context.getSnapshotFilename(suiteInfo, options?.snapshotFileId, isAutoSnapshot)
|
|
51
54
|
|
|
52
|
-
const { baselineDir, resultDir, diffDir, task } =
|
|
55
|
+
const { baselineDir, resultDir, diffDir, task } = suiteInfo
|
|
53
56
|
|
|
54
57
|
task.count = task.count + 1
|
|
55
58
|
const baselinePath = join(baselineDir, snapshotFilename)
|
|
@@ -66,14 +69,17 @@ export function createVisContext() {
|
|
|
66
69
|
getTaskCount(testPath: string, taskId: string) {
|
|
67
70
|
return context.getSuiteInfo(testPath, taskId).task.count
|
|
68
71
|
},
|
|
69
|
-
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined) {
|
|
72
|
+
hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined, isAutoSnapshot: boolean) {
|
|
70
73
|
const info = context.getSuiteInfo(testPath, taskId)
|
|
71
|
-
return file.existFile(join(info.baselineDir, context.getSnapshotFilename(info, snapshotFileId)))
|
|
74
|
+
return file.existFile(join(info.baselineDir, context.getSnapshotFilename(info, snapshotFileId, isAutoSnapshot)))
|
|
72
75
|
},
|
|
73
|
-
getSnapshotFilename(
|
|
76
|
+
getSnapshotFilename(
|
|
77
|
+
info: { taskId: string; task: { count: number } },
|
|
78
|
+
|
|
79
|
+
snapshotFileId: string | undefined,
|
|
80
|
+
isAutoSnapshot: boolean,
|
|
81
|
+
) {
|
|
74
82
|
if (snapshotFileId) return `${snapshotFileId}.png`
|
|
75
|
-
const test = getCurrentTest() as CurrentTest
|
|
76
|
-
const isAutoSnapshot = !!test?.meta.vis?.isAutoSnapshot
|
|
77
83
|
const customizeSnapshotId = visOptions.customizeSnapshotId ?? (({ id, index }) => `${id}-${index}`)
|
|
78
84
|
return `${customizeSnapshotId({
|
|
79
85
|
id: info.taskId,
|
package/src/shared/types.ts
CHANGED
|
@@ -87,7 +87,3 @@ export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptio
|
|
|
87
87
|
enable?: boolean | undefined
|
|
88
88
|
[key: string]: unknown
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
export type CurrentTest = ReturnType<typeof getCurrentTest> & {
|
|
92
|
-
meta: { [NAME]?: SnapshotMeta<'pixel' | 'ssim'> & { isAutoSnapshot?: boolean | undefined } }
|
|
93
|
-
}
|