vitest-plugin-vis 2.3.3 → 2.4.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 +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 +0 -1
- package/esm/config/vis.d.ts.map +1 -1
- package/esm/server/commands/browser_command_context.d.ts +1 -1
- package/esm/server/commands/browser_command_context.d.ts.map +1 -1
- 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/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 +12 -11
- package/esm/server/vis_context.d.ts.map +1 -1
- package/esm/server/vis_context.logic.d.ts +15 -14
- package/esm/server/vis_context.logic.d.ts.map +1 -1
- package/esm/server/vis_context.logic.js +39 -32
- package/esm/server/vis_context.types.d.ts +11 -7
- package/esm/server/vis_context.types.d.ts.map +1 -1
- package/esm/setup/vis.d.ts +1 -1
- package/esm/setup/vis.d.ts.map +1 -1
- package/package.json +11 -8
- 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/server/commands/browser_command_context.ts +1 -1
- package/src/server/commands/extend.ts +0 -3
- 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 -6
- package/src/server/snapshot_path.ts +2 -2
- package/src/server/vis_context.logic.ts +62 -35
- package/src/server/vis_context.types.ts +13 -8
- 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
|
@@ -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;;;;;sBAWxE,MAAM
|
|
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"}
|
|
@@ -1 +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,EAAE,MAAM,CAAA;iBAAE,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,
|
|
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 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, taskId, isAutoSnapshot, options);
|
|
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) {
|
|
@@ -2,26 +2,24 @@ export declare const visContext: {
|
|
|
2
2
|
setOptions<M extends "pixel" | "ssim">(projectName: string | undefined, options?: import("../config.ts").VisOptions<M>): void;
|
|
3
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").
|
|
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
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;
|
|
13
13
|
timeout?: number | undefined | undefined;
|
|
14
|
-
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
15
|
-
failureThreshold?: number | undefined | undefined;
|
|
16
14
|
comparisonMethod: any;
|
|
17
15
|
diffOptions?: Partial<import("ssim.js").Options> | undefined;
|
|
16
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
17
|
+
failureThreshold?: number | undefined | undefined;
|
|
18
18
|
} | {
|
|
19
19
|
baselinePath: string;
|
|
20
20
|
resultPath: string;
|
|
21
21
|
diffPath: string;
|
|
22
22
|
timeout?: number | undefined | undefined;
|
|
23
|
-
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
24
|
-
failureThreshold?: number | undefined | undefined;
|
|
25
23
|
comparisonMethod?: any;
|
|
26
24
|
diffOptions?: {
|
|
27
25
|
threshold?: number | undefined;
|
|
@@ -32,8 +30,10 @@ export declare const visContext: {
|
|
|
32
30
|
diffColorAlt?: [number, number, number] | undefined;
|
|
33
31
|
diffMask?: boolean | undefined;
|
|
34
32
|
} | undefined;
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
34
|
+
failureThreshold?: number | undefined | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
getTaskCount(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, taskId: string): Promise<number>;
|
|
37
37
|
hasImageSnapshot(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, taskId: string, snapshotFileId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>;
|
|
38
38
|
getSnapshotFilename(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, info: {
|
|
39
39
|
taskId: string;
|
|
@@ -41,7 +41,8 @@ export declare const visContext: {
|
|
|
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;;;;;;;sBACs3D,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADl2D,CAAA"}
|
|
@@ -1,34 +1,32 @@
|
|
|
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
4
|
setOptions<M extends "pixel" | "ssim">(projectName: string | undefined, options?: VisOptions<M>): void;
|
|
5
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._<
|
|
13
|
+
setupSuite(context: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<VisProjectState, "subjectDataTestId">>;
|
|
14
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;
|
|
20
20
|
timeout?: number | undefined | undefined;
|
|
21
|
-
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
22
|
-
failureThreshold?: number | undefined | undefined;
|
|
23
21
|
comparisonMethod: any;
|
|
24
22
|
diffOptions?: Partial<import("ssim.js").Options> | undefined;
|
|
23
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
24
|
+
failureThreshold?: number | undefined | undefined;
|
|
25
25
|
} | {
|
|
26
26
|
baselinePath: string;
|
|
27
27
|
resultPath: string;
|
|
28
28
|
diffPath: string;
|
|
29
29
|
timeout?: number | undefined | undefined;
|
|
30
|
-
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
31
|
-
failureThreshold?: number | undefined | undefined;
|
|
32
30
|
comparisonMethod?: any;
|
|
33
31
|
diffOptions?: {
|
|
34
32
|
threshold?: number | undefined;
|
|
@@ -39,8 +37,10 @@ export declare function createVisContext(): {
|
|
|
39
37
|
diffColorAlt?: [number, number, number] | undefined;
|
|
40
38
|
diffMask?: boolean | undefined;
|
|
41
39
|
} | undefined;
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
failureThresholdType?: "pixel" | "percent" | undefined | undefined;
|
|
41
|
+
failureThreshold?: number | undefined | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
getTaskCount(browserContext: PartialBrowserCommandContext, taskId: string): Promise<number>;
|
|
44
44
|
hasImageSnapshot(browserContext: PartialBrowserCommandContext, taskId: string, snapshotFileId: string | undefined, isAutoSnapshot: boolean): Promise<boolean>;
|
|
45
45
|
getSnapshotFilename(browserContext: PartialBrowserCommandContext, info: {
|
|
46
46
|
taskId: string;
|
|
@@ -48,7 +48,8 @@ export declare function createVisContext(): {
|
|
|
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;AAMpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,
|
|
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;IAGtD;;;;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,4 +1,4 @@
|
|
|
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
4
|
import { getProjectName } from "./commands/browser_command_context.js";
|
|
@@ -7,8 +7,7 @@ import { getSnapshotSubpath, resolveSnapshotRootDir } from "./snapshot_path.js";
|
|
|
7
7
|
import { ctx } from "./vis_context.ctx.js";
|
|
8
8
|
export function createVisContext() {
|
|
9
9
|
let visOptionsRecord = {};
|
|
10
|
-
let state;
|
|
11
|
-
let globalStateReady;
|
|
10
|
+
let state = {};
|
|
12
11
|
const context = {
|
|
13
12
|
setOptions(projectName, options = {}) {
|
|
14
13
|
visOptionsRecord[projectName ?? '__default'] = options;
|
|
@@ -18,9 +17,10 @@ export function createVisContext() {
|
|
|
18
17
|
},
|
|
19
18
|
__test__reset() {
|
|
20
19
|
visOptionsRecord = {};
|
|
20
|
+
state = {};
|
|
21
21
|
},
|
|
22
|
-
__test__getState() {
|
|
23
|
-
return state;
|
|
22
|
+
__test__getState(context) {
|
|
23
|
+
return state[getProjectId(context)];
|
|
24
24
|
},
|
|
25
25
|
/**
|
|
26
26
|
* Setup suite is called on each test file's beforeAll hook.
|
|
@@ -28,20 +28,18 @@ export function createVisContext() {
|
|
|
28
28
|
* It needs to make sure there is no race condition between the test files.
|
|
29
29
|
*/
|
|
30
30
|
async setupSuite(context) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
state =
|
|
31
|
+
const projectId = getProjectId(context);
|
|
32
|
+
if (!state[projectId]) {
|
|
33
|
+
state[projectId] = setupState(context, getVisOptions(visOptionsRecord, context) ?? {});
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const { suiteId, suite } = createSuite(state, context.testPath, visOptionsRecord);
|
|
39
|
-
state.suites[suiteId] = suite;
|
|
35
|
+
const projectState = await state[projectId];
|
|
36
|
+
const { suiteId, suite } = createSuite(projectState, context.testPath, visOptionsRecord);
|
|
37
|
+
projectState.suites[suiteId] = suite;
|
|
40
38
|
await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)]);
|
|
41
|
-
return pick(
|
|
39
|
+
return pick(projectState, 'subjectDataTestId');
|
|
42
40
|
},
|
|
43
|
-
getSnapshotInfo(browserContext, name, isAutoSnapshot, options) {
|
|
44
|
-
const suiteInfo = context.getSuiteInfo(browserContext
|
|
41
|
+
async getSnapshotInfo(browserContext, name, isAutoSnapshot, options) {
|
|
42
|
+
const suiteInfo = await context.getSuiteInfo(browserContext, name);
|
|
45
43
|
const snapshotFilename = context.getSnapshotFilename(browserContext, suiteInfo, options?.snapshotFileId, isAutoSnapshot);
|
|
46
44
|
const { baselineDir, resultDir, diffDir, task } = suiteInfo;
|
|
47
45
|
task.count = task.count + 1;
|
|
@@ -55,12 +53,12 @@ export function createVisContext() {
|
|
|
55
53
|
diffPath,
|
|
56
54
|
};
|
|
57
55
|
},
|
|
58
|
-
getTaskCount(
|
|
59
|
-
return context.getSuiteInfo(
|
|
56
|
+
async getTaskCount(browserContext, taskId) {
|
|
57
|
+
return (await context.getSuiteInfo(browserContext, taskId)).task.count;
|
|
60
58
|
},
|
|
61
|
-
hasImageSnapshot(browserContext, taskId, snapshotFileId, isAutoSnapshot) {
|
|
62
|
-
const info = context.getSuiteInfo(browserContext
|
|
63
|
-
return file.existFile(
|
|
59
|
+
async hasImageSnapshot(browserContext, taskId, snapshotFileId, isAutoSnapshot) {
|
|
60
|
+
const info = await context.getSuiteInfo(browserContext, taskId);
|
|
61
|
+
return file.existFile(resolve(info.projectRoot, info.baselineDir, context.getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot)));
|
|
64
62
|
},
|
|
65
63
|
getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot) {
|
|
66
64
|
if (snapshotFileId)
|
|
@@ -72,11 +70,14 @@ export function createVisContext() {
|
|
|
72
70
|
isAutoSnapshot,
|
|
73
71
|
})}.png`;
|
|
74
72
|
},
|
|
75
|
-
getSuiteInfo(
|
|
76
|
-
const
|
|
77
|
-
const
|
|
73
|
+
async getSuiteInfo(browserContext, taskId) {
|
|
74
|
+
const projectId = getProjectId(browserContext);
|
|
75
|
+
const projectState = await state[projectId];
|
|
76
|
+
const suiteId = getSuiteId(projectState, browserContext.testPath, visOptionsRecord);
|
|
77
|
+
const suite = projectState.suites[suiteId];
|
|
78
78
|
const task = (suite.tasks[taskId] = suite.tasks[taskId] ?? { count: 1 });
|
|
79
79
|
return {
|
|
80
|
+
projectRoot: projectState.projectRoot,
|
|
80
81
|
suiteId,
|
|
81
82
|
taskId,
|
|
82
83
|
baselineDir: suite.baselineDir,
|
|
@@ -88,18 +89,18 @@ export function createVisContext() {
|
|
|
88
89
|
};
|
|
89
90
|
return context;
|
|
90
91
|
}
|
|
91
|
-
async function setupState(
|
|
92
|
-
const snapshotRootDir = resolveSnapshotRootDir(
|
|
93
|
-
const
|
|
92
|
+
async function setupState(browserContext, visOptions) {
|
|
93
|
+
const snapshotRootDir = resolveSnapshotRootDir(browserContext, visOptions);
|
|
94
|
+
const projectRoot = getProjectRoot(browserContext);
|
|
94
95
|
const state = {
|
|
95
|
-
|
|
96
|
-
testTimeout:
|
|
97
|
-
hookTimeout:
|
|
96
|
+
projectRoot,
|
|
97
|
+
testTimeout: browserContext.project.config.testTimeout,
|
|
98
|
+
hookTimeout: browserContext.project.config.hookTimeout,
|
|
98
99
|
snapshotRootDir,
|
|
99
100
|
snapshotBaselineDir: join(snapshotRootDir, BASELINE_DIR),
|
|
100
101
|
snapshotResultDir: join(snapshotRootDir, RESULT_DIR),
|
|
101
102
|
snapshotDiffDir: join(snapshotRootDir, DIFF_DIR),
|
|
102
|
-
snapshotRootPath: join(
|
|
103
|
+
snapshotRootPath: join(projectRoot, snapshotRootDir),
|
|
103
104
|
subjectDataTestId: visOptions.subjectDataTestId,
|
|
104
105
|
suites: {},
|
|
105
106
|
};
|
|
@@ -119,8 +120,14 @@ export function createSuite(state, testPath, options) {
|
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
export function getSuiteId(state, testPath, options) {
|
|
122
|
-
return getSnapshotSubpath(relative(state.
|
|
123
|
+
return getSnapshotSubpath(relative(state.projectRoot, testPath), options);
|
|
123
124
|
}
|
|
124
125
|
function getVisOptions(visOptionsRecord, context) {
|
|
125
126
|
return visOptionsRecord[getProjectName(context) ?? '__default'];
|
|
126
127
|
}
|
|
128
|
+
function getProjectRoot(context) {
|
|
129
|
+
return context.project.config.root;
|
|
130
|
+
}
|
|
131
|
+
function getProjectId(context) {
|
|
132
|
+
return `${context.project.config.root}/${context.project.config.name}`;
|
|
133
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export type VisState = {
|
|
2
|
-
projectPath: string
|
|
2
|
+
[projectPath: string]: Promise<VisProjectState>;
|
|
3
|
+
};
|
|
4
|
+
export type VisProjectState = {
|
|
5
|
+
projectRoot: string;
|
|
3
6
|
testTimeout: number;
|
|
4
7
|
hookTimeout: number;
|
|
5
8
|
snapshotRootDir: string;
|
|
@@ -20,6 +23,7 @@ export type VisState = {
|
|
|
20
23
|
export type PartialBrowserCommandContext = {
|
|
21
24
|
project: {
|
|
22
25
|
config: {
|
|
26
|
+
name: string;
|
|
23
27
|
root: string;
|
|
24
28
|
snapshotOptions: {
|
|
25
29
|
updateSnapshot: 'all' | 'new' | 'none';
|
|
@@ -30,18 +34,18 @@ export type PartialBrowserCommandContext = {
|
|
|
30
34
|
vite: {
|
|
31
35
|
config: {
|
|
32
36
|
test?: {
|
|
33
|
-
name
|
|
37
|
+
name?: string | undefined;
|
|
34
38
|
};
|
|
35
39
|
};
|
|
36
40
|
};
|
|
37
41
|
};
|
|
38
42
|
provider: {
|
|
39
43
|
name: string;
|
|
40
|
-
browserName
|
|
41
|
-
options
|
|
42
|
-
headless
|
|
43
|
-
screenshotFailures
|
|
44
|
-
screenshotDirectory
|
|
44
|
+
browserName?: string | undefined;
|
|
45
|
+
options?: {
|
|
46
|
+
headless?: boolean | undefined;
|
|
47
|
+
screenshotFailures?: boolean | undefined;
|
|
48
|
+
screenshotDirectory?: string | undefined;
|
|
45
49
|
};
|
|
46
50
|
};
|
|
47
51
|
testPath: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vis_context.types.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACtB,WAAW,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"vis_context.types.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACtB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;CAC/C,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC7B,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,MAAM,EAAE,MAAM,CACb,MAAM,EACN;QACC,WAAW,EAAE,MAAM,CAAA;QACnB,SAAS,EAAE,MAAM,CAAA;QACjB,OAAO,EAAE,MAAM,CAAA;QACf,KAAK,EAAE,MAAM,CACZ,MAAM,EACN;YACC,KAAK,EAAE,MAAM,CAAA;SACb,CACD,CAAA;KACD,CACD,CAAA;CACD,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE;QACR,MAAM,EAAE;YACP,IAAI,EAAE,MAAM,CAAA;YACZ,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;QACD,IAAI,EAAE;YACL,MAAM,EAAE;gBACP,IAAI,CAAC,EAAE;oBACN,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;iBACzB,CAAA;aACD,CAAA;SACD,CAAA;KACD,CAAA;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAChC,OAAO,CAAC,EAAE;YACT,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;YAC9B,kBAAkB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;YACxC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;SACxC,CAAA;KACD,CAAA;IACD,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA"}
|
package/esm/setup/vis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Visual test configuration on the client side.
|
|
3
3
|
*/
|
|
4
|
-
export declare const vis: import("./create_vis.ts").VisClientConfigurator<import("../
|
|
4
|
+
export declare const vis: import("./create_vis.ts").VisClientConfigurator<import("../client.ts").SnapshotMeta<import("../client.ts").ComparisonMethod>>;
|
|
5
5
|
//# sourceMappingURL=vis.d.ts.map
|
package/esm/setup/vis.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vis.d.ts","sourceRoot":"","sources":["../../src/setup/vis.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"vis.d.ts","sourceRoot":"","sources":["../../src/setup/vis.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,GAAG,+HAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-plugin-vis",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Vitest visual testing plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image-snapshot",
|
|
@@ -58,6 +58,9 @@
|
|
|
58
58
|
},
|
|
59
59
|
"./package.json": "./package.json"
|
|
60
60
|
},
|
|
61
|
+
"imports": {
|
|
62
|
+
"#vitest-plugin-vis/config": "./src/config.ts"
|
|
63
|
+
},
|
|
61
64
|
"types": "./esm/index.d.ts",
|
|
62
65
|
"files": [
|
|
63
66
|
"esm",
|
|
@@ -80,10 +83,10 @@
|
|
|
80
83
|
"@types/is-ci": "^3.0.4",
|
|
81
84
|
"@types/pngjs": "^6.0.5",
|
|
82
85
|
"@types/react": "^19.0.2",
|
|
83
|
-
"@vitest/browser": "^3.0.
|
|
84
|
-
"@vitest/coverage-istanbul": "^3.0.
|
|
85
|
-
"@vitest/coverage-v8": "^3.0.
|
|
86
|
-
"@vitest/expect": "^3.0.
|
|
86
|
+
"@vitest/browser": "^3.0.8",
|
|
87
|
+
"@vitest/coverage-istanbul": "^3.0.8",
|
|
88
|
+
"@vitest/coverage-v8": "^3.0.8",
|
|
89
|
+
"@vitest/expect": "^3.0.8",
|
|
87
90
|
"cross-env": "^7.0.3",
|
|
88
91
|
"never-fail": "^1.1.4",
|
|
89
92
|
"npm-run-all2": "^7.0.2",
|
|
@@ -92,9 +95,8 @@
|
|
|
92
95
|
"react-dom": "^19.0.0",
|
|
93
96
|
"typescript": "^5.7.2",
|
|
94
97
|
"vite": "^6.0.9",
|
|
95
|
-
"vitest": "^3.0.
|
|
96
|
-
"vitest-browser-react": "^0.1.0"
|
|
97
|
-
"webdriverio": "latest"
|
|
98
|
+
"vitest": "^3.0.8",
|
|
99
|
+
"vitest-browser-react": "^0.1.0"
|
|
98
100
|
},
|
|
99
101
|
"peerDependencies": {
|
|
100
102
|
"@vitest/browser": "^2 || ^3",
|
|
@@ -107,6 +109,7 @@
|
|
|
107
109
|
"build": "tsc",
|
|
108
110
|
"build:watch": "tsc -w",
|
|
109
111
|
"clean": "rimraf coverage esm *.tsbuildinfo vitest.*.timestamp*",
|
|
112
|
+
"clean:vis:local": "rimraf __vis__/local",
|
|
110
113
|
"cov": "cross-env COVERAGE=true vitest run --coverage",
|
|
111
114
|
"coverage": "cross-env COVERAGE=true vitest run --coverage",
|
|
112
115
|
"dev": "run-p build:watch w",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { BrowserCommands } from '@vitest/browser/context'
|
|
1
2
|
import dedent from 'dedent'
|
|
2
3
|
import { resolve } from 'pathe'
|
|
3
4
|
import type { ImageSnapshotNextIndexCommand } from '../commands.ts'
|
|
4
5
|
import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts'
|
|
5
|
-
import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts'
|
|
6
6
|
import { isBase64String } from '../shared/base64.ts'
|
|
7
7
|
import { compareImage } from '../shared/compare_image.ts'
|
|
8
8
|
import type { ToMatchImageSnapshotOptions } from '../shared/types.ts'
|
|
@@ -15,7 +15,7 @@ import { server } from './vitest_browser_context_proxy.ts'
|
|
|
15
15
|
import type { CurrentTest } from './vitest_suite_proxy.ts'
|
|
16
16
|
|
|
17
17
|
export function imageSnapshotMatcher(
|
|
18
|
-
commands:
|
|
18
|
+
commands: BrowserCommands & PrepareImageSnapshotComparisonCommand & ImageSnapshotNextIndexCommand,
|
|
19
19
|
) {
|
|
20
20
|
return async function matchImageSnapshot(
|
|
21
21
|
test: CurrentTest & {},
|
|
@@ -65,11 +65,11 @@ export function imageSnapshotMatcher(
|
|
|
65
65
|
return
|
|
66
66
|
}
|
|
67
67
|
if (server.config.snapshotOptions.updateSnapshot === 'all' && !options?.expectToFail) {
|
|
68
|
-
await writeSnapshot(commands, info.baselinePath, resultImage)
|
|
68
|
+
await writeSnapshot(commands, resolve(info.projectRoot, info.baselinePath), resultImage)
|
|
69
69
|
return
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
await writeSnapshot(commands, info.diffPath, diffImage)
|
|
72
|
+
await writeSnapshot(commands, resolve(info.projectRoot, info.diffPath), diffImage)
|
|
73
73
|
|
|
74
74
|
throw new Error(
|
|
75
75
|
dedent`Snapshot \`${taskId}\` mismatched
|
|
@@ -103,9 +103,9 @@ export function parseImageSnapshotSubject(subject: any) {
|
|
|
103
103
|
)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
async function writeSnapshot(commands:
|
|
106
|
+
async function writeSnapshot(commands: BrowserCommands, path: string, image: ImageData) {
|
|
107
107
|
const content = (await toDataURL(image)).split(',')[1]!
|
|
108
|
-
return commands.
|
|
108
|
+
return commands.writeFile(path, content, { encoding: 'base64' })
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
async function parseImageSnapshotOptions(
|
|
@@ -51,7 +51,7 @@ function parseArgs<M extends ComparisonMethod>(
|
|
|
51
51
|
args: [task: MetaTask, meta: SnapshotMeta<M> | boolean] | [meta: boolean | SnapshotMeta<M>],
|
|
52
52
|
): [MetaTask | undefined, SnapshotMeta<M>] {
|
|
53
53
|
return args.length === 1
|
|
54
|
-
? [ctx.getCurrentTest() ?? (ctx.getCurrentSuite()
|
|
54
|
+
? [ctx.getCurrentTest() ?? (ctx.getCurrentSuite()?.tasks?.[0] as any)?.file, parseMeta(args[0])]
|
|
55
55
|
: [args[0], parseMeta(args[1])]
|
|
56
56
|
}
|
|
57
57
|
|
package/src/commands.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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'
|
package/src/config/types.ts
CHANGED
|
@@ -35,11 +35,11 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
|
|
|
35
35
|
| string
|
|
36
36
|
| ((context: {
|
|
37
37
|
ci: boolean
|
|
38
|
-
browserName
|
|
38
|
+
browserName?: string | undefined
|
|
39
39
|
providerName: string
|
|
40
40
|
platform: string
|
|
41
|
-
screenshotFailures
|
|
42
|
-
screenshotDirectory
|
|
41
|
+
screenshotFailures?: boolean | undefined
|
|
42
|
+
screenshotDirectory?: string | undefined
|
|
43
43
|
}) => string)
|
|
44
44
|
| undefined
|
|
45
45
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BrowserCommandContext } from 'vitest/node'
|
|
2
2
|
|
|
3
|
-
export function getProjectName(context: { project: { vite: { config: { test?: { name
|
|
3
|
+
export function getProjectName(context: { project: { vite: { config: { test?: { name?: string | undefined } } } } }) {
|
|
4
4
|
return context.project.vite.config.test?.name
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
prepareImageSnapshotComparison,
|
|
7
7
|
} from './prepare_image_snapshot_comparison.ts'
|
|
8
8
|
import { type SetupVisSuiteCommand, setupVisSuite } from './setup_vis_suite.ts'
|
|
9
|
-
import { type WriteImageSnapshotCommand, writeImageSnapshot } from './write_image_snapshot.ts'
|
|
10
9
|
|
|
11
10
|
declare module '@vitest/browser/context' {
|
|
12
11
|
interface BrowserCommands
|
|
@@ -14,7 +13,6 @@ declare module '@vitest/browser/context' {
|
|
|
14
13
|
ImageSnapshotNextIndexCommand,
|
|
15
14
|
HasImageSnapshotCommand,
|
|
16
15
|
PrepareImageSnapshotComparisonCommand,
|
|
17
|
-
WriteImageSnapshotCommand,
|
|
18
16
|
MatchImageSnapshotCommand {}
|
|
19
17
|
}
|
|
20
18
|
|
|
@@ -24,5 +22,4 @@ export const commands = {
|
|
|
24
22
|
hasImageSnapshot,
|
|
25
23
|
matchImageSnapshot,
|
|
26
24
|
prepareImageSnapshotComparison,
|
|
27
|
-
writeImageSnapshot,
|
|
28
25
|
}
|
|
@@ -12,5 +12,5 @@ export interface ImageSnapshotNextIndexCommand {
|
|
|
12
12
|
export const imageSnapshotNextIndex: BrowserCommand<[taskId: string]> = async (context, taskId) => {
|
|
13
13
|
assertTestPathDefined(context, 'imageSnapshotNextIndex')
|
|
14
14
|
|
|
15
|
-
return visContext.getTaskCount(context
|
|
15
|
+
return visContext.getTaskCount(context, taskId)
|
|
16
16
|
}
|
|
@@ -43,7 +43,7 @@ export const matchImageSnapshot: BrowserCommand<
|
|
|
43
43
|
if (!options) options = {}
|
|
44
44
|
options.timeout = options.timeout ?? 30000
|
|
45
45
|
|
|
46
|
-
const info = visContext.getSnapshotInfo(context as any, taskId, isAutoSnapshot, options)
|
|
46
|
+
const info = await visContext.getSnapshotInfo(context as any, taskId, isAutoSnapshot, options)
|
|
47
47
|
const baselineBuffer = await file.tryReadFile(info.baselinePath)
|
|
48
48
|
if (!baselineBuffer) {
|
|
49
49
|
if (isBase64String(subject)) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve } from 'pathe'
|
|
1
2
|
import type { BrowserCommand } from 'vitest/node'
|
|
2
3
|
import { isBase64String } from '../../shared/base64.ts'
|
|
3
4
|
import type {
|
|
@@ -13,11 +14,29 @@ import { assertTestPathDefined } from './_assertions.ts'
|
|
|
13
14
|
import type { MatchImageSnapshotOptions } from './match_image_snapshot.ts'
|
|
14
15
|
|
|
15
16
|
type ImageSnapshotComparisonInfo = {
|
|
17
|
+
/**
|
|
18
|
+
* Path to the project root.
|
|
19
|
+
*/
|
|
16
20
|
projectRoot: string
|
|
21
|
+
/**
|
|
22
|
+
* Path to the baseline image relative to the project root.
|
|
23
|
+
*/
|
|
17
24
|
baselinePath: string
|
|
25
|
+
/**
|
|
26
|
+
* Path to the result image relative to the project root.
|
|
27
|
+
*/
|
|
18
28
|
resultPath: string
|
|
29
|
+
/**
|
|
30
|
+
* Path to the diff image relative to the project root.
|
|
31
|
+
*/
|
|
19
32
|
diffPath: string
|
|
33
|
+
/**
|
|
34
|
+
* Base64 encoded baseline image.
|
|
35
|
+
*/
|
|
20
36
|
baseline: string
|
|
37
|
+
/**
|
|
38
|
+
* Base64 encoded result image.
|
|
39
|
+
*/
|
|
21
40
|
result: string
|
|
22
41
|
} & ImageSnapshotTimeoutOptions &
|
|
23
42
|
FailureThresholdOptions &
|
|
@@ -40,21 +59,22 @@ export const prepareImageSnapshotComparison: BrowserCommand<
|
|
|
40
59
|
if (!options) options = {}
|
|
41
60
|
options.timeout = options.timeout ?? 30000
|
|
42
61
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
62
|
+
const projectRoot = context.project.config.root
|
|
63
|
+
const info = await visContext.getSnapshotInfo(context as any, taskId, isAutoSnapshot, options)
|
|
64
|
+
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))
|
|
45
65
|
if (!baselineBuffer) {
|
|
46
66
|
if (isBase64String(subject)) {
|
|
47
|
-
await writeSnapshot(info.baselinePath, subject)
|
|
67
|
+
await writeSnapshot(resolve(projectRoot, info.baselinePath), subject)
|
|
48
68
|
} else {
|
|
49
|
-
await takeSnapshotByBrowser(context, info.baselinePath, subject, options)
|
|
69
|
+
await takeSnapshotByBrowser(context, resolve(projectRoot, info.baselinePath), subject, options)
|
|
50
70
|
}
|
|
51
71
|
return
|
|
52
72
|
}
|
|
53
73
|
|
|
54
|
-
const resultBuffer = await takeSnapshot(context, info.resultPath, subject, options)
|
|
74
|
+
const resultBuffer = await takeSnapshot(context, resolve(projectRoot, info.resultPath), subject, options)
|
|
55
75
|
return {
|
|
56
76
|
...info,
|
|
57
|
-
projectRoot
|
|
77
|
+
projectRoot,
|
|
58
78
|
baseline: baselineBuffer.toString('base64'),
|
|
59
79
|
result: resultBuffer.toString('base64'),
|
|
60
80
|
}
|
|
@@ -13,8 +13,8 @@ export function resolveSnapshotRootDir(suite: PartialBrowserCommandContext, opti
|
|
|
13
13
|
browserName: suite.provider.browserName,
|
|
14
14
|
providerName: suite.provider.name,
|
|
15
15
|
platform: process.platform,
|
|
16
|
-
screenshotFailures: suite.provider.options
|
|
17
|
-
screenshotDirectory: suite.provider.options
|
|
16
|
+
screenshotFailures: suite.provider.options?.screenshotFailures,
|
|
17
|
+
screenshotDirectory: suite.provider.options?.screenshotDirectory,
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, relative } from 'pathe'
|
|
1
|
+
import { join, relative, resolve } from 'pathe'
|
|
2
2
|
import { pick } from 'type-plus'
|
|
3
3
|
import type { VisOptions } from '../config/types.ts'
|
|
4
4
|
import { BASELINE_DIR, DIFF_DIR, RESULT_DIR } from '../shared/constants.ts'
|
|
@@ -6,12 +6,11 @@ import { getProjectName } from './commands/browser_command_context.ts'
|
|
|
6
6
|
import { file } from './file.ts'
|
|
7
7
|
import { getSnapshotSubpath, resolveSnapshotRootDir } from './snapshot_path.ts'
|
|
8
8
|
import { ctx } from './vis_context.ctx.ts'
|
|
9
|
-
import type { PartialBrowserCommandContext, VisState } from './vis_context.types.ts'
|
|
9
|
+
import type { PartialBrowserCommandContext, VisProjectState, VisState } from './vis_context.types.ts'
|
|
10
10
|
|
|
11
11
|
export function createVisContext() {
|
|
12
12
|
let visOptionsRecord: Record<string, VisOptions<any>> = {}
|
|
13
|
-
let state: VisState
|
|
14
|
-
let globalStateReady: Promise<VisState>
|
|
13
|
+
let state: VisState = {}
|
|
15
14
|
|
|
16
15
|
const context = {
|
|
17
16
|
setOptions<M extends 'pixel' | 'ssim'>(projectName: string | undefined, options: VisOptions<M> = {} as any) {
|
|
@@ -21,10 +20,11 @@ export function createVisContext() {
|
|
|
21
20
|
return visOptionsRecord[projectName]
|
|
22
21
|
},
|
|
23
22
|
__test__reset() {
|
|
24
|
-
visOptionsRecord = {}
|
|
23
|
+
visOptionsRecord = {}
|
|
24
|
+
state = {}
|
|
25
25
|
},
|
|
26
|
-
__test__getState() {
|
|
27
|
-
return state
|
|
26
|
+
__test__getState(context: PartialBrowserCommandContext) {
|
|
27
|
+
return state[getProjectId(context)]!
|
|
28
28
|
},
|
|
29
29
|
/**
|
|
30
30
|
* Setup suite is called on each test file's beforeAll hook.
|
|
@@ -32,25 +32,27 @@ export function createVisContext() {
|
|
|
32
32
|
* It needs to make sure there is no race condition between the test files.
|
|
33
33
|
*/
|
|
34
34
|
async setupSuite(context: PartialBrowserCommandContext) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
await globalStateReady
|
|
35
|
+
const projectId = getProjectId(context)
|
|
36
|
+
|
|
37
|
+
if (!state[projectId]) {
|
|
38
|
+
state[projectId] = setupState(context, getVisOptions(visOptionsRecord, context) ?? {})
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
const projectState = await state[projectId]
|
|
42
|
+
|
|
43
|
+
const { suiteId, suite } = createSuite(projectState, context.testPath, visOptionsRecord)
|
|
44
|
+
projectState.suites[suiteId] = suite
|
|
45
|
+
|
|
44
46
|
await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)])
|
|
45
|
-
return pick(
|
|
47
|
+
return pick(projectState, 'subjectDataTestId')
|
|
46
48
|
},
|
|
47
|
-
getSnapshotInfo(
|
|
49
|
+
async getSnapshotInfo(
|
|
48
50
|
browserContext: PartialBrowserCommandContext,
|
|
49
51
|
name: string,
|
|
50
52
|
isAutoSnapshot: boolean,
|
|
51
53
|
options?: { snapshotFileId?: string | undefined },
|
|
52
54
|
) {
|
|
53
|
-
const suiteInfo = context.getSuiteInfo(browserContext
|
|
55
|
+
const suiteInfo = await context.getSuiteInfo(browserContext, name)
|
|
54
56
|
const snapshotFilename = context.getSnapshotFilename(
|
|
55
57
|
browserContext,
|
|
56
58
|
suiteInfo,
|
|
@@ -79,18 +81,23 @@ export function createVisContext() {
|
|
|
79
81
|
diffPath,
|
|
80
82
|
}
|
|
81
83
|
},
|
|
82
|
-
getTaskCount(
|
|
83
|
-
return context.getSuiteInfo(
|
|
84
|
+
async getTaskCount(browserContext: PartialBrowserCommandContext, taskId: string) {
|
|
85
|
+
return (await context.getSuiteInfo(browserContext, taskId)).task.count
|
|
84
86
|
},
|
|
85
|
-
hasImageSnapshot(
|
|
87
|
+
async hasImageSnapshot(
|
|
86
88
|
browserContext: PartialBrowserCommandContext,
|
|
87
89
|
taskId: string,
|
|
88
90
|
snapshotFileId: string | undefined,
|
|
89
91
|
isAutoSnapshot: boolean,
|
|
90
92
|
) {
|
|
91
|
-
const info = context.getSuiteInfo(browserContext
|
|
93
|
+
const info = await context.getSuiteInfo(browserContext, taskId)
|
|
94
|
+
|
|
92
95
|
return file.existFile(
|
|
93
|
-
|
|
96
|
+
resolve(
|
|
97
|
+
info.projectRoot,
|
|
98
|
+
info.baselineDir,
|
|
99
|
+
context.getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot),
|
|
100
|
+
),
|
|
94
101
|
)
|
|
95
102
|
},
|
|
96
103
|
getSnapshotFilename(
|
|
@@ -108,11 +115,15 @@ export function createVisContext() {
|
|
|
108
115
|
isAutoSnapshot,
|
|
109
116
|
})}.png`
|
|
110
117
|
},
|
|
111
|
-
getSuiteInfo(
|
|
112
|
-
const
|
|
113
|
-
const
|
|
118
|
+
async getSuiteInfo(browserContext: PartialBrowserCommandContext, taskId: string) {
|
|
119
|
+
const projectId = getProjectId(browserContext)
|
|
120
|
+
const projectState = await state[projectId]!
|
|
121
|
+
|
|
122
|
+
const suiteId = getSuiteId(projectState, browserContext.testPath, visOptionsRecord)
|
|
123
|
+
const suite = projectState.suites[suiteId]!
|
|
114
124
|
const task = (suite.tasks[taskId] = suite.tasks[taskId] ?? { count: 1 })
|
|
115
125
|
return {
|
|
126
|
+
projectRoot: projectState.projectRoot,
|
|
116
127
|
suiteId,
|
|
117
128
|
taskId,
|
|
118
129
|
baselineDir: suite.baselineDir,
|
|
@@ -126,21 +137,21 @@ export function createVisContext() {
|
|
|
126
137
|
}
|
|
127
138
|
|
|
128
139
|
async function setupState(
|
|
129
|
-
|
|
140
|
+
browserContext: PartialBrowserCommandContext,
|
|
130
141
|
visOptions: Pick<VisOptions, 'snapshotRootDir' | 'platform' | 'subjectDataTestId'>,
|
|
131
142
|
) {
|
|
132
|
-
const snapshotRootDir = resolveSnapshotRootDir(
|
|
133
|
-
const
|
|
143
|
+
const snapshotRootDir = resolveSnapshotRootDir(browserContext, visOptions)
|
|
144
|
+
const projectRoot = getProjectRoot(browserContext)
|
|
134
145
|
|
|
135
146
|
const state = {
|
|
136
|
-
|
|
137
|
-
testTimeout:
|
|
138
|
-
hookTimeout:
|
|
147
|
+
projectRoot,
|
|
148
|
+
testTimeout: browserContext.project.config.testTimeout,
|
|
149
|
+
hookTimeout: browserContext.project.config.hookTimeout,
|
|
139
150
|
snapshotRootDir,
|
|
140
151
|
snapshotBaselineDir: join(snapshotRootDir, BASELINE_DIR),
|
|
141
152
|
snapshotResultDir: join(snapshotRootDir, RESULT_DIR),
|
|
142
153
|
snapshotDiffDir: join(snapshotRootDir, DIFF_DIR),
|
|
143
|
-
snapshotRootPath: join(
|
|
154
|
+
snapshotRootPath: join(projectRoot, snapshotRootDir),
|
|
144
155
|
subjectDataTestId: visOptions.subjectDataTestId,
|
|
145
156
|
suites: {},
|
|
146
157
|
}
|
|
@@ -148,7 +159,11 @@ async function setupState(
|
|
|
148
159
|
return state
|
|
149
160
|
}
|
|
150
161
|
|
|
151
|
-
export function createSuite(
|
|
162
|
+
export function createSuite(
|
|
163
|
+
state: VisProjectState,
|
|
164
|
+
testPath: string,
|
|
165
|
+
options: Pick<VisOptions, 'customizeSnapshotSubpath'>,
|
|
166
|
+
) {
|
|
152
167
|
const suiteId = getSuiteId(state, testPath, options)
|
|
153
168
|
return {
|
|
154
169
|
suiteId,
|
|
@@ -161,10 +176,22 @@ export function createSuite(state: VisState, testPath: string, options: Pick<Vis
|
|
|
161
176
|
}
|
|
162
177
|
}
|
|
163
178
|
|
|
164
|
-
export function getSuiteId(
|
|
165
|
-
|
|
179
|
+
export function getSuiteId(
|
|
180
|
+
state: VisProjectState,
|
|
181
|
+
testPath: string,
|
|
182
|
+
options: Pick<VisOptions, 'customizeSnapshotSubpath'>,
|
|
183
|
+
) {
|
|
184
|
+
return getSnapshotSubpath(relative(state.projectRoot, testPath), options)
|
|
166
185
|
}
|
|
167
186
|
|
|
168
187
|
function getVisOptions(visOptionsRecord: Record<string, VisOptions<any>>, context: PartialBrowserCommandContext) {
|
|
169
188
|
return visOptionsRecord[getProjectName(context) ?? '__default']!
|
|
170
189
|
}
|
|
190
|
+
|
|
191
|
+
function getProjectRoot(context: PartialBrowserCommandContext) {
|
|
192
|
+
return context.project.config.root
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function getProjectId(context: PartialBrowserCommandContext) {
|
|
196
|
+
return `${context.project.config.root}/${context.project.config.name}`
|
|
197
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type VisState = {
|
|
2
|
-
projectPath: string
|
|
3
|
-
|
|
2
|
+
[projectPath: string]: Promise<VisProjectState>
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export type VisProjectState = {
|
|
6
|
+
projectRoot: string
|
|
4
7
|
testTimeout: number
|
|
5
8
|
hookTimeout: number
|
|
6
9
|
snapshotRootDir: string
|
|
@@ -24,9 +27,11 @@ export type VisState = {
|
|
|
24
27
|
}
|
|
25
28
|
>
|
|
26
29
|
}
|
|
30
|
+
|
|
27
31
|
export type PartialBrowserCommandContext = {
|
|
28
32
|
project: {
|
|
29
33
|
config: {
|
|
34
|
+
name: string
|
|
30
35
|
root: string
|
|
31
36
|
snapshotOptions: {
|
|
32
37
|
updateSnapshot: 'all' | 'new' | 'none'
|
|
@@ -37,18 +42,18 @@ export type PartialBrowserCommandContext = {
|
|
|
37
42
|
vite: {
|
|
38
43
|
config: {
|
|
39
44
|
test?: {
|
|
40
|
-
name
|
|
45
|
+
name?: string | undefined
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
provider: {
|
|
46
51
|
name: string
|
|
47
|
-
browserName
|
|
48
|
-
options
|
|
49
|
-
headless
|
|
50
|
-
screenshotFailures
|
|
51
|
-
screenshotDirectory
|
|
52
|
+
browserName?: string | undefined
|
|
53
|
+
options?: {
|
|
54
|
+
headless?: boolean | undefined
|
|
55
|
+
screenshotFailures?: boolean | undefined
|
|
56
|
+
screenshotDirectory?: string | undefined
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
testPath: string
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BrowserCommand } from 'vitest/node';
|
|
2
|
-
export interface WriteImageSnapshotCommand {
|
|
3
|
-
/**
|
|
4
|
-
* Writes the image snapshot to the file system.
|
|
5
|
-
* @param relativeFilePath The file path to write the image snapshot to.
|
|
6
|
-
* It is relative to the project root.
|
|
7
|
-
* @param imageBase64 The base64 encoded image.
|
|
8
|
-
*/
|
|
9
|
-
writeImageSnapshot(relativeFilePath: string, imageBase64: string): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export declare const writeImageSnapshot: BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
|
|
12
|
-
//# sourceMappingURL=write_image_snapshot.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"write_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/write_image_snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,yBAAyB;IACzC;;;;;OAKG;IACH,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChF;AAED,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAS9F,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { mkdirp } from 'mkdirp';
|
|
2
|
-
import { dirname, isAbsolute } from 'pathe';
|
|
3
|
-
import { file } from "../file.js";
|
|
4
|
-
import { assertIsRelativePath } from "./_assertions.js";
|
|
5
|
-
export const writeImageSnapshot = async (_, relativeFilePath, imageBase64) => {
|
|
6
|
-
assertIsRelativePath(relativeFilePath, 'relativeFilePath');
|
|
7
|
-
await mkdirp(dirname(relativeFilePath));
|
|
8
|
-
await file.writeFile(relativeFilePath, imageBase64, { encoding: 'base64' });
|
|
9
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { mkdirp } from 'mkdirp'
|
|
2
|
-
import { dirname, isAbsolute } from 'pathe'
|
|
3
|
-
import type { BrowserCommand } from 'vitest/node'
|
|
4
|
-
import { file } from '../file.ts'
|
|
5
|
-
import { assertIsRelativePath } from './_assertions.ts'
|
|
6
|
-
|
|
7
|
-
export interface WriteImageSnapshotCommand {
|
|
8
|
-
/**
|
|
9
|
-
* Writes the image snapshot to the file system.
|
|
10
|
-
* @param relativeFilePath The file path to write the image snapshot to.
|
|
11
|
-
* It is relative to the project root.
|
|
12
|
-
* @param imageBase64 The base64 encoded image.
|
|
13
|
-
*/
|
|
14
|
-
writeImageSnapshot(relativeFilePath: string, imageBase64: string): Promise<void>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const writeImageSnapshot: BrowserCommand<[relativeFilePath: string, imageBase64: string]> = async (
|
|
18
|
-
_,
|
|
19
|
-
relativeFilePath,
|
|
20
|
-
imageBase64,
|
|
21
|
-
) => {
|
|
22
|
-
assertIsRelativePath(relativeFilePath, 'relativeFilePath')
|
|
23
|
-
|
|
24
|
-
await mkdirp(dirname(relativeFilePath))
|
|
25
|
-
await file.writeFile(relativeFilePath, imageBase64, { encoding: 'base64' })
|
|
26
|
-
}
|