vitest-plugin-vis 1.3.2 → 1.5.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 (57) hide show
  1. package/esm/client/expect/to_match_image_snapshot.types.d.ts +4 -4
  2. package/esm/client/expect/to_match_image_snapshot.types.d.ts.map +1 -1
  3. package/esm/client/image_snapshot_matcher.d.ts +1 -1
  4. package/esm/client/image_snapshot_matcher.d.ts.map +1 -1
  5. package/esm/client/image_snapshot_matcher.js +1 -0
  6. package/esm/client/image_snapshot_matcher.logic.d.ts +1 -1
  7. package/esm/client/image_snapshot_matcher.logic.d.ts.map +1 -1
  8. package/esm/client/image_snapshot_matcher.logic.js +3 -2
  9. package/esm/client/should_take_snapshot.d.ts +1 -1
  10. package/esm/client/should_take_snapshot.d.ts.map +1 -1
  11. package/esm/client/snapshot_options.d.ts +4 -3
  12. package/esm/client/snapshot_options.d.ts.map +1 -1
  13. package/esm/client/snapshot_options.internal.d.ts +1 -1
  14. package/esm/client/snapshot_options.internal.d.ts.map +1 -1
  15. package/esm/config/types.d.ts +12 -3
  16. package/esm/config/types.d.ts.map +1 -1
  17. package/esm/config/vis.d.ts +2 -1
  18. package/esm/config/vis.d.ts.map +1 -1
  19. package/esm/server/commands/match_image_snapshot.d.ts +2 -2
  20. package/esm/server/commands/match_image_snapshot.d.ts.map +1 -1
  21. package/esm/server/commands/match_image_snapshot.js +1 -2
  22. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +2 -1
  23. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
  24. package/esm/server/commands/prepare_image_snapshot_comparison.js +1 -2
  25. package/esm/server/snapshot_path.d.ts +2 -2
  26. package/esm/server/snapshot_path.d.ts.map +1 -1
  27. package/esm/server/vis_context.ctx.d.ts.map +1 -1
  28. package/esm/server/vis_context.ctx.js +0 -1
  29. package/esm/server/vis_context.d.ts +16 -2
  30. package/esm/server/vis_context.d.ts.map +1 -1
  31. package/esm/server/vis_context.logic.d.ts +18 -4
  32. package/esm/server/vis_context.logic.d.ts.map +1 -1
  33. package/esm/server/vis_context.logic.js +3 -1
  34. package/esm/setup/create_vis.js +1 -1
  35. package/esm/shared/compare_image.d.ts +2 -2
  36. package/esm/shared/compare_image.d.ts.map +1 -1
  37. package/esm/shared/compare_image.js +36 -4
  38. package/esm/shared/types.d.ts +20 -7
  39. package/esm/shared/types.d.ts.map +1 -1
  40. package/package.json +3 -1
  41. package/readme.md +12 -7
  42. package/src/client/expect/to_match_image_snapshot.types.ts +11 -11
  43. package/src/client/image_snapshot_matcher.logic.ts +4 -3
  44. package/src/client/image_snapshot_matcher.ts +5 -2
  45. package/src/client/should_take_snapshot.ts +1 -1
  46. package/src/client/snapshot_options.internal.ts +1 -1
  47. package/src/client/snapshot_options.ts +14 -10
  48. package/src/config/types.ts +51 -34
  49. package/src/config/vis.ts +2 -1
  50. package/src/server/commands/match_image_snapshot.ts +9 -11
  51. package/src/server/commands/prepare_image_snapshot_comparison.ts +10 -3
  52. package/src/server/snapshot_path.ts +2 -2
  53. package/src/server/vis_context.ctx.ts +0 -1
  54. package/src/server/vis_context.logic.ts +11 -6
  55. package/src/setup/create_vis.ts +1 -1
  56. package/src/shared/compare_image.ts +55 -6
  57. package/src/shared/types.ts +25 -6
@@ -1,12 +1,12 @@
1
- import type { ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../../shared/types.ts';
1
+ import type { ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../../shared/types.ts';
2
2
  export interface ImageSnapshotMatcher {
3
- toMatchImageSnapshot(options?: ToMatchImageSnapshotOptions | undefined): Promise<void>;
3
+ toMatchImageSnapshot<M extends ComparisonMethod>(options?: ToMatchImageSnapshotOptions<M> | undefined): Promise<void>;
4
4
  }
5
- export interface ToMatchImageSnapshotOptions extends ImageSnapshotTimeoutOptions, ImageSnapshotIdOptions, ImageSnapshotCompareOptions {
5
+ export type ToMatchImageSnapshotOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & {
6
6
  /**
7
7
  * Expect the matcher to fail.
8
8
  * If it passes, it will throw an error with details.
9
9
  */
10
10
  expectToFail?: boolean | undefined;
11
- }
11
+ };
12
12
  //# 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,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAE9B,MAAM,WAAW,oBAAoB;IACpC,oBAAoB,CAAC,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACtF;AAED,MAAM,WAAW,2BAChB,SAAQ,2BAA2B,EAClC,sBAAsB,EACtB,2BAA2B;IAC5B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAClC"}
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"}
@@ -3,7 +3,7 @@ import type { ImageSnapshotNextIndexCommand } from '../commands.ts';
3
3
  import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts';
4
4
  import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts';
5
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) => Promise<void>;
6
+ export declare function imageSnapshotMatcher(commands: PrepareImageSnapshotComparisonCommand & WriteImageSnapshotCommand & ImageSnapshotNextIndexCommand): (test: Task, subject: any, options?: ToMatchImageSnapshotOptions<any>) => Promise<void>;
7
7
  /**
8
8
  * @deprecated internalized. Use `matchImageSnapshot` directly instead.
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"image_snapshot_matcher.d.ts","sourceRoot":"","sources":["../../src/client/image_snapshot_matcher.ts"],"names":[],"mappings":"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,mBA8DxG;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;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"}
@@ -14,6 +14,7 @@ export function imageSnapshotMatcher(commands) {
14
14
  const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options?.customizeSnapshotId ? await parseImageSnapshotOptions(commands, taskId, options) : options);
15
15
  if (!info)
16
16
  return;
17
+ options = { ...info, ...options };
17
18
  const baselineImage = await toImageData(info.baseline);
18
19
  const resultImage = await toImageData(info.result);
19
20
  const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage);
@@ -1,3 +1,3 @@
1
1
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
2
- export declare function prettifyOptions(options: ToMatchImageSnapshotOptions | undefined): string;
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,GAAG,SAAS,UAU/E"}
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"}
@@ -3,9 +3,10 @@ export function prettifyOptions(options) {
3
3
  return 'none';
4
4
  return [
5
5
  `failureThreshold: ${options.failureThreshold ?? 0} ${options.failureThresholdType ?? 'pixels'}`,
6
- options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
7
6
  options.timeout ? `timeout: ${options.timeout} ms` : '',
7
+ `comparisonMethod: ${options.comparisonMethod ?? 'pixel'}`,
8
+ options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
8
9
  ]
9
10
  .filter(Boolean)
10
- .join(', ');
11
+ .join('\n ');
11
12
  }
@@ -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 | undefined): boolean;
9
+ export declare function shouldTakeSnapshot(meta?: SnapshotMeta<any> | undefined): boolean;
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,GAAG,SAAS,WAGjE"}
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,5 +1,6 @@
1
+ import type { ComparisonMethod } from '../shared/types.ts';
1
2
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
2
- export type SnapshotMeta = ToMatchImageSnapshotOptions & {
3
+ export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & {
3
4
  enable?: boolean | undefined;
4
5
  };
5
6
  type Suite = {
@@ -28,7 +29,7 @@ export type MetaTask = {
28
29
  * @param task Optional. Suite or task to set the options.
29
30
  * If not provided, it will set the options for the current test.
30
31
  */
31
- export declare function setAutoSnapshotOptions(task: MetaTask, meta: SnapshotMeta | boolean): void;
32
- export declare function setAutoSnapshotOptions(meta: SnapshotMeta | boolean): void;
32
+ export declare function setAutoSnapshotOptions<M extends ComparisonMethod>(task: MetaTask, meta: SnapshotMeta<M> | boolean): void;
33
+ export declare function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: SnapshotMeta<M> | boolean): void;
33
34
  export {};
34
35
  //# 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,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAE5F,MAAM,MAAM,YAAY,GAAG,2BAA2B,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,CAAA;AAEzF,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM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,SAAS,CAAA;IACzB,IAAI,EAAE,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,3 +1,3 @@
1
1
  import type { MetaTask, SnapshotMeta } from './snapshot_options.ts';
2
- export declare function getAutoSnapshotOptions(task: MetaTask): SnapshotMeta | undefined;
2
+ export declare function getAutoSnapshotOptions(task: MetaTask): SnapshotMeta<any> | undefined;
3
3
  //# sourceMappingURL=snapshot_options.internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot_options.internal.d.ts","sourceRoot":"","sources":["../../src/client/snapshot_options.internal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEnE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,GAAG,SAAS,CAkB/E"}
1
+ {"version":3,"file":"snapshot_options.internal.d.ts","sourceRoot":"","sources":["../../src/client/snapshot_options.internal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEnE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,SAAS,CAkBpF"}
@@ -1,9 +1,18 @@
1
- import type { ToMatchImageSnapshotOptions } from '../client/expect/to_match_image_snapshot.types.ts';
2
- export interface VisOptions extends ToMatchImageSnapshotOptions {
1
+ import type { ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../shared/types.ts';
2
+ export type { ComparisonMethod };
3
+ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & {
3
4
  /**
4
5
  * Loads the `test.setupFiles` of the specified preset.
5
6
  */
6
7
  preset?: 'manual' | 'auto' | 'none' | undefined;
8
+ /**
9
+ * The name of the subdirectory that the baseline snapshots get saved in.
10
+ *
11
+ * <snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png
12
+ *
13
+ * Default: undefined
14
+ */
15
+ platform?: string | undefined;
7
16
  /**
8
17
  * The snapshot folder relative to the root of the project.
9
18
  *
@@ -31,5 +40,5 @@ export interface VisOptions extends ToMatchImageSnapshotOptions {
31
40
  * If you want to keep the full path, you can simply return it.
32
41
  */
33
42
  customizeSnapshotSubpath?: (subPath: string) => string;
34
- }
43
+ };
35
44
  //# 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,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAA;AAEpG,MAAM,WAAW,UAAW,SAAQ,2BAA2B;IAC9D;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/C;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD"}
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,3 +1,4 @@
1
+ import type { ComparisonMethod } from '../shared/types.ts';
1
2
  import type { VisOptions } from './types.ts';
2
3
  /**
3
4
  * Create a Vite plugin for visual testing.
@@ -5,7 +6,7 @@ import type { VisOptions } from './types.ts';
5
6
  * If options are not provided, the plugin will use the default options,
6
7
  * which enables the `auto` preset.
7
8
  */
8
- export declare function vis(options?: VisOptions): {
9
+ export declare function vis<M extends ComparisonMethod = 'pixel'>(options?: VisOptions<M>): {
9
10
  name: string;
10
11
  config(this: void): {
11
12
  test: {
@@ -1 +1 @@
1
- {"version":3,"file":"vis.d.ts","sourceRoot":"","sources":["../../src/config/vis.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,OAAO,GAAE,UAA+B;;;;;sBASxB,MAAM;;;;;;;;;;;;;EAQzC"}
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;;;;;sBASxE,MAAM;;;;;;;;;;;;;EAQzC"}
@@ -3,12 +3,12 @@ import type { ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshot
3
3
  export interface MatchImageSnapshotCommand {
4
4
  matchImageSnapshot: (taskId: string | undefined, subject: string, options?: MatchImageSnapshotOptions | undefined) => Promise<void>;
5
5
  }
6
- export interface MatchImageSnapshotOptions extends ImageSnapshotTimeoutOptions, ImageSnapshotIdOptions, ImageSnapshotCompareOptions {
6
+ export type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<any> & {
7
7
  /**
8
8
  * The snapshot file id calculated on the client side.
9
9
  */
10
10
  snapshotFileId?: string | undefined;
11
- }
11
+ };
12
12
  export declare const matchImageSnapshot: BrowserCommand<[
13
13
  taskId: string,
14
14
  subject: string,
@@ -1 +1 @@
1
- {"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/match_image_snapshot.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAKjD,OAAO,KAAK,EACX,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAM9B,MAAM,WAAW,yBAAyB;IACzC,kBAAkB,EAAE,CACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,IAAI,CAAC,CAAA;CAClB;AAED,MAAM,WAAW,yBAChB,SAAQ,2BAA2B,EAClC,sBAAsB,EACtB,2BAA2B;IAC5B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC;AAED,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAC9C;IAAC,MAAM,EAAE,MAAM;IAAE,OAAO,EAAE,MAAM;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CAuElF,CAAA"}
1
+ {"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/match_image_snapshot.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAKjD,OAAO,KAAK,EACX,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,uBAAuB,CAAA;AAM9B,MAAM,WAAW,yBAAyB;IACzC,kBAAkB,EAAE,CACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS,KAC3C,OAAO,CAAC,IAAI,CAAC,CAAA;CAClB;AAED,MAAM,MAAM,yBAAyB,GAAG,2BAA2B,GAClE,sBAAsB,GACtB,2BAA2B,CAAC,GAAG,CAAC,GAAG;IAClC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC,CAAA;AAEF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAC9C;IAAC,MAAM,EAAE,MAAM;IAAE,OAAO,EAAE,MAAM;IAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CAuElF,CAAA"}
@@ -1,5 +1,4 @@
1
1
  import dedent from 'dedent';
2
- import ci from 'is-ci';
3
2
  import { resolve } from 'pathe';
4
3
  import { PNG } from 'pngjs';
5
4
  import { isBase64String } from "../../shared/base64.js";
@@ -15,7 +14,7 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
15
14
  // vitest:browser passes in `null` when not defined
16
15
  if (!options)
17
16
  options = {};
18
- options.timeout = options.timeout ?? (ci ? 30000 : 5000);
17
+ options.timeout = options.timeout ?? 30000;
19
18
  const info = visContext.getSnapshotInfo(context.testPath, taskId, options);
20
19
  const baselineBuffer = await file.tryReadFile(info.baselinePath);
21
20
  if (!baselineBuffer) {
@@ -1,4 +1,5 @@
1
1
  import type { BrowserCommand } from 'vitest/node';
2
+ import type { FailureThresholdOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions } from '../../shared/types.ts';
2
3
  import type { MatchImageSnapshotOptions } from './match_image_snapshot.ts';
3
4
  type ImageSnapshotComparisonInfo = {
4
5
  projectRoot: string;
@@ -7,7 +8,7 @@ type ImageSnapshotComparisonInfo = {
7
8
  diffPath: string;
8
9
  baseline: string;
9
10
  result: string;
10
- };
11
+ } & ImageSnapshotTimeoutOptions & FailureThresholdOptions & (SsimComparisonOptions | PixelComparisonOptions);
11
12
  export interface PrepareImageSnapshotComparisonCommand {
12
13
  prepareImageSnapshotComparison: (taskId: string | undefined, subject: string, options?: MatchImageSnapshotOptions | undefined) => Promise<ImageSnapshotComparisonInfo | undefined>;
13
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prepare_image_snapshot_comparison.d.ts","sourceRoot":"","sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAMjD,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,CAAA;AAED,MAAM,WAAW,qCAAqC;IACrD,8BAA8B,EAAE,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,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,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CA0BrF,CAAA"}
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,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,OAAO,CAAC,EAAE,yBAAyB,GAAG,SAAS;CAAC,CA0BrF,CAAA"}
@@ -1,4 +1,3 @@
1
- import ci from 'is-ci';
2
1
  import { isBase64String } from "../../shared/base64.js";
3
2
  import { file } from "../file.js";
4
3
  import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from "../snapshot.js";
@@ -9,7 +8,7 @@ export const prepareImageSnapshotComparison = async (context, taskId, subject, o
9
8
  // vitest:browser passes in `null` when not defined
10
9
  if (!options)
11
10
  options = {};
12
- options.timeout = options.timeout ?? (ci ? 30000 : 5000);
11
+ options.timeout = options.timeout ?? 30000;
13
12
  const info = visContext.getSnapshotInfo(context.testPath, taskId, options);
14
13
  const baselineBuffer = await file.tryReadFile(info.baselinePath);
15
14
  if (!baselineBuffer) {
@@ -1,4 +1,4 @@
1
1
  import type { VisOptions } from '../config/types.ts';
2
- export declare function resolveSnapshotRootDir(options: VisOptions | undefined): string;
3
- export declare function getSnapshotSubpath(suiteName: string, options: VisOptions): string;
2
+ export declare function resolveSnapshotRootDir(options: Pick<VisOptions, 'snapshotRootDir'> | undefined): string;
3
+ export declare function getSnapshotSubpath(suiteName: string, options: Pick<VisOptions, 'customizeSnapshotSubpath'>): string;
4
4
  //# sourceMappingURL=snapshot_path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot_path.d.ts","sourceRoot":"","sources":["../../src/server/snapshot_path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAIpD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,UAErE;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,UAGxE"}
1
+ {"version":3,"file":"snapshot_path.d.ts","sourceRoot":"","sources":["../../src/server/snapshot_path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAIpD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,GAAG,SAAS,UAE9F;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,0BAA0B,CAAC,UAG1G"}
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.ctx.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ctx.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,GAAG;;6CAQ2qD,CAAC;2CAAkF,CAAC;iDAA8E,CAAC;8CAA2E,CAAC;+CAA0F,CAAC;;iDAAqF,CAAC;8CAA2E,CAAC;+CAA0F,CAAC;;iDAAqF,CAAC;6CAA0E,CAAC;+CAA0F,CAAC;;gDAAoF,CAAC;+CAA4E,CAAC;+CAA0F,CAAC;;kDAAsF,CAAC;kDAA+E,CAAC;+CAA0F,CAAC;;qDAAyF,CAAC;;;CAFtlG,CAAA"}
1
+ {"version":3,"file":"vis_context.ctx.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ctx.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,GAAG;;6CAOksD,CAAC;2CAAkF,CAAC;iDAA8E,CAAC;8CAA2E,CAAC;+CAA0F,CAAC;;iDAAqF,CAAC;8CAA2E,CAAC;+CAA0F,CAAC;;iDAAqF,CAAC;6CAA0E,CAAC;+CAA0F,CAAC;;gDAAoF,CAAC;+CAA4E,CAAC;+CAA0F,CAAC;;kDAAsF,CAAC;kDAA+E,CAAC;+CAA0F,CAAC;;qDAAyF,CAAC;;;CAF7mG,CAAA"}
@@ -4,7 +4,6 @@ import { rimraf } from 'rimraf';
4
4
  export const ctx = {
5
5
  rimraf,
6
6
  getSnapshotPlatform() {
7
- /* v8 ignore next */
8
7
  return ci ? process.platform : 'local';
9
8
  },
10
9
  };
@@ -1,6 +1,6 @@
1
1
  export declare const visContext: {
2
- setOptions(options?: import("../config.ts").VisOptions): void;
3
- __test__getOptions(): import("../config.ts").VisOptions;
2
+ setOptions<M extends "pixel" | "ssim">(options?: import("../config.ts").VisOptions<M>): void;
3
+ __test__getOptions(): import("../config.ts").VisOptions<any>;
4
4
  __test__reset(): void;
5
5
  __test__getState(): import("./vis_context.types.ts").VisState;
6
6
  setupSuite(context: import("./vis_context.logic.ts").PartialBrowserCommandContext): Promise<void>;
@@ -10,6 +10,20 @@ export declare const visContext: {
10
10
  baselinePath: string;
11
11
  resultPath: string;
12
12
  diffPath: string;
13
+ timeout?: number | undefined | undefined;
14
+ comparisonMethod: any;
15
+ diffOptions?: Partial<import("ssim.js").Options> | undefined;
16
+ failureThresholdType?: "pixel" | "percent" | undefined | undefined;
17
+ failureThreshold?: number | undefined | undefined;
18
+ } | {
19
+ baselinePath: string;
20
+ resultPath: string;
21
+ diffPath: string;
22
+ timeout?: number | undefined | undefined;
23
+ comparisonMethod?: any;
24
+ diffOptions?: import("pixelmatch").PixelmatchOptions | undefined;
25
+ failureThresholdType?: "pixel" | "percent" | undefined | undefined;
26
+ failureThreshold?: number | undefined | undefined;
13
27
  };
14
28
  getTaskCount(testPath: string, taskId: string): number;
15
29
  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;;;;;;;sBAC+hD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;CAD3gD,CAAA"}
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"}
@@ -14,8 +14,8 @@ export type PartialBrowserCommandContext = {
14
14
  testPath: string;
15
15
  };
16
16
  export declare function createVisContext(): {
17
- setOptions(options?: VisOptions): void;
18
- __test__getOptions(): VisOptions;
17
+ setOptions<M extends "pixel" | "ssim">(options?: VisOptions<M>): void;
18
+ __test__getOptions(): VisOptions<any>;
19
19
  __test__reset(): void;
20
20
  __test__getState(): VisState;
21
21
  /**
@@ -30,6 +30,20 @@ export declare function createVisContext(): {
30
30
  baselinePath: string;
31
31
  resultPath: string;
32
32
  diffPath: string;
33
+ timeout?: number | undefined | undefined;
34
+ comparisonMethod: any;
35
+ diffOptions?: Partial<import("ssim.js").Options> | undefined;
36
+ failureThresholdType?: "pixel" | "percent" | undefined | undefined;
37
+ failureThreshold?: number | undefined | undefined;
38
+ } | {
39
+ baselinePath: string;
40
+ resultPath: string;
41
+ diffPath: string;
42
+ timeout?: number | undefined | undefined;
43
+ comparisonMethod?: any;
44
+ diffOptions?: import("pixelmatch").PixelmatchOptions | undefined;
45
+ failureThresholdType?: "pixel" | "percent" | undefined | undefined;
46
+ failureThreshold?: number | undefined | undefined;
33
47
  };
34
48
  getTaskCount(testPath: string, taskId: string): number;
35
49
  hasImageSnapshot(testPath: string, taskId: string, snapshotFileId: string | undefined): Promise<boolean>;
@@ -50,7 +64,7 @@ export declare function createVisContext(): {
50
64
  };
51
65
  };
52
66
  };
53
- export declare function createSuite(state: VisState, testPath: string, options: VisOptions): {
67
+ export declare function createSuite(state: VisState, testPath: string, options: Pick<VisOptions, 'customizeSnapshotSubpath'>): {
54
68
  suiteId: string;
55
69
  suite: {
56
70
  baselineDir: string;
@@ -59,5 +73,5 @@ export declare function createSuite(state: VisState, testPath: string, options:
59
73
  tasks: {};
60
74
  };
61
75
  };
62
- export declare function getSuiteId(state: VisState, testPath: string, options: VisOptions): string;
76
+ export declare function getSuiteId(state: VisState, testPath: string, options: Pick<VisOptions, 'customizeSnapshotSubpath'>): string;
63
77
  //# sourceMappingURL=vis_context.logic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.logic.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.logic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,U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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;;;;;;;;;;EAe9C;AA0BD,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,4 +1,5 @@
1
1
  import { join, relative } from 'pathe';
2
+ import { pick } from 'type-plus';
2
3
  import { DIFF_DIR, RESULT_DIR } from "../shared/constants.js";
3
4
  import { file } from "./file.js";
4
5
  import { getSnapshotSubpath, resolveSnapshotRootDir } from "./snapshot_path.js";
@@ -46,6 +47,7 @@ export function createVisContext() {
46
47
  const resultPath = join(resultDir, snapshotFilename);
47
48
  const diffPath = join(diffDir, snapshotFilename);
48
49
  return {
50
+ ...pick(visOptions, 'comparisonMethod', 'diffOptions', 'failureThreshold', 'failureThresholdType', 'timeout'),
49
51
  baselinePath,
50
52
  resultPath,
51
53
  diffPath,
@@ -83,7 +85,7 @@ export function createVisContext() {
83
85
  async function setupState(suite, visOptions) {
84
86
  const snapshotRootDir = resolveSnapshotRootDir(visOptions);
85
87
  const projectPath = suite.project.config.root;
86
- const platform = ctx.getSnapshotPlatform();
88
+ const platform = visOptions.platform ?? ctx.getSnapshotPlatform();
87
89
  const state = {
88
90
  projectPath,
89
91
  platform,
@@ -86,7 +86,7 @@ export function createVis(commands) {
86
86
  .map(([themeId, error]) => {
87
87
  return `Theme \`${themeId}\` failed: ${error.message}`;
88
88
  })
89
- .join('\n')}`);
89
+ .join('\n\n')}`);
90
90
  }
91
91
  };
92
92
  },
@@ -1,5 +1,5 @@
1
- import type { ImageSnapshotCompareOptions } from './types.ts';
2
- export declare function compareImage(img1: Uint8ClampedArray | Buffer, img2: Uint8ClampedArray | Buffer, output: Uint8ClampedArray | Buffer, width: number, height: number, { failureThreshold, failureThresholdType, diffOptions }?: ImageSnapshotCompareOptions): {
1
+ import type { ComparisonMethod, ImageSnapshotCompareOptions } from './types.ts';
2
+ export declare function compareImage<M extends ComparisonMethod>(img1: Uint8ClampedArray | Buffer, img2: Uint8ClampedArray | Buffer, output: Uint8ClampedArray | Buffer, width: number, height: number, options?: ImageSnapshotCompareOptions<M>): {
3
3
  pass: boolean;
4
4
  diffAmount: number;
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"compare_image.d.ts","sourceRoot":"","sources":["../../src/shared/compare_image.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,wBAAgB,YAAY,CAC3B,IAAI,EAAE,iBAAiB,GAAG,MAAM,EAChC,IAAI,EAAE,iBAAiB,GAAG,MAAM,EAChC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAClC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,EAAE,gBAAoB,EAAE,oBAA8B,EAAE,WAAW,EAAE,GAAE,2BAAgC;;;EASvG"}
1
+ {"version":3,"file":"compare_image.d.ts","sourceRoot":"","sources":["../../src/shared/compare_image.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE/E,wBAAgB,YAAY,CAAC,CAAC,SAAS,gBAAgB,EACtD,IAAI,EAAE,iBAAiB,GAAG,MAAM,EAChC,IAAI,EAAE,iBAAiB,GAAG,MAAM,EAChC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAClC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,2BAA2B,CAAC,CAAC,CAAa;;;EAenD"}
@@ -1,10 +1,42 @@
1
1
  import pixelmatch from 'pixelmatch';
2
+ import { ssim } from 'ssim.js';
2
3
  import { convertThresholdUnit } from "./convert_threshold_unit.js";
3
- export function compareImage(img1, img2, output, width, height, { failureThreshold = 0, failureThresholdType = 'pixel', diffOptions } = {}) {
4
- const pixelDiff = pixelmatch(img1, img2, output, width, height, diffOptions);
5
- const diffAmount = convertThresholdUnit({ failureThresholdType, width, height }, pixelDiff);
4
+ export function compareImage(img1, img2, output, width, height, options = {}) {
5
+ const pixelDiff = options.comparisonMethod === 'ssim'
6
+ ? compareWithSsim(img1, img2, output, width, height, options.diffOptions)
7
+ : pixelmatch(img1, img2, output, width, height, options.diffOptions);
8
+ const diffAmount = convertThresholdUnit({ failureThresholdType: options.failureThresholdType ?? 'pixel', width, height }, pixelDiff);
6
9
  return {
7
- pass: diffAmount <= failureThreshold,
10
+ pass: diffAmount <= (options.failureThreshold ?? 0),
8
11
  diffAmount,
9
12
  };
10
13
  }
14
+ /**
15
+ * @author This code is based on `jest-image-snapshot` implementation.
16
+ */
17
+ function compareWithSsim(img1, img2, output, width, height, diffOptions) {
18
+ const newImage = { data: img1, width: width, height: height };
19
+ const baselineImage = { data: img2, width: width, height: height };
20
+ const { ssim_map, mssim } = ssim(newImage, baselineImage, {
21
+ ssim: 'bezkrovny',
22
+ ...diffOptions,
23
+ });
24
+ // Converts the SSIM value to different pixels based on image width and height
25
+ // conforms to how pixelmatch works.
26
+ const diffPixels = Math.round((1 - mssim) * width * height);
27
+ const diffRgbaPixels = new DataView(output.buffer, output.byteOffset);
28
+ for (let ln = 0; ln !== height; ++ln) {
29
+ for (let pos = 0; pos !== width; ++pos) {
30
+ const rPos = ln * width + pos;
31
+ // initial value is transparent. We'll add in the SSIM offset.
32
+ // red (ff) green (00) blue (00) alpha (00)
33
+ const diffValue = 0xff000000 +
34
+ Math.floor(0xff *
35
+ (1 -
36
+ ssim_map.data[ssim_map.width * Math.round((ssim_map.height * ln) / height) +
37
+ Math.round((ssim_map.width * pos) / width)]));
38
+ diffRgbaPixels.setUint32(rPos * 4, diffValue);
39
+ }
40
+ }
41
+ return diffPixels;
42
+ }
@@ -1,9 +1,10 @@
1
1
  import type { PixelmatchOptions } from 'pixelmatch';
2
+ import type { Options as SsimOptions } from 'ssim.js';
2
3
  export interface ImageSnapshotTimeoutOptions {
3
4
  /**
4
5
  * Timeout for taking the snapshot.
5
6
  *
6
- * Default: 5000 ms locally, 30000 ms on CI.
7
+ * Default: 30000 ms (30 seconds)
7
8
  */
8
9
  timeout?: number | undefined;
9
10
  }
@@ -16,11 +17,8 @@ export interface ImageSnapshotIdOptions {
16
17
  */
17
18
  customizeSnapshotId?: (id: string, index: number) => string;
18
19
  }
19
- export interface ImageSnapshotCompareOptions {
20
- /**
21
- * Custom options passed to 'pixelmatch'
22
- */
23
- diffOptions?: PixelmatchOptions | undefined;
20
+ export type ComparisonMethod = 'pixel' | 'ssim';
21
+ export type FailureThresholdOptions = {
24
22
  /**
25
23
  * Failure threshold should measure in `pixel` or `percent`.
26
24
  *
@@ -33,5 +31,20 @@ export interface ImageSnapshotCompareOptions {
33
31
  * Default is `0`.
34
32
  */
35
33
  failureThreshold?: number | undefined;
36
- }
34
+ };
35
+ export type SsimComparisonOptions<M = 'ssim'> = {
36
+ comparisonMethod: M;
37
+ /**
38
+ * Custom options passed to 'ssim'
39
+ */
40
+ diffOptions?: Partial<SsimOptions> | undefined;
41
+ };
42
+ export type PixelComparisonOptions<M = 'pixel'> = {
43
+ comparisonMethod?: M | undefined;
44
+ /**
45
+ * Custom options passed to 'pixelmatch'
46
+ */
47
+ diffOptions?: PixelmatchOptions | undefined;
48
+ };
49
+ export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions;
37
50
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,MAAM,WAAW,2BAA2B;IAC3C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACtC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CAC3D;AAED,MAAM,WAAW,2BAA2B;IAC3C;;OAEG;IACH,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAA;IAC3C;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAA;IACtD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"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2
2
  "name": "vitest-plugin-vis",
3
- "version": "1.3.2",
3
+ "version": "1.5.0",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -54,6 +54,7 @@
54
54
  },
55
55
  "./package.json": "./package.json"
56
56
  },
57
+ "types": "./esm/index.d.ts",
57
58
  "files": [
58
59
  "esm",
59
60
  "src",
@@ -68,6 +69,7 @@
68
69
  "pixelmatch": "^6.0.0",
69
70
  "pngjs": "^7.0.0",
70
71
  "rimraf": "^6.0.1",
72
+ "ssim.js": "^3.5.0",
71
73
  "type-plus": "^8.0.0-beta.6"
72
74
  },
73
75
  "devDependencies": {