vitest-plugin-vis 2.3.1 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/client/image_snapshot_matcher.d.ts.map +1 -1
- package/esm/client/image_snapshot_matcher.js +0 -1
- package/esm/config/vis.d.ts +1 -1
- 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/has_image_snapshot.js +1 -1
- package/esm/server/commands/match_image_snapshot.js +1 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.js +1 -1
- package/esm/server/vis_context.d.ts +5 -5
- package/esm/server/vis_context.d.ts.map +1 -1
- package/esm/server/vis_context.logic.d.ts +5 -5
- package/esm/server/vis_context.logic.d.ts.map +1 -1
- package/esm/server/vis_context.logic.js +22 -18
- package/esm/server/vis_context.types.d.ts +7 -0
- 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 +1 -1
- package/src/client/image_snapshot_matcher.ts +0 -1
- package/src/config/vis.ts +5 -3
- package/src/server/commands/browser_command_context.ts +9 -0
- package/src/server/commands/has_image_snapshot.ts +1 -1
- package/src/server/commands/match_image_snapshot.ts +1 -1
- package/src/server/commands/prepare_image_snapshot_comparison.ts +1 -2
- package/src/server/vis_context.logic.ts +43 -18
- package/src/server/vis_context.types.ts +7 -0
- package/src/testing/stubBrowserCommandContext.ts +7 -0
|
@@ -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":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAA;AACpH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AAG3F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAOrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,qCAAqC,GAAG,yBAAyB,GAAG,6BAA6B,UAGpG,WAAW,GAAG,EAAE,WACb,GAAG,YACF,2BAA2B,CAAC,GAAG,CAAC,mBAqE3C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
|
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;
|
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;
|
|
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,EAAE,MAAM,CAAA;iBAAE,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,sBAErG;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,qBAAqB,wCAE3E"}
|
|
@@ -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
|
};
|
|
@@ -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 = visContext.getSnapshotInfo(context, taskId, isAutoSnapshot, options);
|
|
19
19
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
20
20
|
if (!baselineBuffer) {
|
|
21
21
|
if (isBase64String(subject)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAE1E,KAAK,2BAA2B,GAAG;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACd,GAAG,2BAA2B,GAC9B,uBAAuB,GACvB,CAAC,qBAAqB,GAAG,sBAAsB,CAAC,CAAA;AAEjD,MAAM,WAAW,qCAAqC;IACrD,8BAA8B,EAAE,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,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,
|
|
1
|
+
{"version":3,"file":"prepare_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,KAAK,EACX,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAE1E,KAAK,2BAA2B,GAAG;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACd,GAAG,2BAA2B,GAC9B,uBAAuB,GACvB,CAAC,qBAAqB,GAAG,sBAAsB,CAAC,CAAA;AAEjD,MAAM,WAAW,qCAAqC;IACrD,8BAA8B,EAAE,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,OAAO,EACvB,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAAA;CACrD;AAED,eAAO,MAAM,8BAA8B,EAAE,cAAc,CAC1D;IAAC,MAAM,EAAE,MAAM;IAAE,UAAU,EAAE,MAAM;IAAE,cAAc,EAAE,OAAO;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CAyB9G,CAAA"}
|
|
@@ -9,7 +9,7 @@ export const prepareImageSnapshotComparison = async (context, taskId, subject, i
|
|
|
9
9
|
if (!options)
|
|
10
10
|
options = {};
|
|
11
11
|
options.timeout = options.timeout ?? 30000;
|
|
12
|
-
const info = visContext.getSnapshotInfo(context
|
|
12
|
+
const info = visContext.getSnapshotInfo(context, taskId, isAutoSnapshot, options);
|
|
13
13
|
const baselineBuffer = await file.tryReadFile(info.baselinePath);
|
|
14
14
|
if (!baselineBuffer) {
|
|
15
15
|
if (isBase64String(subject)) {
|
|
@@ -1,10 +1,10 @@
|
|
|
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
5
|
__test__getState(): import("./vis_context.types.ts").VisState;
|
|
6
6
|
setupSuite(context: import("./vis_context.types.ts").PartialBrowserCommandContext): Promise<import("type-plus").Pick._<import("./vis_context.types.ts").VisState, "subjectDataTestId">>;
|
|
7
|
-
getSnapshotInfo(
|
|
7
|
+
getSnapshotInfo(browserContext: import("./vis_context.types.ts").PartialBrowserCommandContext, name: string, isAutoSnapshot: boolean, options?: {
|
|
8
8
|
snapshotFileId?: string | undefined;
|
|
9
9
|
}): {
|
|
10
10
|
baselinePath: string;
|
|
@@ -34,8 +34,8 @@ export declare const visContext: {
|
|
|
34
34
|
} | undefined;
|
|
35
35
|
};
|
|
36
36
|
getTaskCount(testPath: string, taskId: string): number;
|
|
37
|
-
hasImageSnapshot(
|
|
38
|
-
getSnapshotFilename(info: {
|
|
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;
|
|
@@ -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;;;;;;;sBAC8wD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAD1vD,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { VisOptions } from '../config/types.ts';
|
|
2
2
|
import type { PartialBrowserCommandContext, VisState } 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
7
|
__test__getState(): VisState;
|
|
8
8
|
/**
|
|
@@ -11,7 +11,7 @@ export declare function createVisContext(): {
|
|
|
11
11
|
* It needs to make sure there is no race condition between the test files.
|
|
12
12
|
*/
|
|
13
13
|
setupSuite(context: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<VisState, "subjectDataTestId">>;
|
|
14
|
-
getSnapshotInfo(
|
|
14
|
+
getSnapshotInfo(browserContext: PartialBrowserCommandContext, name: string, isAutoSnapshot: boolean, options?: {
|
|
15
15
|
snapshotFileId?: string | undefined;
|
|
16
16
|
}): {
|
|
17
17
|
baselinePath: string;
|
|
@@ -41,8 +41,8 @@ export declare function createVisContext(): {
|
|
|
41
41
|
} | undefined;
|
|
42
42
|
};
|
|
43
43
|
getTaskCount(testPath: string, taskId: string): number;
|
|
44
|
-
hasImageSnapshot(
|
|
45
|
-
getSnapshotFilename(info: {
|
|
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;
|
|
@@ -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,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEpF,wBAAgB,gBAAgB;eAMnB,CAAC,SAAS,OAAO,GAAG,MAAM,eAAe,MAAM,GAAG,SAAS,YAAW,UAAU,CAAC,CAAC,CAAC;oCAG9D,MAAM;;;IAStC;;;;OAIG;wBACuB,4BAA4B;oCAcrC,4BAA4B,QACtC,MAAM,kBACI,OAAO,YACb;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA+B3B,MAAM,UAAU,MAAM;qCAI5B,4BAA4B,UACpC,MAAM,kBACE,MAAM,GAAG,SAAS,kBAClB,OAAO;wCAQP,4BAA4B,QACtC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBACjC,MAAM,GAAG,SAAS,kBAClB,OAAO;2BAWD,MAAM,UAAU,MAAM;;;;;;;;;;EAe9C;AAyBD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC;;;;;;;;EAWnH;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC,UAElH"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { join, relative } 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 visOptionsRecord = {};
|
|
9
10
|
let state;
|
|
10
11
|
let globalStateReady;
|
|
11
12
|
const context = {
|
|
12
|
-
setOptions(options = {}) {
|
|
13
|
-
|
|
13
|
+
setOptions(projectName, options = {}) {
|
|
14
|
+
visOptionsRecord[projectName ?? '__default'] = options;
|
|
14
15
|
},
|
|
15
|
-
__test__getOptions() {
|
|
16
|
-
return
|
|
16
|
+
__test__getOptions(projectName) {
|
|
17
|
+
return visOptionsRecord[projectName];
|
|
17
18
|
},
|
|
18
19
|
__test__reset() {
|
|
19
|
-
|
|
20
|
+
visOptionsRecord = {};
|
|
20
21
|
},
|
|
21
22
|
__test__getState() {
|
|
22
23
|
return state;
|
|
@@ -28,27 +29,27 @@ export function createVisContext() {
|
|
|
28
29
|
*/
|
|
29
30
|
async setupSuite(context) {
|
|
30
31
|
if (!globalStateReady) {
|
|
31
|
-
globalStateReady = setupState(context,
|
|
32
|
+
globalStateReady = setupState(context, getVisOptions(visOptionsRecord, context) ?? {});
|
|
32
33
|
state = await globalStateReady;
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
36
|
await globalStateReady;
|
|
36
37
|
}
|
|
37
|
-
const { suiteId, suite } = createSuite(state, context.testPath,
|
|
38
|
+
const { suiteId, suite } = createSuite(state, context.testPath, visOptionsRecord);
|
|
38
39
|
state.suites[suiteId] = suite;
|
|
39
40
|
await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)]);
|
|
40
41
|
return pick(state, 'subjectDataTestId');
|
|
41
42
|
},
|
|
42
|
-
getSnapshotInfo(
|
|
43
|
-
const suiteInfo = context.getSuiteInfo(testPath, name);
|
|
44
|
-
const snapshotFilename = context.getSnapshotFilename(suiteInfo, options?.snapshotFileId, isAutoSnapshot);
|
|
43
|
+
getSnapshotInfo(browserContext, name, isAutoSnapshot, options) {
|
|
44
|
+
const suiteInfo = context.getSuiteInfo(browserContext.testPath, name);
|
|
45
|
+
const snapshotFilename = context.getSnapshotFilename(browserContext, suiteInfo, options?.snapshotFileId, isAutoSnapshot);
|
|
45
46
|
const { baselineDir, resultDir, diffDir, task } = suiteInfo;
|
|
46
47
|
task.count = task.count + 1;
|
|
47
48
|
const baselinePath = join(baselineDir, snapshotFilename);
|
|
48
49
|
const resultPath = join(resultDir, snapshotFilename);
|
|
49
50
|
const diffPath = join(diffDir, snapshotFilename);
|
|
50
51
|
return {
|
|
51
|
-
...pick(
|
|
52
|
+
...pick(getVisOptions(visOptionsRecord, browserContext), 'comparisonMethod', 'diffOptions', 'failureThreshold', 'failureThresholdType', 'timeout'),
|
|
52
53
|
baselinePath,
|
|
53
54
|
resultPath,
|
|
54
55
|
diffPath,
|
|
@@ -57,14 +58,14 @@ export function createVisContext() {
|
|
|
57
58
|
getTaskCount(testPath, taskId) {
|
|
58
59
|
return context.getSuiteInfo(testPath, taskId).task.count;
|
|
59
60
|
},
|
|
60
|
-
hasImageSnapshot(
|
|
61
|
-
const info = context.getSuiteInfo(testPath, taskId);
|
|
62
|
-
return file.existFile(join(info.baselineDir, context.getSnapshotFilename(info, snapshotFileId, isAutoSnapshot)));
|
|
61
|
+
hasImageSnapshot(browserContext, taskId, snapshotFileId, isAutoSnapshot) {
|
|
62
|
+
const info = context.getSuiteInfo(browserContext.testPath, taskId);
|
|
63
|
+
return file.existFile(join(info.baselineDir, context.getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot)));
|
|
63
64
|
},
|
|
64
|
-
getSnapshotFilename(info, snapshotFileId, isAutoSnapshot) {
|
|
65
|
+
getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot) {
|
|
65
66
|
if (snapshotFileId)
|
|
66
67
|
return `${snapshotFileId}.png`;
|
|
67
|
-
const customizeSnapshotId =
|
|
68
|
+
const customizeSnapshotId = getVisOptions(visOptionsRecord, browserContext).customizeSnapshotId ?? (({ id, index }) => `${id}-${index}`);
|
|
68
69
|
return `${customizeSnapshotId({
|
|
69
70
|
id: info.taskId,
|
|
70
71
|
index: info.task.count,
|
|
@@ -72,7 +73,7 @@ export function createVisContext() {
|
|
|
72
73
|
})}.png`;
|
|
73
74
|
},
|
|
74
75
|
getSuiteInfo(testPath, taskId) {
|
|
75
|
-
const suiteId = getSuiteId(state, testPath,
|
|
76
|
+
const suiteId = getSuiteId(state, testPath, visOptionsRecord);
|
|
76
77
|
const suite = state.suites[suiteId];
|
|
77
78
|
const task = (suite.tasks[taskId] = suite.tasks[taskId] ?? { count: 1 });
|
|
78
79
|
return {
|
|
@@ -120,3 +121,6 @@ export function createSuite(state, testPath, options) {
|
|
|
120
121
|
export function getSuiteId(state, testPath, options) {
|
|
121
122
|
return getSnapshotSubpath(relative(state.projectPath, testPath), options);
|
|
122
123
|
}
|
|
124
|
+
function getVisOptions(visOptionsRecord, context) {
|
|
125
|
+
return visOptionsRecord[getProjectName(context) ?? '__default'];
|
|
126
|
+
}
|
|
@@ -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;IAEnB,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;AACD,MAAM,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE;QACR,MAAM,EAAE;YACP,IAAI,EAAE,MAAM,CAAA;YACZ,eAAe,EAAE;gBAChB,cAAc,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;aACtC,CAAA;YACD,WAAW,EAAE,MAAM,CAAA;YACnB,WAAW,EAAE,MAAM,CAAA;SACnB,CAAA;KACD,CAAA;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,OAAO,EAAE;YACR,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;YAC7B,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAA;YACvC,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAA;SACvC,CAAA;KACD,CAAA;IACD,QAAQ,EAAE,MAAM,CAAA;CAChB,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,WAAW,EAAE,MAAM,CAAA;IAEnB,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;AACD,MAAM,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE;QACR,MAAM,EAAE;YACP,IAAI,EAAE,MAAM,CAAA;YACZ,eAAe,EAAE;gBAChB,cAAc,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;aACtC,CAAA;YACD,WAAW,EAAE,MAAM,CAAA;YACnB,WAAW,EAAE,MAAM,CAAA;SACnB,CAAA;QACD,IAAI,EAAE;YACL,MAAM,EAAE;gBACP,IAAI,CAAC,EAAE;oBACN,IAAI,EAAE,MAAM,CAAA;iBACZ,CAAA;aACD,CAAA;SACD,CAAA;KACD,CAAA;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,OAAO,EAAE;YACR,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;YAC7B,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAA;YACvC,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAA;SACvC,CAAA;KACD,CAAA;IACD,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubBrowserCommandContext.d.ts","sourceRoot":"","sources":["../../src/testing/stubBrowserCommandContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAA;AAElF,eAAO,MAAM,yBAAyB,2GAAwC,CAAA;AAE9E,wBAAgB,sCAAsC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"stubBrowserCommandContext.d.ts","sourceRoot":"","sources":["../../src/testing/stubBrowserCommandContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAA;AAElF,eAAO,MAAM,yBAAyB,2GAAwC,CAAA;AAE9E,wBAAgB,sCAAsC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,2HAmB5G"}
|
package/package.json
CHANGED
package/src/config/vis.ts
CHANGED
|
@@ -12,11 +12,13 @@ import type { VisOptions } from './types.ts'
|
|
|
12
12
|
* which enables the `auto` preset.
|
|
13
13
|
*/
|
|
14
14
|
export function vis<M extends ComparisonMethod = 'pixel'>(options: VisOptions<M> = { preset: 'auto' } as any) {
|
|
15
|
-
visContext.setOptions(options)
|
|
16
|
-
const preset = options?.preset
|
|
17
15
|
return {
|
|
18
16
|
name: NAME,
|
|
19
|
-
config() {
|
|
17
|
+
config(userConfig) {
|
|
18
|
+
const projectName = userConfig?.test?.name
|
|
19
|
+
|
|
20
|
+
visContext.setOptions(projectName, options)
|
|
21
|
+
const preset = options?.preset
|
|
20
22
|
return {
|
|
21
23
|
test: {
|
|
22
24
|
browser: {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BrowserCommandContext } from 'vitest/node'
|
|
2
|
+
|
|
3
|
+
export function getProjectName(context: { project: { vite: { config: { test?: { name: string } } } } }) {
|
|
4
|
+
return context.project.vite.config.test?.name
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getBrowserInstanceProjectName(context: BrowserCommandContext) {
|
|
8
|
+
return context.project.config
|
|
9
|
+
}
|
|
@@ -11,5 +11,5 @@ export const hasImageSnapshot: BrowserCommand<
|
|
|
11
11
|
> = async (context, taskId, snapshotId, isAutoSnapshot) => {
|
|
12
12
|
assertTestPathDefined(context, 'hasImageSnapshot')
|
|
13
13
|
|
|
14
|
-
return visContext.hasImageSnapshot(context
|
|
14
|
+
return visContext.hasImageSnapshot(context as any, taskId, snapshotId, isAutoSnapshot)
|
|
15
15
|
}
|
|
@@ -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
|
|
46
|
+
const info = 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)) {
|
|
@@ -36,12 +36,11 @@ export const prepareImageSnapshotComparison: BrowserCommand<
|
|
|
36
36
|
[taskId: string, snapshotId: string, isAutoSnapshot: boolean, options?: MatchImageSnapshotOptions | undefined]
|
|
37
37
|
> = async (context, taskId, subject, isAutoSnapshot, options) => {
|
|
38
38
|
assertTestPathDefined(context, 'prepareImageSnapshotComparison')
|
|
39
|
-
|
|
40
39
|
// vitest:browser passes in `null` when not defined
|
|
41
40
|
if (!options) options = {}
|
|
42
41
|
options.timeout = options.timeout ?? 30000
|
|
43
42
|
|
|
44
|
-
const info = visContext.getSnapshotInfo(context
|
|
43
|
+
const info = visContext.getSnapshotInfo(context as any, taskId, isAutoSnapshot, options)
|
|
45
44
|
const baselineBuffer = await file.tryReadFile(info.baselinePath)
|
|
46
45
|
if (!baselineBuffer) {
|
|
47
46
|
if (isBase64String(subject)) {
|
|
@@ -2,25 +2,26 @@ import { join, relative } 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'
|
|
5
|
+
import { getProjectName } from './commands/browser_command_context.ts'
|
|
5
6
|
import { file } from './file.ts'
|
|
6
7
|
import { getSnapshotSubpath, resolveSnapshotRootDir } from './snapshot_path.ts'
|
|
7
8
|
import { ctx } from './vis_context.ctx.ts'
|
|
8
9
|
import type { PartialBrowserCommandContext, VisState } from './vis_context.types.ts'
|
|
9
10
|
|
|
10
11
|
export function createVisContext() {
|
|
11
|
-
let
|
|
12
|
+
let visOptionsRecord: Record<string, VisOptions<any>> = {}
|
|
12
13
|
let state: VisState
|
|
13
14
|
let globalStateReady: Promise<VisState>
|
|
14
15
|
|
|
15
16
|
const context = {
|
|
16
|
-
setOptions<M extends 'pixel' | 'ssim'>(options: VisOptions<M> = {} as any) {
|
|
17
|
-
|
|
17
|
+
setOptions<M extends 'pixel' | 'ssim'>(projectName: string | undefined, options: VisOptions<M> = {} as any) {
|
|
18
|
+
visOptionsRecord[projectName ?? '__default'] = options
|
|
18
19
|
},
|
|
19
|
-
__test__getOptions() {
|
|
20
|
-
return
|
|
20
|
+
__test__getOptions(projectName: string) {
|
|
21
|
+
return visOptionsRecord[projectName]
|
|
21
22
|
},
|
|
22
23
|
__test__reset() {
|
|
23
|
-
|
|
24
|
+
visOptionsRecord = {} as any
|
|
24
25
|
},
|
|
25
26
|
__test__getState() {
|
|
26
27
|
return state
|
|
@@ -32,25 +33,30 @@ export function createVisContext() {
|
|
|
32
33
|
*/
|
|
33
34
|
async setupSuite(context: PartialBrowserCommandContext) {
|
|
34
35
|
if (!globalStateReady) {
|
|
35
|
-
globalStateReady = setupState(context,
|
|
36
|
+
globalStateReady = setupState(context, getVisOptions(visOptionsRecord, context) ?? {})
|
|
36
37
|
state = await globalStateReady
|
|
37
38
|
} else {
|
|
38
39
|
await globalStateReady
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
const { suiteId, suite } = createSuite(state, context.testPath,
|
|
42
|
+
const { suiteId, suite } = createSuite(state, context.testPath, visOptionsRecord)
|
|
42
43
|
state.suites[suiteId] = suite
|
|
43
44
|
await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)])
|
|
44
45
|
return pick(state, 'subjectDataTestId')
|
|
45
46
|
},
|
|
46
47
|
getSnapshotInfo(
|
|
47
|
-
|
|
48
|
+
browserContext: PartialBrowserCommandContext,
|
|
48
49
|
name: string,
|
|
49
50
|
isAutoSnapshot: boolean,
|
|
50
51
|
options?: { snapshotFileId?: string | undefined },
|
|
51
52
|
) {
|
|
52
|
-
const suiteInfo = context.getSuiteInfo(testPath, name)
|
|
53
|
-
const snapshotFilename = context.getSnapshotFilename(
|
|
53
|
+
const suiteInfo = context.getSuiteInfo(browserContext.testPath, name)
|
|
54
|
+
const snapshotFilename = context.getSnapshotFilename(
|
|
55
|
+
browserContext,
|
|
56
|
+
suiteInfo,
|
|
57
|
+
options?.snapshotFileId,
|
|
58
|
+
isAutoSnapshot,
|
|
59
|
+
)
|
|
54
60
|
|
|
55
61
|
const { baselineDir, resultDir, diffDir, task } = suiteInfo
|
|
56
62
|
|
|
@@ -60,7 +66,14 @@ export function createVisContext() {
|
|
|
60
66
|
const diffPath = join(diffDir, snapshotFilename)
|
|
61
67
|
|
|
62
68
|
return {
|
|
63
|
-
...pick(
|
|
69
|
+
...pick(
|
|
70
|
+
getVisOptions(visOptionsRecord, browserContext),
|
|
71
|
+
'comparisonMethod',
|
|
72
|
+
'diffOptions',
|
|
73
|
+
'failureThreshold',
|
|
74
|
+
'failureThresholdType',
|
|
75
|
+
'timeout',
|
|
76
|
+
),
|
|
64
77
|
baselinePath,
|
|
65
78
|
resultPath,
|
|
66
79
|
diffPath,
|
|
@@ -69,18 +82,26 @@ export function createVisContext() {
|
|
|
69
82
|
getTaskCount(testPath: string, taskId: string) {
|
|
70
83
|
return context.getSuiteInfo(testPath, taskId).task.count
|
|
71
84
|
},
|
|
72
|
-
hasImageSnapshot(
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
hasImageSnapshot(
|
|
86
|
+
browserContext: PartialBrowserCommandContext,
|
|
87
|
+
taskId: string,
|
|
88
|
+
snapshotFileId: string | undefined,
|
|
89
|
+
isAutoSnapshot: boolean,
|
|
90
|
+
) {
|
|
91
|
+
const info = context.getSuiteInfo(browserContext.testPath, taskId)
|
|
92
|
+
return file.existFile(
|
|
93
|
+
join(info.baselineDir, context.getSnapshotFilename(browserContext, info, snapshotFileId, isAutoSnapshot)),
|
|
94
|
+
)
|
|
75
95
|
},
|
|
76
96
|
getSnapshotFilename(
|
|
97
|
+
browserContext: PartialBrowserCommandContext,
|
|
77
98
|
info: { taskId: string; task: { count: number } },
|
|
78
|
-
|
|
79
99
|
snapshotFileId: string | undefined,
|
|
80
100
|
isAutoSnapshot: boolean,
|
|
81
101
|
) {
|
|
82
102
|
if (snapshotFileId) return `${snapshotFileId}.png`
|
|
83
|
-
const customizeSnapshotId =
|
|
103
|
+
const customizeSnapshotId =
|
|
104
|
+
getVisOptions(visOptionsRecord, browserContext).customizeSnapshotId ?? (({ id, index }) => `${id}-${index}`)
|
|
84
105
|
return `${customizeSnapshotId({
|
|
85
106
|
id: info.taskId,
|
|
86
107
|
index: info.task.count,
|
|
@@ -88,7 +109,7 @@ export function createVisContext() {
|
|
|
88
109
|
})}.png`
|
|
89
110
|
},
|
|
90
111
|
getSuiteInfo(testPath: string, taskId: string) {
|
|
91
|
-
const suiteId = getSuiteId(state, testPath,
|
|
112
|
+
const suiteId = getSuiteId(state, testPath, visOptionsRecord)
|
|
92
113
|
const suite = state.suites[suiteId]!
|
|
93
114
|
const task = (suite.tasks[taskId] = suite.tasks[taskId] ?? { count: 1 })
|
|
94
115
|
return {
|
|
@@ -143,3 +164,7 @@ export function createSuite(state: VisState, testPath: string, options: Pick<Vis
|
|
|
143
164
|
export function getSuiteId(state: VisState, testPath: string, options: Pick<VisOptions, 'customizeSnapshotSubpath'>) {
|
|
144
165
|
return getSnapshotSubpath(relative(state.projectPath, testPath), options)
|
|
145
166
|
}
|
|
167
|
+
|
|
168
|
+
function getVisOptions(visOptionsRecord: Record<string, VisOptions<any>>, context: PartialBrowserCommandContext) {
|
|
169
|
+
return visOptionsRecord[getProjectName(context) ?? '__default']!
|
|
170
|
+
}
|