vitest-plugin-vis 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/client/image_snapshot_matcher.d.ts +2 -2
- package/esm/client/image_snapshot_matcher.d.ts.map +1 -1
- package/esm/client/image_snapshot_matcher.js +3 -3
- package/esm/client/snapshot_options.js +1 -1
- package/esm/commands.d.ts +1 -2
- package/esm/commands.d.ts.map +1 -1
- package/esm/commands.js +1 -2
- package/esm/config/types.d.ts +3 -3
- package/esm/config/types.d.ts.map +1 -1
- package/esm/config/vis.d.ts +1 -2
- package/esm/config/vis.d.ts.map +1 -1
- package/esm/config/vis.js +4 -3
- package/esm/server/commands/browser_command_context.d.ts +14 -0
- package/esm/server/commands/browser_command_context.d.ts.map +1 -0
- package/esm/server/commands/browser_command_context.js +6 -0
- package/esm/server/commands/extend.d.ts +1 -3
- package/esm/server/commands/extend.d.ts.map +1 -1
- package/esm/server/commands/extend.js +0 -2
- package/esm/server/commands/has_image_snapshot.js +1 -1
- package/esm/server/commands/image_snapshot_next_index.js +1 -1
- package/esm/server/commands/match_image_snapshot.js +1 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +18 -0
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.js +8 -6
- package/esm/server/snapshot_path.js +2 -2
- package/esm/server/vis_context.d.ts +13 -12
- package/esm/server/vis_context.d.ts.map +1 -1
- package/esm/server/vis_context.logic.d.ts +16 -15
- package/esm/server/vis_context.logic.d.ts.map +1 -1
- package/esm/server/vis_context.logic.js +51 -42
- package/esm/server/vis_context.types.d.ts +16 -6
- package/esm/server/vis_context.types.d.ts.map +1 -1
- package/esm/testing/stubBrowserCommandContext.d.ts.map +1 -1
- package/esm/testing/stubBrowserCommandContext.js +7 -0
- package/package.json +2 -1
- package/src/client/image_snapshot_matcher.ts +6 -6
- package/src/client/snapshot_options.ts +1 -1
- package/src/commands.ts +1 -2
- package/src/config/types.ts +3 -3
- package/src/config/vis.ts +5 -3
- package/src/server/commands/browser_command_context.ts +9 -0
- package/src/server/commands/extend.ts +0 -3
- package/src/server/commands/has_image_snapshot.ts +1 -1
- package/src/server/commands/image_snapshot_next_index.ts +1 -1
- package/src/server/commands/match_image_snapshot.ts +1 -1
- package/src/server/commands/prepare_image_snapshot_comparison.ts +26 -7
- package/src/server/snapshot_path.ts +2 -2
- package/src/server/vis_context.logic.ts +94 -45
- package/src/server/vis_context.types.ts +18 -7
- package/src/testing/stubBrowserCommandContext.ts +7 -0
- package/esm/server/commands/write_image_snapshot.d.ts +0 -12
- package/esm/server/commands/write_image_snapshot.d.ts.map +0 -1
- package/esm/server/commands/write_image_snapshot.js +0 -9
- package/src/server/commands/write_image_snapshot.ts +0 -26
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { BrowserCommands } from '@vitest/browser/context';
|
|
1
2
|
import type { ImageSnapshotNextIndexCommand } from '../commands.ts';
|
|
2
3
|
import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts';
|
|
3
|
-
import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts';
|
|
4
4
|
import type { ToMatchImageSnapshotOptions } from '../shared/types.ts';
|
|
5
5
|
import type { CurrentTest } from './vitest_suite_proxy.ts';
|
|
6
|
-
export declare function imageSnapshotMatcher(commands:
|
|
6
|
+
export declare function imageSnapshotMatcher(commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand): (test: CurrentTest & {}, subject: any, options?: ToMatchImageSnapshotOptions<any>) => Promise<void>;
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated internalized. Use `matchImageSnapshot` directly instead.
|
|
9
9
|
*/
|
|
@@ -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":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAG9D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAA;AAGpH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAOrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,eAAe,GAAG,qCAAqC,GAAG,6BAA6B,UAG1F,WAAW,GAAG,EAAE,WACb,GAAG,YACF,2BAA2B,CAAC,GAAG,CAAC,mBAqE3C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
|
|
@@ -37,10 +37,10 @@ export function imageSnapshotMatcher(commands) {
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
if (server.config.snapshotOptions.updateSnapshot === 'all' && !options?.expectToFail) {
|
|
40
|
-
await writeSnapshot(commands, info.baselinePath, resultImage);
|
|
40
|
+
await writeSnapshot(commands, resolve(info.projectRoot, info.baselinePath), resultImage);
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
await writeSnapshot(commands, info.diffPath, diffImage);
|
|
43
|
+
await writeSnapshot(commands, resolve(info.projectRoot, info.diffPath), diffImage);
|
|
44
44
|
throw new Error(dedent `Snapshot \`${taskId}\` mismatched
|
|
45
45
|
|
|
46
46
|
${options?.failureThreshold
|
|
@@ -70,7 +70,7 @@ export function parseImageSnapshotSubject(subject) {
|
|
|
70
70
|
}
|
|
71
71
|
async function writeSnapshot(commands, path, image) {
|
|
72
72
|
const content = (await toDataURL(image)).split(',')[1];
|
|
73
|
-
return commands.
|
|
73
|
+
return commands.writeFile(path, content, { encoding: 'base64' });
|
|
74
74
|
}
|
|
75
75
|
async function parseImageSnapshotOptions(commands, taskId, isAutoSnapshot, options) {
|
|
76
76
|
const index = await commands.imageSnapshotNextIndex(taskId);
|
|
@@ -13,7 +13,7 @@ export function setAutoSnapshotOptions(...args) {
|
|
|
13
13
|
}
|
|
14
14
|
function parseArgs(args) {
|
|
15
15
|
return args.length === 1
|
|
16
|
-
? [ctx.getCurrentTest() ?? ctx.getCurrentSuite()
|
|
16
|
+
? [ctx.getCurrentTest() ?? ctx.getCurrentSuite()?.tasks?.[0]?.file, parseMeta(args[0])]
|
|
17
17
|
: [args[0], parseMeta(args[1])];
|
|
18
18
|
}
|
|
19
19
|
function parseMeta(meta) {
|
package/esm/commands.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './server/commands/has_image_snapshot.ts';
|
|
2
2
|
export * from './server/commands/image_snapshot_next_index.ts';
|
|
3
3
|
export * from './server/commands/match_image_snapshot.ts';
|
|
4
|
-
export * from './server/commands/setup_vis_suite.ts';
|
|
5
4
|
export * from './server/commands/prepare_image_snapshot_comparison.ts';
|
|
6
|
-
export * from './server/commands/
|
|
5
|
+
export * from './server/commands/setup_vis_suite.ts';
|
|
7
6
|
//# sourceMappingURL=commands.d.ts.map
|
package/esm/commands.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,2CAA2C,CAAA;AACzD,cAAc,
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,2CAA2C,CAAA;AACzD,cAAc,wDAAwD,CAAA;AACtE,cAAc,sCAAsC,CAAA"}
|
package/esm/commands.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from "./server/commands/has_image_snapshot.js";
|
|
2
2
|
export * from "./server/commands/image_snapshot_next_index.js";
|
|
3
3
|
export * from "./server/commands/match_image_snapshot.js";
|
|
4
|
-
export * from "./server/commands/setup_vis_suite.js";
|
|
5
4
|
export * from "./server/commands/prepare_image_snapshot_comparison.js";
|
|
6
|
-
export * from "./server/commands/
|
|
5
|
+
export * from "./server/commands/setup_vis_suite.js";
|
package/esm/config/types.d.ts
CHANGED
|
@@ -22,11 +22,11 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
|
|
|
22
22
|
*/
|
|
23
23
|
snapshotRootDir?: string | ((context: {
|
|
24
24
|
ci: boolean;
|
|
25
|
-
browserName
|
|
25
|
+
browserName?: string | undefined;
|
|
26
26
|
providerName: string;
|
|
27
27
|
platform: string;
|
|
28
|
-
screenshotFailures
|
|
29
|
-
screenshotDirectory
|
|
28
|
+
screenshotFailures?: boolean | undefined;
|
|
29
|
+
screenshotDirectory?: string | undefined;
|
|
30
30
|
}) => string) | undefined;
|
|
31
31
|
/**
|
|
32
32
|
* Customize the snapshot subpath.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,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,GAC9B,mBAAmB,GAAG;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC1D;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EACb,MAAM,GACN,CAAC,CAAC,OAAO,EAAE;QACX,EAAE,EAAE,OAAO,CAAA;QACX,WAAW,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,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,GAC9B,mBAAmB,GAAG;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC1D;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EACb,MAAM,GACN,CAAC,CAAC,OAAO,EAAE;QACX,EAAE,EAAE,OAAO,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAChC,YAAY,EAAE,MAAM,CAAA;QACpB,QAAQ,EAAE,MAAM,CAAA;QAChB,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACxC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KACvC,KAAK,MAAM,CAAC,GACb,SAAS,CAAA;IACZ;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD,CAAA"}
|
package/esm/config/vis.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { VisOptions } from './types.ts';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function vis<M extends ComparisonMethod = 'pixel'>(options?: VisOptions<M>): {
|
|
10
10
|
name: string;
|
|
11
|
-
config(this: void): {
|
|
11
|
+
config(this: void, userConfig: import("vite").UserConfig): {
|
|
12
12
|
test: {
|
|
13
13
|
browser: {
|
|
14
14
|
name: string;
|
|
@@ -18,7 +18,6 @@ export declare function vis<M extends ComparisonMethod = 'pixel'>(options?: VisO
|
|
|
18
18
|
hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean]>;
|
|
19
19
|
matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, isAutoSnapshot: boolean, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
|
|
20
20
|
prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, isAutoSnapshot: boolean, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
|
|
21
|
-
writeImageSnapshot: import("vitest/node").BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
|
|
22
21
|
};
|
|
23
22
|
};
|
|
24
23
|
setupFiles: string[];
|
package/esm/config/vis.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vis.d.ts","sourceRoot":"","sources":["../../src/config/vis.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,EAAE,OAAO,GAAE,UAAU,CAAC,CAAC,CAA6B;;;;;
|
|
1
|
+
{"version":3,"file":"vis.d.ts","sourceRoot":"","sources":["../../src/config/vis.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,EAAE,OAAO,GAAE,UAAU,CAAC,CAAC,CAA6B;;;;;sBAWxE,MAAM;;;;;;;;;;;;EAQzC"}
|
package/esm/config/vis.js
CHANGED
|
@@ -8,11 +8,12 @@ import { NAME } from "../shared/constants.js";
|
|
|
8
8
|
* which enables the `auto` preset.
|
|
9
9
|
*/
|
|
10
10
|
export function vis(options = { preset: 'auto' }) {
|
|
11
|
-
visContext.setOptions(options);
|
|
12
|
-
const preset = options?.preset;
|
|
13
11
|
return {
|
|
14
12
|
name: NAME,
|
|
15
|
-
config() {
|
|
13
|
+
config(userConfig) {
|
|
14
|
+
const projectName = userConfig?.test?.name;
|
|
15
|
+
visContext.setOptions(projectName, options);
|
|
16
|
+
const preset = options?.preset;
|
|
16
17
|
return {
|
|
17
18
|
test: {
|
|
18
19
|
browser: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BrowserCommandContext } from 'vitest/node';
|
|
2
|
+
export declare function getProjectName(context: {
|
|
3
|
+
project: {
|
|
4
|
+
vite: {
|
|
5
|
+
config: {
|
|
6
|
+
test?: {
|
|
7
|
+
name?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}): string | undefined;
|
|
13
|
+
export declare function getBrowserInstanceProjectName(context: BrowserCommandContext): import("vitest/node").ResolvedConfig;
|
|
14
|
+
//# sourceMappingURL=browser_command_context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser_command_context.d.ts","sourceRoot":"","sources":["../../../src/server/commands/browser_command_context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,MAAM,EAAE;gBAAE,IAAI,CAAC,EAAE;oBAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;iBAAE,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,sBAElH;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,qBAAqB,wCAE3E"}
|
|
@@ -3,9 +3,8 @@ import { type ImageSnapshotNextIndexCommand } from './image_snapshot_next_index.
|
|
|
3
3
|
import { type MatchImageSnapshotCommand } from './match_image_snapshot.ts';
|
|
4
4
|
import { type PrepareImageSnapshotComparisonCommand } from './prepare_image_snapshot_comparison.ts';
|
|
5
5
|
import { type SetupVisSuiteCommand } from './setup_vis_suite.ts';
|
|
6
|
-
import { type WriteImageSnapshotCommand } from './write_image_snapshot.ts';
|
|
7
6
|
declare module '@vitest/browser/context' {
|
|
8
|
-
interface BrowserCommands extends SetupVisSuiteCommand, ImageSnapshotNextIndexCommand, HasImageSnapshotCommand, PrepareImageSnapshotComparisonCommand,
|
|
7
|
+
interface BrowserCommands extends SetupVisSuiteCommand, ImageSnapshotNextIndexCommand, HasImageSnapshotCommand, PrepareImageSnapshotComparisonCommand, MatchImageSnapshotCommand {
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
export declare const commands: {
|
|
@@ -14,6 +13,5 @@ export declare const commands: {
|
|
|
14
13
|
hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean]>;
|
|
15
14
|
matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, isAutoSnapshot: boolean, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
|
|
16
15
|
prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, isAutoSnapshot: boolean, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
|
|
17
|
-
writeImageSnapshot: import("vitest/node").BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
|
|
18
16
|
};
|
|
19
17
|
//# sourceMappingURL=extend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../src/server/commands/extend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,uBAAuB,EAAoB,MAAM,yBAAyB,CAAA;AACxF,OAAO,EAAE,KAAK,6BAA6B,EAA0B,MAAM,gCAAgC,CAAA;AAC3G,OAAO,EAAE,KAAK,yBAAyB,EAAsB,MAAM,2BAA2B,CAAA;AAC9F,OAAO,EACN,KAAK,qCAAqC,EAE1C,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../src/server/commands/extend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,uBAAuB,EAAoB,MAAM,yBAAyB,CAAA;AACxF,OAAO,EAAE,KAAK,6BAA6B,EAA0B,MAAM,gCAAgC,CAAA;AAC3G,OAAO,EAAE,KAAK,yBAAyB,EAAsB,MAAM,2BAA2B,CAAA;AAC9F,OAAO,EACN,KAAK,qCAAqC,EAE1C,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,sBAAsB,CAAA;AAE/E,OAAO,QAAQ,yBAAyB,CAAC;IACxC,UAAU,eACT,SAAQ,oBAAoB,EAC3B,6BAA6B,EAC7B,uBAAuB,EACvB,qCAAqC,EACrC,yBAAyB;KAAG;CAC9B;AAED,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAA"}
|
|
@@ -3,12 +3,10 @@ import { imageSnapshotNextIndex } from "./image_snapshot_next_index.js";
|
|
|
3
3
|
import { matchImageSnapshot } from "./match_image_snapshot.js";
|
|
4
4
|
import { prepareImageSnapshotComparison, } from "./prepare_image_snapshot_comparison.js";
|
|
5
5
|
import { setupVisSuite } from "./setup_vis_suite.js";
|
|
6
|
-
import { writeImageSnapshot } from "./write_image_snapshot.js";
|
|
7
6
|
export const commands = {
|
|
8
7
|
setupVisSuite,
|
|
9
8
|
imageSnapshotNextIndex,
|
|
10
9
|
hasImageSnapshot,
|
|
11
10
|
matchImageSnapshot,
|
|
12
11
|
prepareImageSnapshotComparison,
|
|
13
|
-
writeImageSnapshot,
|
|
14
12
|
};
|
|
@@ -2,5 +2,5 @@ import { visContext } from "../vis_context.js";
|
|
|
2
2
|
import { assertTestPathDefined } from "./_assertions.js";
|
|
3
3
|
export const hasImageSnapshot = async (context, taskId, snapshotId, isAutoSnapshot) => {
|
|
4
4
|
assertTestPathDefined(context, 'hasImageSnapshot');
|
|
5
|
-
return visContext.hasImageSnapshot(context
|
|
5
|
+
return visContext.hasImageSnapshot(context, taskId, snapshotId, isAutoSnapshot);
|
|
6
6
|
};
|
|
@@ -2,5 +2,5 @@ import { visContext } from "../vis_context.js";
|
|
|
2
2
|
import { assertTestPathDefined } from "./_assertions.js";
|
|
3
3
|
export const imageSnapshotNextIndex = async (context, taskId) => {
|
|
4
4
|
assertTestPathDefined(context, 'imageSnapshotNextIndex');
|
|
5
|
-
return visContext.getTaskCount(context
|
|
5
|
+
return visContext.getTaskCount(context, taskId);
|
|
6
6
|
};
|
|
@@ -15,7 +15,7 @@ export const matchImageSnapshot = async (context, taskId, subject, isAutoSnapsho
|
|
|
15
15
|
if (!options)
|
|
16
16
|
options = {};
|
|
17
17
|
options.timeout = options.timeout ?? 30000;
|
|
18
|
-
const info = visContext.getSnapshotInfo(context
|
|
18
|
+
const info = await visContext.getSnapshotInfo(context, taskId, isAutoSnapshot, options);
|
|
19
19
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
20
20
|
if (!baselineBuffer) {
|
|
21
21
|
if (isBase64String(subject)) {
|
|
@@ -2,11 +2,29 @@ import type { BrowserCommand } from 'vitest/node';
|
|
|
2
2
|
import type { FailureThresholdOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions } from '../../shared/types.ts';
|
|
3
3
|
import type { MatchImageSnapshotOptions } from './match_image_snapshot.ts';
|
|
4
4
|
type ImageSnapshotComparisonInfo = {
|
|
5
|
+
/**
|
|
6
|
+
* Path to the project root.
|
|
7
|
+
*/
|
|
5
8
|
projectRoot: string;
|
|
9
|
+
/**
|
|
10
|
+
* Path to the baseline image relative to the project root.
|
|
11
|
+
*/
|
|
6
12
|
baselinePath: string;
|
|
13
|
+
/**
|
|
14
|
+
* Path to the result image relative to the project root.
|
|
15
|
+
*/
|
|
7
16
|
resultPath: string;
|
|
17
|
+
/**
|
|
18
|
+
* Path to the diff image relative to the project root.
|
|
19
|
+
*/
|
|
8
20
|
diffPath: string;
|
|
21
|
+
/**
|
|
22
|
+
* Base64 encoded baseline image.
|
|
23
|
+
*/
|
|
9
24
|
baseline: string;
|
|
25
|
+
/**
|
|
26
|
+
* Base64 encoded result image.
|
|
27
|
+
*/
|
|
10
28
|
result: string;
|
|
11
29
|
} & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions);
|
|
12
30
|
export interface PrepareImageSnapshotComparisonCommand {
|
|
@@ -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":"AACA,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;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve } from 'pathe';
|
|
1
2
|
import { isBase64String } from "../../shared/base64.js";
|
|
2
3
|
import { file } from "../file.js";
|
|
3
4
|
import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from "../snapshot.js";
|
|
@@ -9,21 +10,22 @@ export const prepareImageSnapshotComparison = async (context, taskId, subject, i
|
|
|
9
10
|
if (!options)
|
|
10
11
|
options = {};
|
|
11
12
|
options.timeout = options.timeout ?? 30000;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
13
|
+
const projectRoot = context.project.config.root;
|
|
14
|
+
const info = await visContext.getSnapshotInfo(context, taskId, isAutoSnapshot, options);
|
|
15
|
+
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath));
|
|
14
16
|
if (!baselineBuffer) {
|
|
15
17
|
if (isBase64String(subject)) {
|
|
16
|
-
await writeSnapshot(info.baselinePath, subject);
|
|
18
|
+
await writeSnapshot(resolve(projectRoot, info.baselinePath), subject);
|
|
17
19
|
}
|
|
18
20
|
else {
|
|
19
|
-
await takeSnapshotByBrowser(context, info.baselinePath, subject, options);
|
|
21
|
+
await takeSnapshotByBrowser(context, resolve(projectRoot, info.baselinePath), subject, options);
|
|
20
22
|
}
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
23
|
-
const resultBuffer = await takeSnapshot(context, info.resultPath, subject, options);
|
|
25
|
+
const resultBuffer = await takeSnapshot(context, resolve(projectRoot, info.resultPath), subject, options);
|
|
24
26
|
return {
|
|
25
27
|
...info,
|
|
26
|
-
projectRoot
|
|
28
|
+
projectRoot,
|
|
27
29
|
baseline: baselineBuffer.toString('base64'),
|
|
28
30
|
result: resultBuffer.toString('base64'),
|
|
29
31
|
};
|
|
@@ -12,8 +12,8 @@ export function resolveSnapshotRootDir(suite, options) {
|
|
|
12
12
|
browserName: suite.provider.browserName,
|
|
13
13
|
providerName: suite.provider.name,
|
|
14
14
|
platform: process.platform,
|
|
15
|
-
screenshotFailures: suite.provider.options
|
|
16
|
-
screenshotDirectory: suite.provider.options
|
|
15
|
+
screenshotFailures: suite.provider.options?.screenshotFailures,
|
|
16
|
+
screenshotDirectory: suite.provider.options?.screenshotDirectory,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
function getSnapshotRootDir(snapshotRootDir, platform = process.platform) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export declare const visContext: {
|
|
2
|
-
setOptions<M extends "pixel" | "ssim">(options?: import("../config.ts").VisOptions<M>): void;
|
|
3
|
-
__test__getOptions(): import("../config.ts").VisOptions<any
|
|
2
|
+
setOptions<M extends "pixel" | "ssim">(projectName: string | undefined, options?: import("../config.ts").VisOptions<M>): void;
|
|
3
|
+
__test__getOptions(projectName: string): import("../config.ts").VisOptions<any> | undefined;
|
|
4
4
|
__test__reset(): void;
|
|
5
|
-
__test__getState(): import("./vis_context.types.ts").
|
|
6
|
-
setupSuite(context: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("type-plus").Pick._<import("./vis_context.types.ts").
|
|
7
|
-
getSnapshotInfo(
|
|
5
|
+
__test__getState(context: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("./vis_context.types.ts").VisProjectState>;
|
|
6
|
+
setupSuite(context: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("type-plus").Pick._<import("./vis_context.types.ts").VisProjectState, "subjectDataTestId">>;
|
|
7
|
+
getSnapshotInfo(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, name: string, isAutoSnapshot: boolean, options?: {
|
|
8
8
|
snapshotFileId?: string | undefined;
|
|
9
|
-
}): {
|
|
9
|
+
}): Promise<{
|
|
10
10
|
baselinePath: string;
|
|
11
11
|
resultPath: string;
|
|
12
12
|
diffPath: string;
|
|
@@ -32,16 +32,17 @@ export declare const visContext: {
|
|
|
32
32
|
diffColorAlt?: [number, number, number] | undefined;
|
|
33
33
|
diffMask?: boolean | undefined;
|
|
34
34
|
} | undefined;
|
|
35
|
-
}
|
|
36
|
-
getTaskCount(
|
|
37
|
-
hasImageSnapshot(
|
|
38
|
-
getSnapshotFilename(info: {
|
|
35
|
+
}>;
|
|
36
|
+
getTaskCount(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, taskId: string): Promise<number>;
|
|
37
|
+
hasImageSnapshot(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, taskId: string, snapshotFileId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>;
|
|
38
|
+
getSnapshotFilename(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, info: {
|
|
39
39
|
taskId: string;
|
|
40
40
|
task: {
|
|
41
41
|
count: number;
|
|
42
42
|
};
|
|
43
43
|
}, snapshotFileId: string | undefined, isAutoSnapshot: boolean): string;
|
|
44
|
-
getSuiteInfo(
|
|
44
|
+
getSuiteInfo(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, taskId: string): Promise<{
|
|
45
|
+
projectRoot: string;
|
|
45
46
|
suiteId: string;
|
|
46
47
|
taskId: string;
|
|
47
48
|
baselineDir: string;
|
|
@@ -50,6 +51,6 @@ export declare const visContext: {
|
|
|
50
51
|
task: {
|
|
51
52
|
count: number;
|
|
52
53
|
};
|
|
53
|
-
}
|
|
54
|
+
}>;
|
|
54
55
|
};
|
|
55
56
|
//# sourceMappingURL=vis_context.d.ts.map
|
|
@@ -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;;;;;;;sBACq6D,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADj5D,CAAA"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { VisOptions } from '../config/types.ts';
|
|
2
|
-
import type { PartialBrowserCommandContext,
|
|
2
|
+
import type { PartialBrowserCommandContext, VisProjectState } from './vis_context.types.ts';
|
|
3
3
|
export declare function createVisContext(): {
|
|
4
|
-
setOptions<M extends "pixel" | "ssim">(options?: VisOptions<M>): void;
|
|
5
|
-
__test__getOptions(): VisOptions<any
|
|
4
|
+
setOptions<M extends "pixel" | "ssim">(projectName: string | undefined, options?: VisOptions<M>): void;
|
|
5
|
+
__test__getOptions(projectName: string): VisOptions<any> | undefined;
|
|
6
6
|
__test__reset(): void;
|
|
7
|
-
__test__getState():
|
|
7
|
+
__test__getState(context: PartialBrowserCommandContext): Promise<VisProjectState>;
|
|
8
8
|
/**
|
|
9
9
|
* Setup suite is called on each test file's beforeAll hook.
|
|
10
10
|
* Test files include vitest test files and storybook story files.
|
|
11
11
|
* It needs to make sure there is no race condition between the test files.
|
|
12
12
|
*/
|
|
13
|
-
setupSuite(context: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<
|
|
14
|
-
getSnapshotInfo(
|
|
13
|
+
setupSuite(context: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<VisProjectState, "subjectDataTestId">>;
|
|
14
|
+
getSnapshotInfo(browserContext: PartialBrowserCommandContext, name: string, isAutoSnapshot: boolean, options?: {
|
|
15
15
|
snapshotFileId?: string | undefined;
|
|
16
|
-
}): {
|
|
16
|
+
}): Promise<{
|
|
17
17
|
baselinePath: string;
|
|
18
18
|
resultPath: string;
|
|
19
19
|
diffPath: string;
|
|
@@ -39,16 +39,17 @@ export declare function createVisContext(): {
|
|
|
39
39
|
diffColorAlt?: [number, number, number] | undefined;
|
|
40
40
|
diffMask?: boolean | undefined;
|
|
41
41
|
} | undefined;
|
|
42
|
-
}
|
|
43
|
-
getTaskCount(
|
|
44
|
-
hasImageSnapshot(
|
|
45
|
-
getSnapshotFilename(info: {
|
|
42
|
+
}>;
|
|
43
|
+
getTaskCount(browserContext: PartialBrowserCommandContext, taskId: string): Promise<number>;
|
|
44
|
+
hasImageSnapshot(browserContext: PartialBrowserCommandContext, taskId: string, snapshotFileId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>;
|
|
45
|
+
getSnapshotFilename(browserContext: PartialBrowserCommandContext, info: {
|
|
46
46
|
taskId: string;
|
|
47
47
|
task: {
|
|
48
48
|
count: number;
|
|
49
49
|
};
|
|
50
50
|
}, snapshotFileId: string | undefined, isAutoSnapshot: boolean): string;
|
|
51
|
-
getSuiteInfo(
|
|
51
|
+
getSuiteInfo(browserContext: PartialBrowserCommandContext, taskId: string): Promise<{
|
|
52
|
+
projectRoot: string;
|
|
52
53
|
suiteId: string;
|
|
53
54
|
taskId: string;
|
|
54
55
|
baselineDir: string;
|
|
@@ -57,9 +58,9 @@ export declare function createVisContext(): {
|
|
|
57
58
|
task: {
|
|
58
59
|
count: number;
|
|
59
60
|
};
|
|
60
|
-
}
|
|
61
|
+
}>;
|
|
61
62
|
};
|
|
62
|
-
export declare function createSuite(state:
|
|
63
|
+
export declare function createSuite(state: VisProjectState, testPath: string, options: Pick<VisOptions, 'customizeSnapshotSubpath'>): {
|
|
63
64
|
suiteId: string;
|
|
64
65
|
suite: {
|
|
65
66
|
baselineDir: string;
|
|
@@ -68,5 +69,5 @@ export declare function createSuite(state: VisState, testPath: string, options:
|
|
|
68
69
|
tasks: {};
|
|
69
70
|
};
|
|
70
71
|
};
|
|
71
|
-
export declare function getSuiteId(state:
|
|
72
|
+
export declare function getSuiteId(state: VisProjectState, testPath: string, options: Pick<VisOptions, 'customizeSnapshotSubpath'>): string;
|
|
72
73
|
//# sourceMappingURL=vis_context.logic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAMpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,eAAe,EAAY,MAAM,wBAAwB,CAAA;AAErG,wBAAgB,gBAAgB;eAKnB,CAAC,SAAS,OAAO,GAAG,MAAM,eAAe,MAAM,GAAG,SAAS,YAAW,UAAU,CAAC,CAAC,CAAC;oCAG9D,MAAM;;8BAOZ,4BAA4B;IAItD;;;;OAIG;wBACuB,4BAA4B;oCAgBrC,4BAA4B,QACtC,MAAM,kBACI,OAAO,YACb;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA+Bf,4BAA4B,UAAU,MAAM;qCAI9D,4BAA4B,UACpC,MAAM,kBACE,MAAM,GAAG,SAAS,kBAClB,OAAO;wCAaP,4BAA4B,QACtC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBACjC,MAAM,GAAG,SAAS,kBAClB,OAAO;iCAWW,4BAA4B,UAAU,MAAM;;;;;;;;;;;EAmBhF;AAyBD,wBAAgB,WAAW,CAC1B,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC;;;;;;;;EAYrD;AAED,wBAAgB,UAAU,CACzB,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC,UAGrD"}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { join, relative } from 'pathe';
|
|
1
|
+
import { join, relative, resolve } from 'pathe';
|
|
2
2
|
import { pick } from 'type-plus';
|
|
3
3
|
import { BASELINE_DIR, DIFF_DIR, RESULT_DIR } from "../shared/constants.js";
|
|
4
|
+
import { getProjectName } from "./commands/browser_command_context.js";
|
|
4
5
|
import { file } from "./file.js";
|
|
5
6
|
import { getSnapshotSubpath, resolveSnapshotRootDir } from "./snapshot_path.js";
|
|
6
7
|
import { ctx } from "./vis_context.ctx.js";
|
|
7
8
|
export function createVisContext() {
|
|
8
|
-
let
|
|
9
|
-
let state;
|
|
10
|
-
let globalStateReady;
|
|
9
|
+
let visOptionsRecord = {};
|
|
10
|
+
let state = {};
|
|
11
11
|
const context = {
|
|
12
|
-
setOptions(options = {}) {
|
|
13
|
-
|
|
12
|
+
setOptions(projectName, options = {}) {
|
|
13
|
+
visOptionsRecord[projectName ?? '__default'] = options;
|
|
14
14
|
},
|
|
15
|
-
__test__getOptions() {
|
|
16
|
-
return
|
|
15
|
+
__test__getOptions(projectName) {
|
|
16
|
+
return visOptionsRecord[projectName];
|
|
17
17
|
},
|
|
18
18
|
__test__reset() {
|
|
19
|
-
|
|
19
|
+
visOptionsRecord = {};
|
|
20
|
+
state = {};
|
|
20
21
|
},
|
|
21
|
-
__test__getState() {
|
|
22
|
-
|
|
22
|
+
__test__getState(context) {
|
|
23
|
+
const projectRoot = getProjectRoot(context);
|
|
24
|
+
return state[projectRoot];
|
|
23
25
|
},
|
|
24
26
|
/**
|
|
25
27
|
* Setup suite is called on each test file's beforeAll hook.
|
|
@@ -27,55 +29,56 @@ export function createVisContext() {
|
|
|
27
29
|
* It needs to make sure there is no race condition between the test files.
|
|
28
30
|
*/
|
|
29
31
|
async setupSuite(context) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
state =
|
|
32
|
+
const projectRoot = getProjectRoot(context);
|
|
33
|
+
if (!state[projectRoot]) {
|
|
34
|
+
state[projectRoot] = setupState(context, getVisOptions(visOptionsRecord, context) ?? {});
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const { suiteId, suite } = createSuite(state, context.testPath, visOptions);
|
|
38
|
-
state.suites[suiteId] = suite;
|
|
36
|
+
const projectState = await state[projectRoot];
|
|
37
|
+
const { suiteId, suite } = createSuite(projectState, context.testPath, visOptionsRecord);
|
|
38
|
+
projectState.suites[suiteId] = suite;
|
|
39
39
|
await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)]);
|
|
40
|
-
return pick(
|
|
40
|
+
return pick(projectState, 'subjectDataTestId');
|
|
41
41
|
},
|
|
42
|
-
getSnapshotInfo(
|
|
43
|
-
const suiteInfo = context.getSuiteInfo(
|
|
44
|
-
const snapshotFilename = context.getSnapshotFilename(suiteInfo, options?.snapshotFileId, isAutoSnapshot);
|
|
42
|
+
async getSnapshotInfo(browserContext, name, isAutoSnapshot, options) {
|
|
43
|
+
const suiteInfo = await context.getSuiteInfo(browserContext, name);
|
|
44
|
+
const snapshotFilename = context.getSnapshotFilename(browserContext, suiteInfo, options?.snapshotFileId, isAutoSnapshot);
|
|
45
45
|
const { baselineDir, resultDir, diffDir, task } = suiteInfo;
|
|
46
46
|
task.count = task.count + 1;
|
|
47
47
|
const baselinePath = join(baselineDir, snapshotFilename);
|
|
48
48
|
const resultPath = join(resultDir, snapshotFilename);
|
|
49
49
|
const diffPath = join(diffDir, snapshotFilename);
|
|
50
50
|
return {
|
|
51
|
-
...pick(
|
|
51
|
+
...pick(getVisOptions(visOptionsRecord, browserContext), 'comparisonMethod', 'diffOptions', 'failureThreshold', 'failureThresholdType', 'timeout'),
|
|
52
52
|
baselinePath,
|
|
53
53
|
resultPath,
|
|
54
54
|
diffPath,
|
|
55
55
|
};
|
|
56
56
|
},
|
|
57
|
-
getTaskCount(
|
|
58
|
-
return context.getSuiteInfo(
|
|
57
|
+
async getTaskCount(browserContext, taskId) {
|
|
58
|
+
return (await context.getSuiteInfo(browserContext, taskId)).task.count;
|
|
59
59
|
},
|
|
60
|
-
hasImageSnapshot(
|
|
61
|
-
const info = context.getSuiteInfo(
|
|
62
|
-
return file.existFile(
|
|
60
|
+
async hasImageSnapshot(browserContext, taskId, snapshotFileId, isAutoSnapshot) {
|
|
61
|
+
const info = await context.getSuiteInfo(browserContext, taskId);
|
|
62
|
+
return file.existFile(resolve(info.projectRoot, info.baselineDir, context.getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot)));
|
|
63
63
|
},
|
|
64
|
-
getSnapshotFilename(info, snapshotFileId, isAutoSnapshot) {
|
|
64
|
+
getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot) {
|
|
65
65
|
if (snapshotFileId)
|
|
66
66
|
return `${snapshotFileId}.png`;
|
|
67
|
-
const customizeSnapshotId =
|
|
67
|
+
const customizeSnapshotId = getVisOptions(visOptionsRecord, browserContext).customizeSnapshotId ?? (({ id, index }) => `${id}-${index}`);
|
|
68
68
|
return `${customizeSnapshotId({
|
|
69
69
|
id: info.taskId,
|
|
70
70
|
index: info.task.count,
|
|
71
71
|
isAutoSnapshot,
|
|
72
72
|
})}.png`;
|
|
73
73
|
},
|
|
74
|
-
getSuiteInfo(
|
|
75
|
-
const
|
|
76
|
-
const
|
|
74
|
+
async getSuiteInfo(browserContext, taskId) {
|
|
75
|
+
const projectRoot = getProjectRoot(browserContext);
|
|
76
|
+
const projectState = await state[projectRoot];
|
|
77
|
+
const suiteId = getSuiteId(projectState, browserContext.testPath, visOptionsRecord);
|
|
78
|
+
const suite = projectState.suites[suiteId];
|
|
77
79
|
const task = (suite.tasks[taskId] = suite.tasks[taskId] ?? { count: 1 });
|
|
78
80
|
return {
|
|
81
|
+
projectRoot,
|
|
79
82
|
suiteId,
|
|
80
83
|
taskId,
|
|
81
84
|
baselineDir: suite.baselineDir,
|
|
@@ -87,18 +90,18 @@ export function createVisContext() {
|
|
|
87
90
|
};
|
|
88
91
|
return context;
|
|
89
92
|
}
|
|
90
|
-
async function setupState(
|
|
91
|
-
const snapshotRootDir = resolveSnapshotRootDir(
|
|
92
|
-
const
|
|
93
|
+
async function setupState(browserContext, visOptions) {
|
|
94
|
+
const snapshotRootDir = resolveSnapshotRootDir(browserContext, visOptions);
|
|
95
|
+
const projectRoot = getProjectRoot(browserContext);
|
|
93
96
|
const state = {
|
|
94
|
-
|
|
95
|
-
testTimeout:
|
|
96
|
-
hookTimeout:
|
|
97
|
+
projectRoot,
|
|
98
|
+
testTimeout: browserContext.project.config.testTimeout,
|
|
99
|
+
hookTimeout: browserContext.project.config.hookTimeout,
|
|
97
100
|
snapshotRootDir,
|
|
98
101
|
snapshotBaselineDir: join(snapshotRootDir, BASELINE_DIR),
|
|
99
102
|
snapshotResultDir: join(snapshotRootDir, RESULT_DIR),
|
|
100
103
|
snapshotDiffDir: join(snapshotRootDir, DIFF_DIR),
|
|
101
|
-
snapshotRootPath: join(
|
|
104
|
+
snapshotRootPath: join(projectRoot, snapshotRootDir),
|
|
102
105
|
subjectDataTestId: visOptions.subjectDataTestId,
|
|
103
106
|
suites: {},
|
|
104
107
|
};
|
|
@@ -118,5 +121,11 @@ export function createSuite(state, testPath, options) {
|
|
|
118
121
|
};
|
|
119
122
|
}
|
|
120
123
|
export function getSuiteId(state, testPath, options) {
|
|
121
|
-
return getSnapshotSubpath(relative(state.
|
|
124
|
+
return getSnapshotSubpath(relative(state.projectRoot, testPath), options);
|
|
125
|
+
}
|
|
126
|
+
function getVisOptions(visOptionsRecord, context) {
|
|
127
|
+
return visOptionsRecord[getProjectName(context) ?? '__default'];
|
|
128
|
+
}
|
|
129
|
+
function getProjectRoot(context) {
|
|
130
|
+
return context.project.config.root;
|
|
122
131
|
}
|