vitest-plugin-vis 2.1.1 → 2.3.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.
Files changed (67) hide show
  1. package/esm/client/ctx.d.ts +2 -1
  2. package/esm/client/ctx.d.ts.map +1 -1
  3. package/esm/client/ctx.js +2 -0
  4. package/esm/client/expect/to_match_image_snapshot.d.ts +1 -1
  5. package/esm/client/expect/to_match_image_snapshot.d.ts.map +1 -1
  6. package/esm/client/expect/to_match_image_snapshot.types.d.ts +1 -8
  7. package/esm/client/expect/to_match_image_snapshot.types.d.ts.map +1 -1
  8. package/esm/client/image_snapshot_matcher.d.ts +2 -3
  9. package/esm/client/image_snapshot_matcher.d.ts.map +1 -1
  10. package/esm/client/image_snapshot_matcher.js +6 -3
  11. package/esm/client/image_snapshot_matcher.logic.d.ts +1 -1
  12. package/esm/client/image_snapshot_matcher.logic.d.ts.map +1 -1
  13. package/esm/client/page/has_image_snapshot.d.ts.map +1 -1
  14. package/esm/client/page/has_image_snapshot.js +1 -1
  15. package/esm/client/should_take_snapshot.d.ts +2 -2
  16. package/esm/client/should_take_snapshot.d.ts.map +1 -1
  17. package/esm/client/should_take_snapshot.js +3 -3
  18. package/esm/client/snapshot_options.d.ts +3 -6
  19. package/esm/client/snapshot_options.d.ts.map +1 -1
  20. package/esm/client/snapshot_options.js +19 -1
  21. package/esm/client/vitest_suite_proxy.d.ts +2 -1
  22. package/esm/client/vitest_suite_proxy.d.ts.map +1 -1
  23. package/esm/client.d.ts +1 -1
  24. package/esm/client.d.ts.map +1 -1
  25. package/esm/client.js +1 -1
  26. package/esm/config/types.d.ts +1 -1
  27. package/esm/config/types.d.ts.map +1 -1
  28. package/esm/index.d.ts +2 -1
  29. package/esm/index.d.ts.map +1 -1
  30. package/esm/index.js +1 -1
  31. package/esm/presets/enable.d.ts +3 -0
  32. package/esm/presets/enable.d.ts.map +1 -0
  33. package/esm/presets/enable.js +4 -0
  34. package/esm/server/vis_context.d.ts +4 -4
  35. package/esm/server/vis_context.d.ts.map +1 -1
  36. package/esm/server/vis_context.logic.d.ts +4 -4
  37. package/esm/server/vis_context.logic.d.ts.map +1 -1
  38. package/esm/server/vis_context.logic.js +4 -0
  39. package/esm/setup/create_vis.d.ts +18 -5
  40. package/esm/setup/create_vis.d.ts.map +1 -1
  41. package/esm/setup/create_vis.js +10 -30
  42. package/esm/setup/vis.d.ts +1 -14
  43. package/esm/setup/vis.d.ts.map +1 -1
  44. package/esm/shared/types.d.ts +21 -0
  45. package/esm/shared/types.d.ts.map +1 -1
  46. package/package.json +5 -1
  47. package/readme.md +37 -15
  48. package/src/client/ctx.ts +2 -0
  49. package/src/client/expect/to_match_image_snapshot.ts +1 -1
  50. package/src/client/expect/to_match_image_snapshot.types.ts +1 -16
  51. package/src/client/image_snapshot_matcher.logic.ts +1 -1
  52. package/src/client/image_snapshot_matcher.ts +12 -5
  53. package/src/client/page/has_image_snapshot.ts +6 -1
  54. package/src/client/should_take_snapshot.ts +4 -4
  55. package/src/client/snapshot_options.ts +27 -9
  56. package/src/client/vitest_suite_proxy.ts +3 -1
  57. package/src/client.ts +1 -1
  58. package/src/config/types.ts +1 -1
  59. package/src/index.ts +2 -1
  60. package/src/presets/enable.ts +5 -0
  61. package/src/server/vis_context.logic.ts +5 -1
  62. package/src/setup/create_vis.ts +73 -39
  63. package/src/shared/types.ts +22 -2
  64. package/esm/client/snapshot_options.internal.d.ts +0 -3
  65. package/esm/client/snapshot_options.internal.d.ts.map +0 -1
  66. package/esm/client/snapshot_options.internal.js +0 -20
  67. package/src/client/snapshot_options.internal.ts +0 -22
@@ -1,5 +1,6 @@
1
1
  export declare const ctx: {
2
- getCurrentTest: () => import("vitest").RunnerTestCase<object> | undefined;
2
+ autoEnabled: boolean | undefined;
3
+ getCurrentTest: () => import("../index.ts").CurrentTest;
3
4
  getCurrentSuite: () => import("vitest").SuiteCollector<object>;
4
5
  __test__reset(): void;
5
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/client/ctx.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG;;;;CAOf,CAAA"}
1
+ {"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/client/ctx.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG;iBACW,OAAO,GAAG,SAAS;;;;CAQ7C,CAAA"}
package/esm/client/ctx.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { getCurrentSuite, getCurrentTest } from "./vitest_suite_proxy.js";
2
2
  export const ctx = {
3
+ autoEnabled: undefined,
3
4
  getCurrentTest,
4
5
  getCurrentSuite,
5
6
  __test__reset() {
6
7
  ctx.getCurrentTest = getCurrentTest;
7
8
  ctx.getCurrentSuite = getCurrentSuite;
9
+ ctx.autoEnabled = undefined;
8
10
  },
9
11
  };
@@ -1,5 +1,5 @@
1
1
  import type { AsyncExpectationResult } from '@vitest/expect';
2
- import type { ToMatchImageSnapshotOptions } from './to_match_image_snapshot.types.ts';
2
+ import type { ToMatchImageSnapshotOptions } from '../../shared/types.ts';
3
3
  export declare function toMatchImageSnapshot(
4
4
  /**
5
5
  * The element or locator to take the snapshot of,
@@ -1 +1 @@
1
- {"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAI5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAA;AAErF,wBAAgB,oBAAoB;AACnC;;;GAGG;AACH,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,GAC/C,sBAAsB,CAcxB"}
1
+ {"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAKxE,wBAAgB,oBAAoB;AACnC;;;GAGG;AACH,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,GAC/C,sBAAsB,CAcxB"}
@@ -1,12 +1,5 @@
1
- import type { ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../../shared/types.ts';
1
+ import type { ComparisonMethod, ToMatchImageSnapshotOptions } from '../../shared/types.ts';
2
2
  export interface ImageSnapshotMatcher {
3
3
  toMatchImageSnapshot<M extends ComparisonMethod>(options?: ToMatchImageSnapshotOptions<M> | undefined): Promise<void>;
4
4
  }
5
- export type ToMatchImageSnapshotOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & {
6
- /**
7
- * Expect the matcher to fail.
8
- * If it passes, it will throw an error with details.
9
- */
10
- expectToFail?: boolean | undefined;
11
- };
12
5
  //# sourceMappingURL=to_match_image_snapshot.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"to_match_image_snapshot.types.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAE9B,MAAM,WAAW,oBAAoB;IACpC,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,EAAE,OAAO,CAAC,EAAE,2BAA2B,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrH;AAED,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,GAC1G,sBAAsB,GACtB,2BAA2B,CAAC,CAAC,CAAC,GAAG;IAChC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAClC,CAAA"}
1
+ {"version":3,"file":"to_match_image_snapshot.types.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAE1F,MAAM,WAAW,oBAAoB;IACpC,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,EAAE,OAAO,CAAC,EAAE,2BAA2B,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrH"}
@@ -1,9 +1,8 @@
1
- import type { Task } from 'vitest';
2
1
  import type { ImageSnapshotNextIndexCommand } from '../commands.ts';
3
2
  import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts';
4
3
  import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts';
5
- import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
6
- export declare function imageSnapshotMatcher(commands: PrepareImageSnapshotComparisonCommand & WriteImageSnapshotCommand & ImageSnapshotNextIndexCommand): (test: Task, subject: any, options?: ToMatchImageSnapshotOptions<any>) => Promise<void>;
4
+ import type { CurrentTest, ToMatchImageSnapshotOptions } from '../shared/types.ts';
5
+ export declare function imageSnapshotMatcher(commands: PrepareImageSnapshotComparisonCommand & WriteImageSnapshotCommand & ImageSnapshotNextIndexCommand): (test: CurrentTest & {}, subject: any, options?: ToMatchImageSnapshotOptions<any>) => Promise<void>;
7
6
  /**
8
7
  * @deprecated internalized. Use `matchImageSnapshot` directly instead.
9
8
  */
@@ -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;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
+ {"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,WAAW,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAQlF,wBAAgB,oBAAoB,CACnC,QAAQ,EAAE,qCAAqC,GAAG,yBAAyB,GAAG,6BAA6B,UAGpG,WAAW,GAAG,EAAE,WACb,GAAG,YACF,2BAA2B,CAAC,GAAG,CAAC,mBAoE3C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
@@ -10,8 +10,11 @@ import { toTaskId } from "./task_id.js";
10
10
  import { server } from "./vitest_browser_context_proxy.js";
11
11
  export function imageSnapshotMatcher(commands) {
12
12
  return async function matchImageSnapshot(test, subject, options) {
13
+ const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot;
13
14
  const taskId = toTaskId(test);
14
- const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options?.customizeSnapshotId ? await parseImageSnapshotOptions(commands, taskId, options) : options);
15
+ const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options?.customizeSnapshotId
16
+ ? await parseImageSnapshotOptions(commands, taskId, isAutoSnapshot, options)
17
+ : options);
15
18
  if (!info)
16
19
  return;
17
20
  options = { ...info, ...options };
@@ -69,9 +72,9 @@ async function writeSnapshot(commands, path, image) {
69
72
  const content = (await toDataURL(image)).split(',')[1];
70
73
  return commands.writeImageSnapshot(path, content);
71
74
  }
72
- async function parseImageSnapshotOptions(commands, taskId, options) {
75
+ async function parseImageSnapshotOptions(commands, taskId, isAutoSnapshot, options) {
73
76
  const index = await commands.imageSnapshotNextIndex(taskId);
74
77
  const { customizeSnapshotId, ...rest } = options;
75
- const snapshotFileId = customizeSnapshotId({ id: taskId, index });
78
+ const snapshotFileId = customizeSnapshotId({ id: taskId, index, isAutoSnapshot });
76
79
  return { ...rest, snapshotFileId };
77
80
  }
@@ -1,3 +1,3 @@
1
- import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
1
+ import type { ToMatchImageSnapshotOptions } from '../shared/types.ts';
2
2
  export declare function prettifyOptions(options: ToMatchImageSnapshotOptions<any> | undefined): string;
3
3
  //# sourceMappingURL=image_snapshot_matcher.logic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"image_snapshot_matcher.logic.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAE5F,wBAAgB,eAAe,CAAC,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,GAAG,SAAS,UAWpF"}
1
+ {"version":3,"file":"image_snapshot_matcher.logic.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.logic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAErE,wBAAgB,eAAe,CAAC,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,GAAG,SAAS,UAWpF"}
@@ -1 +1 @@
1
- {"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAInE,MAAM,WAAW,sBAAsB;IACtC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACnG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,oBAoB/F"}
1
+ {"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/page/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,yBAAyB,CAAA;AACpE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAInE,MAAM,WAAW,sBAAsB;IACtC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACnG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,oBAyB/F"}
@@ -17,7 +17,7 @@ export function hasImageSnapshot(options) {
17
17
  if (options?.customizeSnapshotId) {
18
18
  return commands
19
19
  .imageSnapshotNextIndex(taskId)
20
- .then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId({ id: taskId, index })));
20
+ .then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot: !!test.meta.vis?.isAutoSnapshot })));
21
21
  }
22
22
  return commands.hasImageSnapshot(taskId);
23
23
  }
@@ -1,4 +1,4 @@
1
- import type { SnapshotMeta } from './snapshot_options.ts';
1
+ import type { SnapshotMeta } from '../shared/types.ts';
2
2
  /**
3
3
  * Determine should snapshot be taken.
4
4
  *
@@ -6,5 +6,5 @@ import type { SnapshotMeta } from './snapshot_options.ts';
6
6
  * no `snapshot` tag: false
7
7
  * disabled by `!snapshot` tag: false
8
8
  */
9
- export declare function shouldTakeSnapshot(meta?: SnapshotMeta<any> | undefined): boolean;
9
+ export declare function shouldTakeSnapshot(meta?: SnapshotMeta<any> | undefined): boolean | undefined;
10
10
  //# sourceMappingURL=should_take_snapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"should_take_snapshot.d.ts","sourceRoot":"","sources":["../../src/client/should_take_snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,SAAS,WAGtE"}
1
+ {"version":3,"file":"should_take_snapshot.d.ts","sourceRoot":"","sources":["../../src/client/should_take_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAItD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,SAAS,uBAGtE"}
@@ -1,5 +1,5 @@
1
1
  import { ctx } from "./ctx.js";
2
- import { getAutoSnapshotOptions } from "./snapshot_options.internal.js";
2
+ import { extractAutoSnapshotOptions } from "./snapshot_options.js";
3
3
  /**
4
4
  * Determine should snapshot be taken.
5
5
  *
@@ -8,6 +8,6 @@ import { getAutoSnapshotOptions } from "./snapshot_options.internal.js";
8
8
  * disabled by `!snapshot` tag: false
9
9
  */
10
10
  export function shouldTakeSnapshot(meta) {
11
- const m = meta ?? getAutoSnapshotOptions(ctx.getCurrentTest());
12
- return document.body.childElementCount > 0 && m?.enable !== false;
11
+ const m = meta ?? extractAutoSnapshotOptions(ctx.getCurrentTest());
12
+ return document.body.childElementCount > 0 && m?.enable;
13
13
  }
@@ -1,9 +1,4 @@
1
- import type { AutoSnapshotOptions, ComparisonMethod } from '../shared/types.ts';
2
- import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
3
- export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions & {
4
- enable?: boolean | undefined;
5
- [key: string]: unknown;
6
- };
1
+ import type { ComparisonMethod, SnapshotMeta } from '../shared/types.ts';
7
2
  type Suite = {
8
3
  meta: Record<string, any>;
9
4
  suite?: Suite | undefined;
@@ -15,6 +10,7 @@ export type MetaTask = {
15
10
  suite?: Suite | undefined;
16
11
  meta: Record<string, any>;
17
12
  } | undefined;
13
+ export declare function enableAuto(): void;
18
14
  /**
19
15
  * Set the snapshot options for auto snapshot.
20
16
  *
@@ -32,5 +28,6 @@ export type MetaTask = {
32
28
  */
33
29
  export declare function setAutoSnapshotOptions<M extends ComparisonMethod>(task: MetaTask, meta: SnapshotMeta<M> | boolean): void;
34
30
  export declare function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: SnapshotMeta<M> | boolean): void;
31
+ export declare function extractAutoSnapshotOptions<M extends SnapshotMeta<any> = SnapshotMeta<any>>(task: MetaTask): M | undefined;
35
32
  export {};
36
33
  //# sourceMappingURL=snapshot_options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/snapshot_options.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,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AC,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,CAAA;KAAE,GAAG,SAAS,CAAA;IAChD,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACxB,GACD,SAAS,CAAA;AAEZ,wBAAgB,UAAU,SAEzB;AAED;;;;;;;;;;;;;;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;AAwBzG,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,EACzF,IAAI,EAAE,QAAQ,GACZ,CAAC,GAAG,SAAS,CAkBf"}
@@ -1,6 +1,8 @@
1
- import { getCurrentTest } from 'vitest/suite';
2
1
  import { NAME } from "../shared/constants.js";
3
2
  import { ctx } from "./ctx.js";
3
+ export function enableAuto() {
4
+ ctx.autoEnabled = true;
5
+ }
4
6
  export function setAutoSnapshotOptions(...args) {
5
7
  const [task, meta] = parseArgs(args);
6
8
  if (task)
@@ -17,3 +19,19 @@ function parseArgs(args) {
17
19
  function parseMeta(meta) {
18
20
  return typeof meta === 'boolean' ? { enable: meta } : { enable: true, ...meta };
19
21
  }
22
+ export function extractAutoSnapshotOptions(task) {
23
+ if (!task)
24
+ return;
25
+ const list = [];
26
+ let current = task;
27
+ while (current?.suite) {
28
+ list.unshift(current.suite.meta);
29
+ current = current.suite;
30
+ }
31
+ list.unshift(task.file?.meta);
32
+ list.push(task.meta);
33
+ return list.reduce((acc, cur) => {
34
+ const meta = cur?.[NAME];
35
+ return meta ? Object.assign({}, acc, meta) : acc;
36
+ }, { enable: ctx.autoEnabled });
37
+ }
@@ -1,3 +1,4 @@
1
- export declare const getCurrentTest: () => import("vitest").RunnerTestCase<object> | undefined;
1
+ import type { CurrentTest } from '../shared/types.ts';
2
+ export declare const getCurrentTest: () => CurrentTest;
2
3
  export declare const getCurrentSuite: () => import("vitest").SuiteCollector<object>;
3
4
  //# 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,2DAAsC,CAAA;AACjE,eAAO,MAAM,eAAe,+CAAuC,CAAA"}
1
+ {"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAUrD,eAAO,MAAM,cAAc,QAA0C,WAAW,CAAA;AAChF,eAAO,MAAM,eAAe,+CAAuC,CAAA"}
package/esm/client.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from './client/expect/expectation_result.ts';
2
2
  export type * from './client/expect/to_match_image_snapshot.types.ts';
3
3
  export * from './client/image_snapshot_matcher.ts';
4
4
  export * from './client/should_take_snapshot.ts';
5
- export * from './client/snapshot_options.ts';
5
+ export { setAutoSnapshotOptions, type MetaTask } from './client/snapshot_options.ts';
6
6
  export * from './client/task_id.ts';
7
7
  export type * from './shared/types.ts';
8
8
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,mBAAmB,kDAAkD,CAAA;AACrE,cAAc,oCAAoC,CAAA;AAClD,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,qBAAqB,CAAA;AACnC,mBAAmB,mBAAmB,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,mBAAmB,kDAAkD,CAAA;AACrE,cAAc,oCAAoC,CAAA;AAClD,cAAc,kCAAkC,CAAA;AAChD,OAAO,EAAE,sBAAsB,EAAE,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACpF,cAAc,qBAAqB,CAAA;AACnC,mBAAmB,mBAAmB,CAAA"}
package/esm/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./client/expect/expectation_result.js";
2
2
  export * from "./client/image_snapshot_matcher.js";
3
3
  export * from "./client/should_take_snapshot.js";
4
- export * from "./client/snapshot_options.js";
4
+ export { setAutoSnapshotOptions } from "./client/snapshot_options.js";
5
5
  export * from "./client/task_id.js";
@@ -4,7 +4,7 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
4
4
  /**
5
5
  * Loads the `test.setupFiles` of the specified preset.
6
6
  */
7
- preset?: 'manual' | 'auto' | 'none' | undefined;
7
+ preset?: 'enable' | 'manual' | 'auto' | 'none' | undefined;
8
8
  /**
9
9
  * The name of the subdirectory that the baseline snapshots get saved in.
10
10
  *
@@ -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,gBAA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A;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EACb,MAAM,GACN,CAAC,CAAC,OAAO,EAAE;QACX,EAAE,EAAE,OAAO,CAAA;QACX,WAAW,EAAE,MAAM,CAAA;QACnB,YAAY,EAAE,MAAM,CAAA;QACpB,QAAQ,EAAE,MAAM,CAAA;QAChB,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAA;QACvC,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAA;KACtC,KAAK,MAAM,CAAC,GACb,SAAS,CAAA;IACZ;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD,CAAA"}
package/esm/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import './client/expect/augment.ts';
2
2
  import './client/page/augment.ts';
3
- export * from './client/snapshot_options.ts';
3
+ export { setAutoSnapshotOptions, type MetaTask } from './client/snapshot_options.ts';
4
+ export type * from './shared/types.ts';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,4BAA4B,CAAA;AACnC,OAAO,0BAA0B,CAAA;AAEjC,cAAc,8BAA8B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,4BAA4B,CAAA;AACnC,OAAO,0BAA0B,CAAA;AAEjC,OAAO,EAAE,sBAAsB,EAAE,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACpF,mBAAmB,mBAAmB,CAAA"}
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // `vitest-plugin-vis` provides code that can be used in test files.
2
2
  import "./client/expect/augment.js";
3
3
  import "./client/page/augment.js";
4
- export * from "./client/snapshot_options.js";
4
+ export { setAutoSnapshotOptions } from "./client/snapshot_options.js";
@@ -0,0 +1,3 @@
1
+ import '../client/expect/extend.ts';
2
+ import '../client/page/extend.ts';
3
+ //# sourceMappingURL=enable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enable.d.ts","sourceRoot":"","sources":["../../src/presets/enable.ts"],"names":[],"mappings":"AACA,OAAO,4BAA4B,CAAA;AACnC,OAAO,0BAA0B,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { vis } from "../setup/vis.js";
2
+ import "../client/expect/extend.js";
3
+ import "../client/page/extend.js";
4
+ vis.presets.enable();
@@ -11,15 +11,17 @@ export declare const visContext: {
11
11
  resultPath: string;
12
12
  diffPath: string;
13
13
  timeout?: number | undefined | undefined;
14
- comparisonMethod: any;
15
- diffOptions?: Partial<import("ssim.js").Options> | undefined;
16
14
  failureThresholdType?: "pixel" | "percent" | undefined | undefined;
17
15
  failureThreshold?: number | undefined | undefined;
16
+ comparisonMethod: any;
17
+ diffOptions?: Partial<import("ssim.js").Options> | 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;
23
25
  comparisonMethod?: any;
24
26
  diffOptions?: {
25
27
  threshold?: number | undefined;
@@ -30,8 +32,6 @@ export declare const visContext: {
30
32
  diffColorAlt?: [number, number, number] | undefined;
31
33
  diffMask?: boolean | undefined;
32
34
  } | undefined;
33
- failureThresholdType?: "pixel" | "percent" | undefined | undefined;
34
- failureThreshold?: number | undefined | undefined;
35
35
  };
36
36
  getTaskCount(testPath: string, taskId: string): number;
37
37
  hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBAC69C,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADz8C,CAAA"}
1
+ {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBACikD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAD7iD,CAAA"}
@@ -18,15 +18,17 @@ export declare function createVisContext(): {
18
18
  resultPath: string;
19
19
  diffPath: string;
20
20
  timeout?: number | undefined | undefined;
21
- comparisonMethod: any;
22
- diffOptions?: Partial<import("ssim.js").Options> | undefined;
23
21
  failureThresholdType?: "pixel" | "percent" | undefined | undefined;
24
22
  failureThreshold?: number | undefined | undefined;
23
+ comparisonMethod: any;
24
+ diffOptions?: Partial<import("ssim.js").Options> | 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;
30
32
  comparisonMethod?: any;
31
33
  diffOptions?: {
32
34
  threshold?: number | undefined;
@@ -37,8 +39,6 @@ export declare function createVisContext(): {
37
39
  diffColorAlt?: [number, number, number] | undefined;
38
40
  diffMask?: boolean | undefined;
39
41
  } | undefined;
40
- failureThresholdType?: "pixel" | "percent" | undefined | undefined;
41
- failureThreshold?: number | undefined | undefined;
42
42
  };
43
43
  getTaskCount(testPath: string, taskId: string): number;
44
44
  hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined): Promise<boolean>;
@@ -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,4BAA4B,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEpF,wBAAgB,gB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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;2BAWlF,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,5 +1,6 @@
1
1
  import { join, relative } from 'pathe';
2
2
  import { pick } from 'type-plus';
3
+ import { getCurrentTest } from 'vitest/suite';
3
4
  import { BASELINE_DIR, DIFF_DIR, RESULT_DIR } from "../shared/constants.js";
4
5
  import { file } from "./file.js";
5
6
  import { getSnapshotSubpath, resolveSnapshotRootDir } from "./snapshot_path.js";
@@ -64,10 +65,13 @@ export function createVisContext() {
64
65
  getSnapshotFilename(info, snapshotFileId) {
65
66
  if (snapshotFileId)
66
67
  return `${snapshotFileId}.png`;
68
+ const test = getCurrentTest();
69
+ const isAutoSnapshot = !!test?.meta.vis?.isAutoSnapshot;
67
70
  const customizeSnapshotId = visOptions.customizeSnapshotId ?? (({ id, index }) => `${id}-${index}`);
68
71
  return `${customizeSnapshotId({
69
72
  id: info.taskId,
70
73
  index: info.task.count,
74
+ isAutoSnapshot,
71
75
  })}.png`;
72
76
  },
73
77
  getSuiteInfo(testPath, taskId) {
@@ -1,9 +1,21 @@
1
- import { type SnapshotMeta } from '../client.ts';
1
+ import { type ComparisonMethod, type SnapshotMeta } from '../client.ts';
2
2
  import type { SetupVisSuiteCommand } from '../server/commands/setup_vis_suite.ts';
3
- export declare function createVis<M extends SnapshotMeta<any>>(commands: SetupVisSuiteCommand): {
3
+ /**
4
+ * Visual test configuration on the client side.
5
+ */
6
+ export type VisClientConfigurator<SM extends SnapshotMeta<ComparisonMethod>> = {
4
7
  presets: {
5
8
  /**
6
- * Enable manual visual testing.
9
+ * Enable visual testing.
10
+ *
11
+ * auto snapshot is turned off by default.
12
+ * You can specify the test to take a snapshot during `afterEach()` hook with `setAutoSnapshotOptions()`.
13
+ */
14
+ enable(): void;
15
+ /**
16
+ * Enable visual testing.
17
+ *
18
+ * `setAutoSnapshotOptions` will have no effect in this preset.
7
19
  */
8
20
  manual(): void;
9
21
  /**
@@ -27,14 +39,15 @@ export declare function createVis<M extends SnapshotMeta<any>>(commands: SetupVi
27
39
  * })
28
40
  * ```
29
41
  */
30
- theme(themes: Record<string, (options: M) => Promise<boolean> | Promise<void> | boolean | void>): void;
42
+ theme<M>(themes: Record<string, (options: M & SM) => Promise<boolean> | Promise<void> | boolean | void>): void;
31
43
  };
32
44
  beforeAll: {
33
45
  setup(): Promise<void>;
34
46
  };
35
47
  afterEach: {
36
48
  matchImageSnapshot(): Promise<void>;
37
- matchPerTheme(themes: Record<string, (options: M) => Promise<boolean> | Promise<void> | boolean | void>): () => Promise<void>;
49
+ matchPerTheme<M>(themes: Record<string, (options: M & SM) => Promise<boolean> | Promise<void> | boolean | void>): () => Promise<void>;
38
50
  };
39
51
  };
52
+ export declare function createVis<SM extends SnapshotMeta<ComparisonMethod>>(commands: SetupVisSuiteCommand): VisClientConfigurator<SM>;
40
53
  //# sourceMappingURL=create_vis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create_vis.d.ts","sourceRoot":"","sources":["../../src/setup/create_vis.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAY,MAAM,cAAc,CAAA;AAI1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAEjF,wBAAgB,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SAAS,EAAE;QACV,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;QACnC,aAAa,CAAC,CAAC,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,GAC5F,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;KACtB,CAAA;CACD,CAAA;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,YAAY,CAAC,gBAAgB,CAAC,EAAE,QAAQ,EAAE,oBAAoB,6BAoFlG"}
@@ -3,44 +3,23 @@ import { afterEach, beforeAll } from 'vitest';
3
3
  import { toTaskId } from "../client.js";
4
4
  import { ctx } from "../client/ctx.js";
5
5
  import { shouldTakeSnapshot } from "../client/should_take_snapshot.js";
6
- import { getAutoSnapshotOptions } from '../client/snapshot_options.internal.js';
6
+ import { enableAuto, extractAutoSnapshotOptions } from "../client/snapshot_options.js";
7
7
  export function createVis(commands) {
8
8
  let subjectDataTestId;
9
- /**
10
- * Visual test configuration on the client side.
11
- */
12
9
  const vis = {
13
10
  presets: {
14
- /**
15
- * Enable manual visual testing.
16
- */
11
+ enable() {
12
+ beforeAll(vis.beforeAll.setup);
13
+ afterEach(vis.afterEach.matchImageSnapshot);
14
+ },
17
15
  manual() {
18
16
  beforeAll(vis.beforeAll.setup);
19
17
  },
20
- /**
21
- * Enable automatic visual testing.
22
- *
23
- * This will take a snapshot after each test.
24
- */
25
18
  auto() {
26
19
  beforeAll(vis.beforeAll.setup);
27
20
  afterEach(vis.afterEach.matchImageSnapshot);
21
+ enableAuto();
28
22
  },
29
- /**
30
- * Enable automatic visual testing with multiple themes.
31
- *
32
- * This will take a snapshot after each test for each theme.
33
- *
34
- * @param themes A record of theme names and their setup functions.
35
- *
36
- * @example
37
- * ```ts
38
- * vis().presets.theme({
39
- * light() { document.body.classList.add('light') },
40
- * dark() { document.body.classList.add('dark') },
41
- * })
42
- * ```
43
- */
44
23
  theme(themes) {
45
24
  beforeAll(vis.beforeAll.setup);
46
25
  afterEach(vis.afterEach.matchPerTheme(themes));
@@ -56,9 +35,10 @@ export function createVis(commands) {
56
35
  const test = ctx.getCurrentTest();
57
36
  if ((test?.result?.errors?.length ?? 0) > 0)
58
37
  return;
59
- const meta = getAutoSnapshotOptions(test);
38
+ const meta = extractAutoSnapshotOptions(test);
60
39
  if (!shouldTakeSnapshot(meta))
61
40
  return;
41
+ test.meta.vis = { ...test.meta.vis, isAutoSnapshot: true };
62
42
  await test.context.expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta);
63
43
  },
64
44
  matchPerTheme(themes) {
@@ -66,7 +46,7 @@ export function createVis(commands) {
66
46
  const test = ctx.getCurrentTest();
67
47
  if ((test?.result?.errors?.length ?? 0) > 0)
68
48
  return;
69
- const meta = getAutoSnapshotOptions(test);
49
+ const meta = extractAutoSnapshotOptions(test);
70
50
  if (!shouldTakeSnapshot(meta))
71
51
  return;
72
52
  const errors = [];
@@ -81,7 +61,7 @@ export function createVis(commands) {
81
61
  .toMatchImageSnapshot({
82
62
  ...meta,
83
63
  customizeSnapshotId: meta?.customizeSnapshotId
84
- ? ({ id, index }) => `${meta.customizeSnapshotId({ id, index })}-${themeId}`
64
+ ? ({ id, index }) => `${meta.customizeSnapshotId({ id, index, isAutoSnapshot: true })}-${themeId}`
85
65
  : ({ id }) => `${id}-${themeId}`,
86
66
  });
87
67
  }
@@ -1,18 +1,5 @@
1
1
  /**
2
2
  * Visual test configuration on the client side.
3
3
  */
4
- export declare const vis: {
5
- presets: {
6
- manual(): void;
7
- auto(): void;
8
- theme(themes: Record<string, (options: import("../client.ts").SnapshotMeta<any>) => Promise<boolean> | Promise<void> | boolean | void>): void;
9
- };
10
- beforeAll: {
11
- setup(): Promise<void>;
12
- };
13
- afterEach: {
14
- matchImageSnapshot(): Promise<void>;
15
- matchPerTheme(themes: Record<string, (options: import("../client.ts").SnapshotMeta<any>) => Promise<boolean> | Promise<void> | boolean | void>): () => Promise<void>;
16
- };
17
- };
4
+ export declare const vis: import("./create_vis.ts").VisClientConfigurator<import("../index.ts").SnapshotMeta<import("../index.ts").ComparisonMethod>>;
18
5
  //# sourceMappingURL=vis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vis.d.ts","sourceRoot":"","sources":["../../src/setup/vis.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;CAAsB,CAAA"}
1
+ {"version":3,"file":"vis.d.ts","sourceRoot":"","sources":["../../src/setup/vis.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,GAAG,6HAAsB,CAAA"}
@@ -1,5 +1,7 @@
1
1
  import type pixelMatch from 'pixelmatch';
2
2
  import type { Options as SsimOptions } from 'ssim.js';
3
+ import type { getCurrentTest } from 'vitest/suite';
4
+ import type { NAME } from './constants.ts';
3
5
  export interface ImageSnapshotTimeoutOptions {
4
6
  /**
5
7
  * Timeout for taking the snapshot.
@@ -18,6 +20,7 @@ export interface ImageSnapshotIdOptions {
18
20
  customizeSnapshotId?: (context: {
19
21
  id: string;
20
22
  index: number;
23
+ isAutoSnapshot: boolean;
21
24
  }) => string;
22
25
  }
23
26
  export type ComparisonMethod = 'pixel' | 'ssim';
@@ -59,4 +62,22 @@ export type AutoSnapshotOptions = {
59
62
  */
60
63
  subjectDataTestId?: string | undefined;
61
64
  };
65
+ export type ToMatchImageSnapshotOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & {
66
+ /**
67
+ * Expect the matcher to fail.
68
+ * If it passes, it will throw an error with details.
69
+ */
70
+ expectToFail?: boolean | undefined;
71
+ };
72
+ export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions & {
73
+ enable?: boolean | undefined;
74
+ [key: string]: unknown;
75
+ };
76
+ export type CurrentTest = ReturnType<typeof getCurrentTest> & {
77
+ meta: {
78
+ [NAME]?: SnapshotMeta<'pixel' | 'ssim'> & {
79
+ isAutoSnapshot?: boolean | undefined;
80
+ };
81
+ };
82
+ };
62
83
  //# sourceMappingURL=types.d.ts.map