vitest-plugin-vis 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  export declare const ctx: {
2
- getCurrentTest: () => import("vitest").RunnerTestCase<object> | import("vitest").RunnerCustomCase<object> | undefined;
2
+ getCurrentTest: () => import("vitest").RunnerTestCase<object> | undefined;
3
3
  __test__reset(): void;
4
4
  };
5
5
  //# sourceMappingURL=ctx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"image_snapshot_matcher.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAA;AACpH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AAK3F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAO5F,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,qCAAqC,GAAG,yBAAyB,GAAG,6BAA6B,UAE5D,IAAI,WAAW,GAAG,YAAY,2BAA2B,CAAC,GAAG,CAAC,mBAgE7G;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
1
+ {"version":3,"file":"image_snapshot_matcher.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAA;AACpH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAA;AAI3F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAO5F,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,qCAAqC,GAAG,yBAAyB,GAAG,6BAA6B,UAE5D,IAAI,WAAW,GAAG,YAAY,2BAA2B,CAAC,GAAG,CAAC,mBAgE7G;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
@@ -1,6 +1,7 @@
1
+ import type { AutoSnapshotOptions } from '../config/types.ts';
1
2
  import type { ComparisonMethod } from '../shared/types.ts';
2
3
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
3
- export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & {
4
+ export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions & {
4
5
  enable?: boolean | undefined;
5
6
  };
6
7
  type Suite = {
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/snapshot_options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAE5F,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,gBAAgB,IAAI,2BAA2B,CAAC,CAAC,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,CAAA;AAExH,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,CAAA;AAErE,MAAM,MAAM,QAAQ,GACjB;IACA,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC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E,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACxB,GACD,SAAS,CAAA;AAEZ;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAChE,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,GAC7B,IAAI,CAAA;AACP,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,CAAA"}
@@ -1,2 +1,2 @@
1
- export declare const getCurrentTest: () => import("vitest").RunnerTestCase<object> | import("vitest").RunnerCustomCase<object> | undefined;
1
+ export declare const getCurrentTest: () => import("vitest").RunnerTestCase<object> | undefined;
2
2
  //# sourceMappingURL=vitest_suite_proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,uGAAsC,CAAA"}
1
+ {"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,2DAAsC,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import type { ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../shared/types.ts';
2
2
  export type { ComparisonMethod };
3
- export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & {
3
+ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & AutoSnapshotOptions & {
4
4
  /**
5
5
  * Loads the `test.setupFiles` of the specified preset.
6
6
  */
@@ -41,4 +41,13 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
41
41
  */
42
42
  customizeSnapshotSubpath?: (subPath: string) => string;
43
43
  };
44
+ export type AutoSnapshotOptions = {
45
+ /**
46
+ * Specify the data-testid of the subject element. Default is `subject`.
47
+ *
48
+ * If the test does not have an element with the specified data-testid,
49
+ * the `body` element will be used.
50
+ */
51
+ subjectDataTestId?: string | undefined;
52
+ };
44
53
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,GACzF,sBAAsB,GACtB,2BAA2B,CAAC,CAAC,CAAC,GAAG;IAChC;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,GACzF,sBAAsB,GACtB,2BAA2B,CAAC,CAAC,CAAC,GAC9B,mBAAmB,GAAG;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACtC,CAAA"}
@@ -7,7 +7,9 @@ export interface SetupVisSuiteCommand {
7
7
  *
8
8
  * In subsequent runs, it will only remove the results and diffs directory of the current suite.
9
9
  */
10
- setupVisSuite: () => Promise<void>;
10
+ setupVisSuite: () => Promise<{
11
+ subjectDataTestId: string | undefined;
12
+ }>;
11
13
  }
12
14
  export declare const setupVisSuite: BrowserCommand<[]>;
13
15
  //# sourceMappingURL=setup_vis_suite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup_vis_suite.d.ts","sourceRoot":"","sources":["../../../src/server/commands/setup_vis_suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AAED,eAAO,MAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAI5C,CAAA"}
1
+ {"version":3,"file":"setup_vis_suite.d.ts","sourceRoot":"","sources":["../../../src/server/commands/setup_vis_suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,OAAO,CAAC;QAAE,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC,CAAA;CACvE;AAED,eAAO,MAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAM5C,CAAA"}
@@ -2,5 +2,5 @@ import { visContext } from "../vis_context.js";
2
2
  import { assertTestPathDefined } from "./_assertions.js";
3
3
  export const setupVisSuite = async (context) => {
4
4
  assertTestPathDefined(context, 'setupVisSuite');
5
- await visContext.setupSuite(context);
5
+ return visContext.setupSuite(context);
6
6
  };
@@ -3,7 +3,7 @@ export declare const visContext: {
3
3
  __test__getOptions(): import("../config.ts").VisOptions<any>;
4
4
  __test__reset(): void;
5
5
  __test__getState(): import("./vis_context.types.ts").VisState;
6
- setupSuite(context: import("./vis_context.logic.ts").PartialBrowserCommandContext): Promise<void>;
6
+ setupSuite(context: import("./vis_context.logic.ts").PartialBrowserCommandContext): Promise<import("type-plus").Pick._<import("./vis_context.types.ts").VisState, "subjectDataTestId">>;
7
7
  getSnapshotInfo(testPath: string, name: string, options?: {
8
8
  snapshotFileId?: string | undefined;
9
9
  }): {
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBAC2mD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADvlD,CAAA"}
1
+ {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBACspD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADloD,CAAA"}
@@ -23,7 +23,7 @@ export declare function createVisContext(): {
23
23
  * Test files include vitest test files and storybook story files.
24
24
  * It needs to make sure there is no race condition between the test files.
25
25
  */
26
- setupSuite(context: PartialBrowserCommandContext): Promise<void>;
26
+ setupSuite(context: PartialBrowserCommandContext): Promise<import("type-plus").Pick._<VisState, "subjectDataTestId">>;
27
27
  getSnapshotInfo(testPath: string, name: string, options?: {
28
28
  snapshotFileId?: string | undefined;
29
29
  }): {
@@ -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;AAKpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEtD,MAAM,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE;QACR,MAAM,EAAE;YACP,IAAI,EAAE,MAAM,CAAA;YACZ,eAAe,EAAE;gBAChB,cAAc,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;aACtC,CAAA;YACD,WAAW,EAAE,MAAM,CAAA;YACnB,WAAW,EAAE,MAAM,CAAA;SACnB,CAAA;KACD,CAAA;IACD,QAAQ,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,gBAAgB;eAMnB,CAAC,SAAS,OAAO,GAAG,MAAM,YAAW,UAAU,CAAC,CAAC,CAAC;;;;IAY7D;;;;OAIG;wBACuB,4BAA4B;8BAY5B,MAAM,QAAQ,MAAM,YAAY;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;2BAkB1E,MAAM,UAAU,MAAM;+BAGlB,MAAM,UAAU,MAAM,kBAAkB,MAAM,GAAG,SAAS;8BAI3D;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBAAkB,MAAM,GAAG,SAAS;2BAMlF,MAAM,UAAU,MAAM;;;;;;;;;;EA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AAS;2BAMlF,MAAM,UAAU,MAAM;;;;;;;;;;EAe9C;AA2BD,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"}
@@ -37,6 +37,7 @@ export function createVisContext() {
37
37
  const { suiteId, suite } = createSuite(state, context.testPath, visOptions);
38
38
  state.suites[suiteId] = suite;
39
39
  await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)]);
40
+ return pick(state, 'subjectDataTestId');
40
41
  },
41
42
  getSnapshotInfo(testPath, name, options) {
42
43
  const info = context.getSuiteInfo(testPath, name);
@@ -96,6 +97,7 @@ async function setupState(suite, visOptions) {
96
97
  snapshotResultDir: join(snapshotRootDir, RESULT_DIR),
97
98
  snapshotDiffDir: join(snapshotRootDir, DIFF_DIR),
98
99
  snapshotRootPath: join(projectPath, snapshotRootDir),
100
+ subjectDataTestId: visOptions.subjectDataTestId,
99
101
  suites: {},
100
102
  };
101
103
  await Promise.allSettled([ctx.rimraf(join(state.snapshotDiffDir)), ctx.rimraf(join(state.snapshotResultDir))]);
@@ -8,6 +8,7 @@ export type VisState = {
8
8
  snapshotResultDir: string;
9
9
  snapshotDiffDir: string;
10
10
  snapshotRootPath: string;
11
+ subjectDataTestId: string | undefined;
11
12
  suites: Record<string, {
12
13
  baselineDir: string;
13
14
  resultDir: 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;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,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,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"}
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;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"create_vis.d.ts","sourceRoot":"","sources":["../../src/setup/create_vis.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAEjF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,oBAAoB;;QAMrD;;WAEG;;QAIH;;;;WAIG;;QAKH;;;;;;;;;;;;;;WAcG;sBACW,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;;;;;;;8BAgBlC,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;;EAqClE"}
1
+ {"version":3,"file":"create_vis.d.ts","sourceRoot":"","sources":["../../src/setup/create_vis.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAEjF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,oBAAoB;;QAOrD;;WAEG;;QAIH;;;;WAIG;;QAKH;;;;;;;;;;;;;;WAcG;sBACW,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;;;;;;;8BAiBlC,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;;EAoClE"}
@@ -5,6 +5,7 @@ import { ctx } from "../client/ctx.js";
5
5
  import { shouldTakeSnapshot } from "../client/should_take_snapshot.js";
6
6
  import { getAutoSnapshotOptions } from '../client/snapshot_options.internal.js';
7
7
  export function createVis(commands) {
8
+ let subjectDataTestId;
8
9
  /**
9
10
  * Visual test configuration on the client side.
10
11
  */
@@ -47,7 +48,7 @@ export function createVis(commands) {
47
48
  },
48
49
  beforeAll: {
49
50
  async setup() {
50
- await commands.setupVisSuite();
51
+ subjectDataTestId = (await commands.setupVisSuite()).subjectDataTestId;
51
52
  },
52
53
  },
53
54
  afterEach: {
@@ -55,7 +56,7 @@ export function createVis(commands) {
55
56
  const meta = getAutoSnapshotOptions(ctx.getCurrentTest());
56
57
  if (!shouldTakeSnapshot(meta))
57
58
  return;
58
- await expect(document.body).toMatchImageSnapshot(meta);
59
+ await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta);
59
60
  },
60
61
  matchPerTheme(themes) {
61
62
  return async function matchImageSnapshot() {
@@ -67,7 +68,7 @@ export function createVis(commands) {
67
68
  for (const themeId in themes) {
68
69
  try {
69
70
  await themes[themeId]();
70
- await expect(document.body).toMatchImageSnapshot({
71
+ await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot({
71
72
  ...meta,
72
73
  customizeSnapshotId: (id) => `${id}-${themeId}`,
73
74
  });
@@ -94,3 +95,11 @@ export function createVis(commands) {
94
95
  };
95
96
  return vis;
96
97
  }
98
+ function getSubject(subjectDataTestId) {
99
+ if (subjectDataTestId) {
100
+ const subject = document.querySelector(`[data-testid="${subjectDataTestId}"]`);
101
+ if (subject)
102
+ return subject;
103
+ }
104
+ return document.body;
105
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -77,10 +77,10 @@
77
77
  "@types/is-ci": "^3.0.4",
78
78
  "@types/pngjs": "^6.0.5",
79
79
  "@types/react": "^19.0.2",
80
- "@vitest/browser": "^2.1.8",
81
- "@vitest/coverage-istanbul": "^2.1.8",
82
- "@vitest/coverage-v8": "^2.1.8",
83
- "@vitest/expect": "^2.1.8",
80
+ "@vitest/browser": "^3.0.0",
81
+ "@vitest/coverage-istanbul": "^3.0.0",
82
+ "@vitest/coverage-v8": "^3.0.0",
83
+ "@vitest/expect": "^3.0.0",
84
84
  "cross-env": "^7.0.3",
85
85
  "never-fail": "^1.1.4",
86
86
  "npm-run-all2": "^7.0.2",
@@ -88,13 +88,14 @@
88
88
  "react": "^19.0.0",
89
89
  "react-dom": "^19.0.0",
90
90
  "typescript": "^5.7.2",
91
- "vite": "^5.3.5",
92
- "vitest": "^2.1.3",
91
+ "vite": "^6.0.0",
92
+ "vitest": "^3.0.0",
93
93
  "vitest-browser-react": "^0.0.4",
94
- "webdriverio": "^9.4.1"
94
+ "webdriverio": "^9.5.7"
95
95
  },
96
96
  "peerDependencies": {
97
- "@vitest/browser": "^2.1.3"
97
+ "@vitest/browser": "^2 || ^3",
98
+ "vitest": "^2 || ^3"
98
99
  },
99
100
  "publishConfig": {
100
101
  "access": "public"
@@ -108,11 +109,14 @@
108
109
  "dev": "run-p build:watch w",
109
110
  "nuke": "rimraf node_modules",
110
111
  "test": "vitest run",
112
+ "t:node": "vitest --project=vpv:node",
113
+ "t:pw": "vitest run --project=\"vpv:pw (*)\"",
114
+ "t:wd": "vitest run --project=\"vpv:wd (*)\"",
111
115
  "v": "run-p build cov",
112
116
  "w": "vitest",
113
117
  "w:cov": "cross-env COVERAGE=true vitest --coverage",
114
118
  "w:node": "vitest --project=vpv:node",
115
- "w:pw": "vitest --project=vpv:pw",
116
- "w:wd": "vitest --project=vpv:wd"
119
+ "w:pw": "vitest --project=\"vpv:pw (*)\"",
120
+ "w:wd": "vitest --project=\"vpv:wd (*)\""
117
121
  }
118
122
  }
package/readme.md CHANGED
@@ -19,7 +19,7 @@ yarn add --save-dev vitest-plugin-vis
19
19
 
20
20
  ## Config
21
21
 
22
- Vitest visual testing plugin supports zero-config setup.
22
+ The `vitest-plugin-vis` plugin can be used without customization.
23
23
 
24
24
  ```ts
25
25
  // vitest.config.ts
@@ -41,9 +41,10 @@ export default defineConfig({
41
41
 
42
42
  This default configuration will:
43
43
 
44
- - Use `pixelmatch` as the image comparison method.
45
44
  - Use the `auto` preset, taking image snapshot at the end on each rendering test.
45
+ - Use `pixelmatch` as the image comparison method.
46
46
  - Set config to compare image snapshot with a failure threshold of `0 pixels`.
47
+ - Timeout for image comparison is set to `30000 ms`.
47
48
  - Local (non-CI) image snapshots are saved in the `<root>/__vis__/local` directory.
48
49
  - CI image snapshots are saved in the `<root>/__vis__/<process.platform>` directory.
49
50
  - Image snapshots of the current test run are saved in the `<root>/__vis__/__results__` directory.
@@ -64,16 +65,18 @@ export default defineConfig({
64
65
  platform: '...', // {process.platform} or `local`
65
66
  customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
66
67
  customizeSnapshotId: (id, index) => `${id}-${index}`,
68
+ // set a default subject (e.g. 'subject') to capture image snapshot
69
+ subjectDataTestId: undefined,
67
70
  comparisonMethod: 'pixel',
68
71
  // pixelmatch or ssim.js options, depending on `comparisonMethod`.
69
72
  diffOptions: undefined,
73
+ timeout: 30000,
70
74
  failureThresholdType: 'pixel',
71
75
  failureThreshold: 0,
72
- timeout: 30000
73
76
  })
74
77
  ],
75
78
  test:{
76
- browser:{/* ... */}
79
+ browser: {/* ... */}
77
80
  }
78
81
  })
79
82
  ```
@@ -6,7 +6,6 @@ import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/p
6
6
  import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts'
7
7
  import { isBase64String } from '../shared/base64.ts'
8
8
  import { compareImage } from '../shared/compare_image.ts'
9
- import type { ComparisonMethod } from '../shared/types.ts'
10
9
  import { alignImagesToSameSize } from './align_images.ts'
11
10
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts'
12
11
  import { toDataURL, toImageData } from './image_data.ts'
@@ -1,9 +1,13 @@
1
+ import type { AutoSnapshotOptions } from '../config/types.ts'
1
2
  import { NAME } from '../shared/constants.ts'
2
3
  import type { ComparisonMethod } from '../shared/types.ts'
3
4
  import { ctx } from './ctx.ts'
4
5
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts'
5
6
 
6
- export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & { enable?: boolean | undefined }
7
+ export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> &
8
+ AutoSnapshotOptions & {
9
+ enable?: boolean | undefined
10
+ }
7
11
 
8
12
  type Suite = { meta: Record<string, any>; suite?: Suite | undefined }
9
13
 
@@ -9,7 +9,8 @@ export type { ComparisonMethod }
9
9
 
10
10
  export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions &
11
11
  ImageSnapshotIdOptions &
12
- ImageSnapshotCompareOptions<M> & {
12
+ ImageSnapshotCompareOptions<M> &
13
+ AutoSnapshotOptions & {
13
14
  /**
14
15
  * Loads the `test.setupFiles` of the specified preset.
15
16
  */
@@ -50,3 +51,13 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
50
51
  */
51
52
  customizeSnapshotSubpath?: (subPath: string) => string
52
53
  }
54
+
55
+ export type AutoSnapshotOptions = {
56
+ /**
57
+ * Specify the data-testid of the subject element. Default is `subject`.
58
+ *
59
+ * If the test does not have an element with the specified data-testid,
60
+ * the `body` element will be used.
61
+ */
62
+ subjectDataTestId?: string | undefined
63
+ }
@@ -10,11 +10,13 @@ export interface SetupVisSuiteCommand {
10
10
  *
11
11
  * In subsequent runs, it will only remove the results and diffs directory of the current suite.
12
12
  */
13
- setupVisSuite: () => Promise<void>
13
+ setupVisSuite: () => Promise<{ subjectDataTestId: string | undefined }>
14
14
  }
15
15
 
16
- export const setupVisSuite: BrowserCommand<[]> = async (context) => {
16
+ export const setupVisSuite: BrowserCommand<[]> = async (
17
+ context,
18
+ ): Promise<{ subjectDataTestId: string | undefined }> => {
17
19
  assertTestPathDefined(context, 'setupVisSuite')
18
20
 
19
- await visContext.setupSuite(context)
21
+ return visContext.setupSuite(context)
20
22
  }
@@ -55,6 +55,7 @@ export function createVisContext() {
55
55
  const { suiteId, suite } = createSuite(state, context.testPath, visOptions)
56
56
  state.suites[suiteId] = suite
57
57
  await Promise.allSettled([ctx.rimraf(suite.diffDir), ctx.rimraf(suite.resultDir)])
58
+ return pick(state, 'subjectDataTestId')
58
59
  },
59
60
  getSnapshotInfo(testPath: string, name: string, options?: { snapshotFileId?: string | undefined }) {
60
61
  const info = context.getSuiteInfo(testPath, name)
@@ -106,7 +107,7 @@ export function createVisContext() {
106
107
 
107
108
  async function setupState(
108
109
  suite: PartialBrowserCommandContext,
109
- visOptions: Pick<VisOptions, 'snapshotRootDir' | 'platform'>,
110
+ visOptions: Pick<VisOptions, 'snapshotRootDir' | 'platform' | 'subjectDataTestId'>,
110
111
  ) {
111
112
  const snapshotRootDir = resolveSnapshotRootDir(visOptions)
112
113
  const projectPath = suite.project.config.root
@@ -122,6 +123,7 @@ async function setupState(
122
123
  snapshotResultDir: join(snapshotRootDir, RESULT_DIR),
123
124
  snapshotDiffDir: join(snapshotRootDir, DIFF_DIR),
124
125
  snapshotRootPath: join(projectPath, snapshotRootDir),
126
+ subjectDataTestId: visOptions.subjectDataTestId,
125
127
  suites: {},
126
128
  }
127
129
  await Promise.allSettled([ctx.rimraf(join(state.snapshotDiffDir)), ctx.rimraf(join(state.snapshotResultDir))])
@@ -8,6 +8,7 @@ export type VisState = {
8
8
  snapshotResultDir: string
9
9
  snapshotDiffDir: string
10
10
  snapshotRootPath: string
11
+ subjectDataTestId: string | undefined
11
12
  suites: Record<
12
13
  string,
13
14
  {
@@ -7,6 +7,7 @@ import { getAutoSnapshotOptions } from '../client/snapshot_options.internal.js'
7
7
  import type { SetupVisSuiteCommand } from '../server/commands/setup_vis_suite.ts'
8
8
 
9
9
  export function createVis(commands: SetupVisSuiteCommand) {
10
+ let subjectDataTestId: string | undefined
10
11
  /**
11
12
  * Visual test configuration on the client side.
12
13
  */
@@ -49,26 +50,26 @@ export function createVis(commands: SetupVisSuiteCommand) {
49
50
  },
50
51
  beforeAll: {
51
52
  async setup() {
52
- await commands.setupVisSuite()
53
+ subjectDataTestId = (await commands.setupVisSuite()).subjectDataTestId
53
54
  },
54
55
  },
55
56
  afterEach: {
56
57
  async matchImageSnapshot() {
57
58
  const meta = getAutoSnapshotOptions(ctx.getCurrentTest())
58
59
  if (!shouldTakeSnapshot(meta)) return
59
- await expect(document.body).toMatchImageSnapshot(meta)
60
+
61
+ await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta)
60
62
  },
61
63
  matchPerTheme(themes: Record<string, () => Promise<void> | void>) {
62
64
  return async function matchImageSnapshot() {
63
65
  const test = ctx.getCurrentTest()
64
66
  const meta = getAutoSnapshotOptions(test)
65
67
  if (!shouldTakeSnapshot(meta)) return
66
-
67
68
  const errors: any[] = []
68
69
  for (const themeId in themes) {
69
70
  try {
70
71
  await themes[themeId]!()
71
- await expect(document.body).toMatchImageSnapshot({
72
+ await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot({
72
73
  ...meta,
73
74
  customizeSnapshotId: (id) => `${id}-${themeId}`,
74
75
  })
@@ -96,3 +97,12 @@ export function createVis(commands: SetupVisSuiteCommand) {
96
97
  }
97
98
  return vis
98
99
  }
100
+
101
+ function getSubject(subjectDataTestId: string | undefined) {
102
+ if (subjectDataTestId) {
103
+ const subject = document.querySelector(`[data-testid="${subjectDataTestId}"]`)
104
+ if (subject) return subject
105
+ }
106
+
107
+ return document.body
108
+ }