vitest-plugin-vis 1.4.0 → 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 (32) hide show
  1. package/esm/client/image_snapshot_matcher.d.ts.map +1 -1
  2. package/esm/client/image_snapshot_matcher.js +1 -0
  3. package/esm/client/image_snapshot_matcher.logic.d.ts.map +1 -1
  4. package/esm/client/image_snapshot_matcher.logic.js +3 -2
  5. package/esm/config/types.d.ts +10 -3
  6. package/esm/config/types.d.ts.map +1 -1
  7. package/esm/server/commands/match_image_snapshot.d.ts.map +1 -1
  8. package/esm/server/commands/match_image_snapshot.js +1 -2
  9. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +2 -1
  10. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
  11. package/esm/server/commands/prepare_image_snapshot_comparison.js +1 -2
  12. package/esm/server/vis_context.ctx.d.ts.map +1 -1
  13. package/esm/server/vis_context.ctx.js +0 -1
  14. package/esm/server/vis_context.d.ts +14 -0
  15. package/esm/server/vis_context.d.ts.map +1 -1
  16. package/esm/server/vis_context.logic.d.ts +14 -0
  17. package/esm/server/vis_context.logic.d.ts.map +1 -1
  18. package/esm/server/vis_context.logic.js +3 -1
  19. package/esm/setup/create_vis.js +1 -1
  20. package/esm/shared/types.d.ts +12 -20
  21. package/esm/shared/types.d.ts.map +1 -1
  22. package/package.json +2 -1
  23. package/readme.md +8 -5
  24. package/src/client/image_snapshot_matcher.logic.ts +3 -2
  25. package/src/client/image_snapshot_matcher.ts +3 -0
  26. package/src/config/types.ts +49 -35
  27. package/src/server/commands/match_image_snapshot.ts +1 -2
  28. package/src/server/commands/prepare_image_snapshot_comparison.ts +10 -3
  29. package/src/server/vis_context.ctx.ts +0 -1
  30. package/src/server/vis_context.logic.ts +7 -2
  31. package/src/setup/create_vis.ts +1 -1
  32. package/src/shared/types.ts +35 -40
@@ -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,mBA8D7G;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 +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,UAUpF"}
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
  }
@@ -1,11 +1,18 @@
1
- import type { ToMatchImageSnapshotOptions } from '../client/expect/to_match_image_snapshot.types.ts';
2
- import type { ComparisonMethod } from '../shared/types.ts';
1
+ import type { ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../shared/types.ts';
3
2
  export type { ComparisonMethod };
4
- export type VisOptions<M extends ComparisonMethod = 'pixel'> = ToMatchImageSnapshotOptions<M> & {
3
+ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & {
5
4
  /**
6
5
  * Loads the `test.setupFiles` of the specified preset.
7
6
  */
8
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;
9
16
  /**
10
17
  * The snapshot folder relative to the root of the project.
11
18
  *
@@ -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;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,CAAC,CAAC,CAAC,GAAG;IAC/F;;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,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,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 +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,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
+ {"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 +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
  };
@@ -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;;;;;;;sBAC0kD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;CADtjD,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"}
@@ -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>;
@@ -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,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;;;;;2BAiB1E,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;AAuBD,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
+ {"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;;;;;;;;;;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
  },
@@ -4,7 +4,7 @@ export interface ImageSnapshotTimeoutOptions {
4
4
  /**
5
5
  * Timeout for taking the snapshot.
6
6
  *
7
- * Default: 5000 ms locally, 30000 ms on CI.
7
+ * Default: 30000 ms (30 seconds)
8
8
  */
9
9
  timeout?: number | undefined;
10
10
  }
@@ -18,12 +18,7 @@ export interface ImageSnapshotIdOptions {
18
18
  customizeSnapshotId?: (id: string, index: number) => string;
19
19
  }
20
20
  export type ComparisonMethod = 'pixel' | 'ssim';
21
- export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = M extends 'ssim' ? {
22
- comparisonMethod: M;
23
- /**
24
- * Custom options passed to 'ssim'
25
- */
26
- diffOptions?: Partial<SsimOptions> | undefined;
21
+ export type FailureThresholdOptions = {
27
22
  /**
28
23
  * Failure threshold should measure in `pixel` or `percent`.
29
24
  *
@@ -36,23 +31,20 @@ export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> =
36
31
  * Default is `0`.
37
32
  */
38
33
  failureThreshold?: number | undefined;
39
- } : {
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'> = {
40
43
  comparisonMethod?: M | undefined;
41
44
  /**
42
45
  * Custom options passed to 'pixelmatch'
43
46
  */
44
47
  diffOptions?: PixelmatchOptions | undefined;
45
- /**
46
- * Failure threshold should measure in `pixel` or `percent`.
47
- *
48
- * Default is `pixel`.
49
- */
50
- failureThresholdType?: 'pixel' | 'percent' | undefined;
51
- /**
52
- * Failure tolerance threshold.
53
- *
54
- * Default is `0`.
55
- */
56
- failureThreshold?: number | undefined;
57
48
  };
49
+ export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions;
58
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;AACnD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;AAErD,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,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAA;AAE/C,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,CAAC,SAAS,MAAM,GAC7F;IACA,gBAAgB,EAAE,CAAC,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;IAC9C;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAA;IACtD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC,GACA;IACA,gBAAgB,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IAChC;;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,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;AAErD,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,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAA;AAE/C,MAAM,MAAM,uBAAuB,GAAG;IACrC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAA;IACtD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,MAAM,IAAI;IAC/C,gBAAgB,EAAE,CAAC,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;CAC9C,CAAA;AACD,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAAI;IACjD,gBAAgB,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAA;CAC3C,CAAA;AAED,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,CAAC,CAAC,SAAS,MAAM,GAC9F,qBAAqB,CAAC,CAAC,CAAC,GACxB,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAC5B,uBAAuB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "1.4.0",
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",
package/readme.md CHANGED
@@ -60,14 +60,16 @@ export default defineConfig({
60
60
  plugins: [
61
61
  vis({
62
62
  preset: 'auto',
63
- comparisonMethod: 'pixel',
64
63
  snapshotRootDir: '__vis__',
64
+ platform: '...', // {process.platform} or `local`
65
65
  customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
66
66
  customizeSnapshotId: (id, index) => `${id}-${index}`,
67
- diffOptions: undefined, // pixelmatch options
67
+ comparisonMethod: 'pixel',
68
+ // pixelmatch or ssim.js options, depending on `comparisonMethod`.
69
+ diffOptions: undefined,
68
70
  failureThresholdType: 'pixel',
69
71
  failureThreshold: 0,
70
- timeout: 5000 // 30000 on CI
72
+ timeout: 30000
71
73
  })
72
74
  ],
73
75
  test:{
@@ -189,7 +191,7 @@ setAutoSnapshotOptions({
189
191
  diffOptions: { threshold: 0.01 },
190
192
  failureThreshold: 0.01,
191
193
  failureThresholdType: 'percent',
192
- timeout: 15000
194
+ timeout: 60000
193
195
  })
194
196
  ```
195
197
 
@@ -242,7 +244,7 @@ it('manual snapshot with options', async () => {
242
244
  diffOptions: {
243
245
  threshold: 0.1
244
246
  },
245
- timeout: 15000
247
+ timeout: 60000
246
248
  })
247
249
  })
248
250
  ```
@@ -286,6 +288,7 @@ Please follow its guide to set up your environment.
286
288
 
287
289
  Bonus note, if you want to install [Firefox] on WSL,
288
290
  you can follow these steps: [Install Firefox on Ubuntu 22.04](https://askubuntu.com/a/1444967).
291
+ Also, you may need to `sudo apt-get install xdg-utils` to fix [`xdg-settings: not found`](https://serverfault.com/questions/1091926/running-chrome-on-ubuntu-server-how-to-solve-xdg-settings-not-found-using).
289
292
 
290
293
  ## Running on CI
291
294
 
@@ -5,9 +5,10 @@ export function prettifyOptions(options: ToMatchImageSnapshotOptions<any> | unde
5
5
 
6
6
  return [
7
7
  `failureThreshold: ${options.failureThreshold ?? 0} ${options.failureThresholdType ?? 'pixels'}`,
8
- options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
9
8
  options.timeout ? `timeout: ${options.timeout} ms` : '',
9
+ `comparisonMethod: ${options.comparisonMethod ?? 'pixel'}`,
10
+ options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
10
11
  ]
11
12
  .filter(Boolean)
12
- .join(', ')
13
+ .join('\n ')
13
14
  }
@@ -6,6 +6,7 @@ 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'
9
10
  import { alignImagesToSameSize } from './align_images.ts'
10
11
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts'
11
12
  import { toDataURL, toImageData } from './image_data.ts'
@@ -27,6 +28,8 @@ export function imageSnapshotMatcher(
27
28
 
28
29
  if (!info) return
29
30
 
31
+ options = { ...info, ...options } as any
32
+
30
33
  const baselineImage = await toImageData(info.baseline)
31
34
  const resultImage = await toImageData(info.result)
32
35
  const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage)
@@ -1,38 +1,52 @@
1
- import type { ToMatchImageSnapshotOptions } from '../client/expect/to_match_image_snapshot.types.ts'
2
- import type { ComparisonMethod } from '../shared/types.ts'
1
+ import type {
2
+ ComparisonMethod,
3
+ ImageSnapshotCompareOptions,
4
+ ImageSnapshotIdOptions,
5
+ ImageSnapshotTimeoutOptions,
6
+ } from '../shared/types.ts'
3
7
 
4
8
  export type { ComparisonMethod }
5
9
 
6
- export type VisOptions<M extends ComparisonMethod = 'pixel'> = ToMatchImageSnapshotOptions<M> & {
7
- /**
8
- * Loads the `test.setupFiles` of the specified preset.
9
- */
10
- preset?: 'manual' | 'auto' | 'none' | undefined
11
- /**
12
- * The snapshot folder relative to the root of the project.
13
- *
14
- * Default: `__vis__`
15
- */
16
- snapshotRootDir?: string | undefined
17
- /**
18
- * Customize the snapshot subpath.
19
- *
20
- * The snapshot subpath is used along with `snapshotRootDir` to determine the folder of the snapshots:
21
- *
22
- * - baseline: `<snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png`
23
- * - result: `<snapshotRootDir>/__results__/<snapshotSubpath>/<snapshotId>.png`
24
- * - diff: `<snapshotRootDir>/__diffs__/<snapshotSubpath>/<snapshotId>.png`
25
- *
26
- * Typically, you place your test files either in a dedicated `tests` folder or in the `src` folder along with your source code.
27
- * By default, the snapshot subpath is the test file path with that folder removed to reduces nesting of the snapshot folders.
28
- *
29
- * If you place your test files in multiple folders,
30
- * such as in both `tests` and `src` folders,
31
- * and they might have files with the same name and create conflicting snapshots,
32
- * you can set this to customize the snapshot subpath.
33
- *
34
- * @param subPath - The path of the test file to be used as the snapshot sub path.
35
- * If you want to keep the full path, you can simply return it.
36
- */
37
- customizeSnapshotSubpath?: (subPath: string) => string
38
- }
10
+ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions &
11
+ ImageSnapshotIdOptions &
12
+ ImageSnapshotCompareOptions<M> & {
13
+ /**
14
+ * Loads the `test.setupFiles` of the specified preset.
15
+ */
16
+ preset?: 'manual' | 'auto' | 'none' | undefined
17
+ /**
18
+ * The name of the subdirectory that the baseline snapshots get saved in.
19
+ *
20
+ * <snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png
21
+ *
22
+ * Default: undefined
23
+ */
24
+ platform?: string | undefined
25
+ /**
26
+ * The snapshot folder relative to the root of the project.
27
+ *
28
+ * Default: `__vis__`
29
+ */
30
+ snapshotRootDir?: string | undefined
31
+ /**
32
+ * Customize the snapshot subpath.
33
+ *
34
+ * The snapshot subpath is used along with `snapshotRootDir` to determine the folder of the snapshots:
35
+ *
36
+ * - baseline: `<snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png`
37
+ * - result: `<snapshotRootDir>/__results__/<snapshotSubpath>/<snapshotId>.png`
38
+ * - diff: `<snapshotRootDir>/__diffs__/<snapshotSubpath>/<snapshotId>.png`
39
+ *
40
+ * Typically, you place your test files either in a dedicated `tests` folder or in the `src` folder along with your source code.
41
+ * By default, the snapshot subpath is the test file path with that folder removed to reduces nesting of the snapshot folders.
42
+ *
43
+ * If you place your test files in multiple folders,
44
+ * such as in both `tests` and `src` folders,
45
+ * and they might have files with the same name and create conflicting snapshots,
46
+ * you can set this to customize the snapshot subpath.
47
+ *
48
+ * @param subPath - The path of the test file to be used as the snapshot sub path.
49
+ * If you want to keep the full path, you can simply return it.
50
+ */
51
+ customizeSnapshotSubpath?: (subPath: string) => string
52
+ }
@@ -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 type { BrowserCommand } from 'vitest/node'
@@ -41,7 +40,7 @@ export const matchImageSnapshot: BrowserCommand<
41
40
 
42
41
  // vitest:browser passes in `null` when not defined
43
42
  if (!options) options = {}
44
- options.timeout = options.timeout ?? (ci ? 30000 : 5000)
43
+ options.timeout = options.timeout ?? 30000
45
44
 
46
45
  const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
47
46
  const baselineBuffer = await file.tryReadFile(info.baselinePath)
@@ -1,6 +1,11 @@
1
- import ci from 'is-ci'
2
1
  import type { BrowserCommand } from 'vitest/node'
3
2
  import { isBase64String } from '../../shared/base64.ts'
3
+ import type {
4
+ FailureThresholdOptions,
5
+ ImageSnapshotTimeoutOptions,
6
+ PixelComparisonOptions,
7
+ SsimComparisonOptions,
8
+ } from '../../shared/types.ts'
4
9
  import { file } from '../file.ts'
5
10
  import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from '../snapshot.ts'
6
11
  import { visContext } from '../vis_context.ts'
@@ -14,7 +19,9 @@ type ImageSnapshotComparisonInfo = {
14
19
  diffPath: string
15
20
  baseline: string
16
21
  result: string
17
- }
22
+ } & ImageSnapshotTimeoutOptions &
23
+ FailureThresholdOptions &
24
+ (SsimComparisonOptions | PixelComparisonOptions)
18
25
 
19
26
  export interface PrepareImageSnapshotComparisonCommand {
20
27
  prepareImageSnapshotComparison: (
@@ -31,7 +38,7 @@ export const prepareImageSnapshotComparison: BrowserCommand<
31
38
 
32
39
  // vitest:browser passes in `null` when not defined
33
40
  if (!options) options = {}
34
- options.timeout = options.timeout ?? (ci ? 30000 : 5000)
41
+ options.timeout = options.timeout ?? 30000
35
42
 
36
43
  const info = visContext.getSnapshotInfo(context.testPath, taskId, options)
37
44
  const baselineBuffer = await file.tryReadFile(info.baselinePath)
@@ -5,7 +5,6 @@ import { rimraf } from 'rimraf'
5
5
  export const ctx = {
6
6
  rimraf,
7
7
  getSnapshotPlatform() {
8
- /* v8 ignore next */
9
8
  return ci ? process.platform : 'local'
10
9
  },
11
10
  }
@@ -1,4 +1,5 @@
1
1
  import { join, relative } from 'pathe'
2
+ import { pick } from 'type-plus'
2
3
  import type { VisOptions } from '../config/types.ts'
3
4
  import { DIFF_DIR, RESULT_DIR } from '../shared/constants.ts'
4
5
  import { file } from './file.ts'
@@ -67,6 +68,7 @@ export function createVisContext() {
67
68
  const diffPath = join(diffDir, snapshotFilename)
68
69
 
69
70
  return {
71
+ ...pick(visOptions, 'comparisonMethod', 'diffOptions', 'failureThreshold', 'failureThresholdType', 'timeout'),
70
72
  baselinePath,
71
73
  resultPath,
72
74
  diffPath,
@@ -102,10 +104,13 @@ export function createVisContext() {
102
104
  return context
103
105
  }
104
106
 
105
- async function setupState(suite: PartialBrowserCommandContext, visOptions: Pick<VisOptions, 'snapshotRootDir'>) {
107
+ async function setupState(
108
+ suite: PartialBrowserCommandContext,
109
+ visOptions: Pick<VisOptions, 'snapshotRootDir' | 'platform'>,
110
+ ) {
106
111
  const snapshotRootDir = resolveSnapshotRootDir(visOptions)
107
112
  const projectPath = suite.project.config.root
108
- const platform = ctx.getSnapshotPlatform()
113
+ const platform = visOptions.platform ?? ctx.getSnapshotPlatform()
109
114
 
110
115
  const state = {
111
116
  projectPath,
@@ -87,7 +87,7 @@ export function createVis(commands: SetupVisSuiteCommand) {
87
87
  .map(([themeId, error]) => {
88
88
  return `Theme \`${themeId}\` failed: ${error.message}`
89
89
  })
90
- .join('\n')}`,
90
+ .join('\n\n')}`,
91
91
  )
92
92
  }
93
93
  }
@@ -5,7 +5,7 @@ export interface ImageSnapshotTimeoutOptions {
5
5
  /**
6
6
  * Timeout for taking the snapshot.
7
7
  *
8
- * Default: 5000 ms locally, 30000 ms on CI.
8
+ * Default: 30000 ms (30 seconds)
9
9
  */
10
10
  timeout?: number | undefined
11
11
  }
@@ -22,42 +22,37 @@ export interface ImageSnapshotIdOptions {
22
22
 
23
23
  export type ComparisonMethod = 'pixel' | 'ssim'
24
24
 
25
- export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = M extends 'ssim'
26
- ? {
27
- comparisonMethod: M
28
- /**
29
- * Custom options passed to 'ssim'
30
- */
31
- diffOptions?: Partial<SsimOptions> | undefined
32
- /**
33
- * Failure threshold should measure in `pixel` or `percent`.
34
- *
35
- * Default is `pixel`.
36
- */
37
- failureThresholdType?: 'pixel' | 'percent' | undefined
38
- /**
39
- * Failure tolerance threshold.
40
- *
41
- * Default is `0`.
42
- */
43
- failureThreshold?: number | undefined
44
- }
45
- : {
46
- comparisonMethod?: M | undefined
47
- /**
48
- * Custom options passed to 'pixelmatch'
49
- */
50
- diffOptions?: PixelmatchOptions | undefined
51
- /**
52
- * Failure threshold should measure in `pixel` or `percent`.
53
- *
54
- * Default is `pixel`.
55
- */
56
- failureThresholdType?: 'pixel' | 'percent' | undefined
57
- /**
58
- * Failure tolerance threshold.
59
- *
60
- * Default is `0`.
61
- */
62
- failureThreshold?: number | undefined
63
- }
25
+ export type FailureThresholdOptions = {
26
+ /**
27
+ * Failure threshold should measure in `pixel` or `percent`.
28
+ *
29
+ * Default is `pixel`.
30
+ */
31
+ failureThresholdType?: 'pixel' | 'percent' | undefined
32
+ /**
33
+ * Failure tolerance threshold.
34
+ *
35
+ * Default is `0`.
36
+ */
37
+ failureThreshold?: number | undefined
38
+ }
39
+
40
+ export type SsimComparisonOptions<M = 'ssim'> = {
41
+ comparisonMethod: M
42
+ /**
43
+ * Custom options passed to 'ssim'
44
+ */
45
+ diffOptions?: Partial<SsimOptions> | undefined
46
+ }
47
+ export type PixelComparisonOptions<M = 'pixel'> = {
48
+ comparisonMethod?: M | undefined
49
+ /**
50
+ * Custom options passed to 'pixelmatch'
51
+ */
52
+ diffOptions?: PixelmatchOptions | undefined
53
+ }
54
+
55
+ export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim'
56
+ ? SsimComparisonOptions<M>
57
+ : PixelComparisonOptions<M>) &
58
+ FailureThresholdOptions