vitest-plugin-vis 1.1.0 → 1.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 (104) hide show
  1. package/esm/client/expect/augment.d.ts +8 -0
  2. package/esm/client/expect/augment.d.ts.map +1 -0
  3. package/esm/client/expect/augment.js +1 -0
  4. package/esm/client/expect/extend.d.ts +1 -7
  5. package/esm/client/expect/extend.d.ts.map +1 -1
  6. package/esm/client/expect/extend.js +1 -0
  7. package/esm/client/expect/to_match_image_snapshot.d.ts.map +1 -1
  8. package/esm/client/expect/to_match_image_snapshot.js +3 -2
  9. package/esm/client/expect/to_match_image_snapshot.types.d.ts +5 -0
  10. package/esm/client/expect/to_match_image_snapshot.types.d.ts.map +1 -1
  11. package/esm/client/match_image_snapshot.d.ts +4 -1
  12. package/esm/client/match_image_snapshot.d.ts.map +1 -1
  13. package/esm/client/match_image_snapshot.js +43 -30
  14. package/esm/client/match_image_snapshot.logic.js +1 -1
  15. package/esm/client/page/augment.d.ts +6 -0
  16. package/esm/client/page/augment.d.ts.map +1 -0
  17. package/esm/client/page/augment.js +1 -0
  18. package/esm/client/page/extend.d.ts +1 -5
  19. package/esm/client/page/extend.d.ts.map +1 -1
  20. package/esm/client/page/extend.js +1 -0
  21. package/esm/client/selector.d.ts +0 -2
  22. package/esm/client/selector.d.ts.map +1 -1
  23. package/esm/client/selector.js +5 -12
  24. package/esm/commands.d.ts +2 -0
  25. package/esm/commands.d.ts.map +1 -1
  26. package/esm/commands.js +2 -0
  27. package/esm/config/vis.d.ts +1 -1
  28. package/esm/index.d.ts +2 -0
  29. package/esm/index.d.ts.map +1 -1
  30. package/esm/index.js +2 -0
  31. package/esm/presets/auto.d.ts +2 -1
  32. package/esm/presets/auto.d.ts.map +1 -1
  33. package/esm/presets/auto.js +2 -1
  34. package/esm/presets/manual.d.ts +2 -1
  35. package/esm/presets/manual.d.ts.map +1 -1
  36. package/esm/presets/manual.js +2 -1
  37. package/esm/server/commands/_assertions.d.ts +5 -0
  38. package/esm/server/commands/_assertions.d.ts.map +1 -0
  39. package/esm/server/commands/_assertions.js +11 -0
  40. package/esm/server/commands/extend.d.ts +1 -1
  41. package/esm/server/commands/has_image_snapshot.d.ts.map +1 -1
  42. package/esm/server/commands/has_image_snapshot.js +2 -3
  43. package/esm/server/commands/image_snapshot_next_index.d.ts.map +1 -1
  44. package/esm/server/commands/image_snapshot_next_index.js +2 -3
  45. package/esm/server/commands/match_image_snapshot.d.ts.map +1 -1
  46. package/esm/server/commands/match_image_snapshot.js +6 -5
  47. package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
  48. package/esm/server/commands/prepare_image_snapshot_comparison.js +2 -3
  49. package/esm/server/commands/setup_vis_suite.d.ts.map +1 -1
  50. package/esm/server/commands/setup_vis_suite.js +2 -0
  51. package/esm/server/commands/write_image_snapshot.d.ts +8 -2
  52. package/esm/server/commands/write_image_snapshot.d.ts.map +1 -1
  53. package/esm/server/commands/write_image_snapshot.js +6 -7
  54. package/esm/server/vis_context.d.ts.map +1 -1
  55. package/esm/server/vis_context.logic.d.ts +2 -2
  56. package/esm/server/vis_context.logic.d.ts.map +1 -1
  57. package/esm/server/vis_context.logic.js +3 -3
  58. package/esm/shared/compare_image.d.ts +6 -0
  59. package/esm/shared/compare_image.d.ts.map +1 -0
  60. package/esm/shared/compare_image.js +10 -0
  61. package/esm/testing/stubBrowserCommandContext.d.ts +3 -0
  62. package/esm/testing/stubBrowserCommandContext.d.ts.map +1 -0
  63. package/esm/testing/stubBrowserCommandContext.js +2 -0
  64. package/esm/testing.d.ts +1 -0
  65. package/esm/testing.d.ts.map +1 -1
  66. package/esm/testing.js +1 -0
  67. package/package.json +2 -1
  68. package/readme.md +38 -2
  69. package/src/client/expect/augment.ts +8 -0
  70. package/src/client/expect/extend.ts +1 -8
  71. package/src/client/expect/to_match_image_snapshot.ts +3 -2
  72. package/src/client/expect/to_match_image_snapshot.types.ts +7 -1
  73. package/src/client/match_image_snapshot.logic.ts +1 -1
  74. package/src/client/match_image_snapshot.ts +68 -36
  75. package/src/client/page/augment.ts +5 -0
  76. package/src/client/page/extend.ts +2 -5
  77. package/src/client/selector.ts +0 -13
  78. package/src/commands.ts +2 -0
  79. package/src/index.ts +3 -0
  80. package/src/presets/auto.ts +2 -1
  81. package/src/presets/manual.ts +2 -1
  82. package/src/server/commands/_assertions.ts +18 -0
  83. package/src/server/commands/has_image_snapshot.ts +2 -3
  84. package/src/server/commands/image_snapshot_next_index.ts +2 -3
  85. package/src/server/commands/match_image_snapshot.ts +13 -6
  86. package/src/server/commands/prepare_image_snapshot_comparison.ts +2 -3
  87. package/src/server/commands/setup_vis_suite.ts +3 -0
  88. package/src/server/commands/write_image_snapshot.ts +17 -11
  89. package/src/server/vis_context.logic.ts +6 -6
  90. package/src/shared/compare_image.ts +20 -0
  91. package/src/testing/stubBrowserCommandContext.ts +4 -0
  92. package/src/testing.ts +1 -0
  93. package/esm/client/compare_image.d.ts +0 -7
  94. package/esm/client/compare_image.d.ts.map +0 -1
  95. package/esm/client/compare_image.js +0 -13
  96. package/esm/server/commands/is_ci.d.ts +0 -2
  97. package/esm/server/commands/is_ci.d.ts.map +0 -1
  98. package/esm/server/commands/is_ci.js +0 -6
  99. package/esm/server/compare_image.d.ts +0 -8
  100. package/esm/server/compare_image.d.ts.map +0 -1
  101. package/esm/server/compare_image.js +0 -16
  102. package/src/client/compare_image.ts +0 -21
  103. package/src/server/commands/is_ci.ts +0 -7
  104. package/src/server/compare_image.ts +0 -34
@@ -0,0 +1,8 @@
1
+ import type { ImageSnapshotMatcher } from './to_match_image_snapshot.types.ts';
2
+ declare global {
3
+ namespace jest {
4
+ interface Matchers<R, T> extends ImageSnapshotMatcher {
5
+ }
6
+ }
7
+ }
8
+ //# sourceMappingURL=augment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augment.d.ts","sourceRoot":"","sources":["../../../src/client/expect/augment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAE9E,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,IAAI,CAAC;QAEd,UAAU,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,oBAAoB;SAAG;KACxD;CACD"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,2 @@
1
- import type { ImageSnapshotMatcher } from './to_match_image_snapshot.types.ts';
2
- declare global {
3
- namespace jest {
4
- interface Matchers<R, T> extends ImageSnapshotMatcher {
5
- }
6
- }
7
- }
1
+ import './augment.ts';
8
2
  //# sourceMappingURL=extend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../src/client/expect/extend.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAE9E,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,IAAI,CAAC;QAEd,UAAU,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,oBAAoB;SAAG;KACxD;CACD"}
1
+ {"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../src/client/expect/extend.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,CAAA"}
@@ -1,3 +1,4 @@
1
1
  import { expect } from 'vitest';
2
2
  import { toMatchImageSnapshot } from "./to_match_image_snapshot.js";
3
+ import "./augment.js";
3
4
  expect.extend({ toMatchImageSnapshot });
@@ -1 +1 @@
1
- {"version":3,"file":"to_match_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/client/expect/to_match_image_snapshot.ts"],"names":[],"mappings":"AAAA,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;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,5 +1,6 @@
1
+ import { commands } from '@vitest/browser/context';
1
2
  import { ctx } from "../ctx.js";
2
- import { matchImageSnapshot } from "../match_image_snapshot.js";
3
+ import { imageSnapshotMatcher } from "../match_image_snapshot.js";
3
4
  import { success } from "./expectation_result.js";
4
5
  export function toMatchImageSnapshot(
5
6
  /**
@@ -15,5 +16,5 @@ subject, options) {
15
16
  throw new Error('`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +
16
17
  "concurrent tests run at the same time in the same iframe and affect each other's environment. ");
17
18
  }
18
- return matchImageSnapshot(test, subject, options).then(() => success);
19
+ return imageSnapshotMatcher(commands)(test, subject, options).then(() => success);
19
20
  }
@@ -3,5 +3,10 @@ export interface ImageSnapshotMatcher {
3
3
  toMatchImageSnapshot(options?: ToMatchImageSnapshotOptions | undefined): Promise<void>;
4
4
  }
5
5
  export interface ToMatchImageSnapshotOptions extends ImageSnapshotTimeoutOptions, ImageSnapshotIdOptions, ImageSnapshotCompareOptions {
6
+ /**
7
+ * Expect the matcher to fail.
8
+ * If it passes, it will throw an error with details.
9
+ */
10
+ expectToFail?: boolean | undefined;
6
11
  }
7
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;CAAG"}
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,6 +1,9 @@
1
1
  import type { Task } from 'vitest';
2
+ import type { ImageSnapshotNextIndexCommand } from '../commands.ts';
3
+ import type { PrepareImageSnapshotComparisonCommand } from '../server/commands/prepare_image_snapshot_comparison.ts';
4
+ import type { WriteImageSnapshotCommand } from '../server/commands/write_image_snapshot.ts';
2
5
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
3
- export declare function matchImageSnapshot(test: Task, subject: any, options?: ToMatchImageSnapshotOptions): Promise<void>;
6
+ export declare function imageSnapshotMatcher(commands: PrepareImageSnapshotComparisonCommand & WriteImageSnapshotCommand & ImageSnapshotNextIndexCommand): (test: Task, subject: any, options?: ToMatchImageSnapshotOptions) => Promise<void>;
4
7
  /**
5
8
  * @deprecated internalized. Use `matchImageSnapshot` directly instead.
6
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../src/client/match_image_snapshot.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAIlC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAO5F,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,2BAA2B,iBAuCvG;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,GAAG,OAOrD"}
1
+ {"version":3,"file":"match_image_snapshot.d.ts","sourceRoot":"","sources":["../../src/client/match_image_snapshot.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,43 +1,56 @@
1
- import { commands } from '@vitest/browser/context';
2
1
  import dedent from 'dedent';
3
2
  import { resolve } from 'pathe';
4
3
  import { isBase64String } from "../shared/base64.js";
4
+ import { compareImage } from "../shared/compare_image.js";
5
5
  import { alignImagesToSameSize } from "./align_images.js";
6
- import { compareImage } from "./compare_image.js";
7
6
  import { toDataURL, toImageData } from "./image_data.js";
8
7
  import { prettifyOptions } from "./match_image_snapshot.logic.js";
9
8
  import { convertElementToCssSelector } from "./selector.js";
10
9
  import { toTaskId } from "./task_id.js";
11
10
  import { server } from "./vitest_browser_context_proxy.js";
12
- export async function matchImageSnapshot(test, subject, options) {
13
- const taskId = toTaskId(test);
14
- const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options?.customizeSnapshotId ? await parseImageSnapshotOptions(taskId, options) : options);
15
- if (!info)
16
- return;
17
- const baselineImage = await toImageData(info.baseline);
18
- const resultImage = await toImageData(info.result);
19
- const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage);
20
- const { pass, diffAmount, diffImage } = compareImage(baselineAlignedImage, resultAlignedImage, options);
21
- if (pass)
22
- return;
23
- if (server.config.snapshotOptions.updateSnapshot === 'all') {
24
- await writeSnapshot(info.baselinePath, resultImage);
25
- return;
26
- }
27
- await writeSnapshot(info.diffPath, diffImage);
28
- throw new Error(dedent `Snapshot \`${taskId}\` mismatched
11
+ export function imageSnapshotMatcher(commands) {
12
+ return async function matchImageSnapshot(test, subject, options) {
13
+ const taskId = toTaskId(test);
14
+ const info = await commands.prepareImageSnapshotComparison(taskId, parseImageSnapshotSubject(subject), options?.customizeSnapshotId ? await parseImageSnapshotOptions(commands, taskId, options) : options);
15
+ if (!info)
16
+ return;
17
+ const baselineImage = await toImageData(info.baseline);
18
+ const resultImage = await toImageData(info.result);
19
+ const [baselineAlignedImage, resultAlignedImage] = alignImagesToSameSize(baselineImage, resultImage);
20
+ const { width, height } = baselineAlignedImage;
21
+ const diffImage = new ImageData(width, height);
22
+ const { pass, diffAmount } = compareImage(baselineAlignedImage.data, resultAlignedImage.data, diffImage.data, width, height, options);
23
+ if (pass) {
24
+ if (options?.expectToFail) {
25
+ throw new Error(dedent `Snapshot \`${taskId}\` matched but expected to fail.
29
26
 
30
- ${options?.failureThreshold
31
- ? options?.failureThresholdType === 'percent'
32
- ? `Expected image to match within ${options.failureThreshold}% but was differ by ${diffAmount}%.`
33
- : `Expected image to match within ${options.failureThreshold} pixels but was differ by ${diffAmount} pixels.`
34
- : `Expected image to match but was differ by ${options?.failureThresholdType === 'percent' ? `${diffAmount}%` : `${diffAmount} pixels`}.`}
27
+ Options: ${prettifyOptions(options)}
28
+ DiffAmount: ${options.failureThresholdType === 'percent' ? `${diffAmount}%` : `${diffAmount} pixels`}
35
29
 
36
- Options: ${prettifyOptions(options)}
30
+ Expected: ${resolve(info.projectRoot, info.baselinePath)}
31
+ Actual: ${resolve(info.projectRoot, info.resultPath)}`);
32
+ }
33
+ return;
34
+ }
35
+ if (server.config.snapshotOptions.updateSnapshot === 'all') {
36
+ await writeSnapshot(commands, info.baselinePath, resultImage);
37
+ return;
38
+ }
39
+ await writeSnapshot(commands, info.diffPath, diffImage);
40
+ throw new Error(dedent `Snapshot \`${taskId}\` mismatched
37
41
 
38
- Expected: ${resolve(info.projectRoot, info.baselinePath)}
39
- Actual: ${resolve(info.projectRoot, info.resultPath)}
40
- Difference: ${resolve(info.projectRoot, info.diffPath)}`);
42
+ ${options?.failureThreshold
43
+ ? options?.failureThresholdType === 'percent'
44
+ ? `Expected image to match within ${options.failureThreshold}% but was differ by ${diffAmount}%.`
45
+ : `Expected image to match within ${options.failureThreshold} pixels but was differ by ${diffAmount} pixels.`
46
+ : `Expected image to match but was differ by ${options?.failureThresholdType === 'percent' ? `${diffAmount}%` : `${diffAmount} pixels`}.`}
47
+
48
+ Options: ${prettifyOptions(options)}
49
+
50
+ Expected: ${resolve(info.projectRoot, info.baselinePath)}
51
+ Actual: ${resolve(info.projectRoot, info.resultPath)}
52
+ Difference: ${resolve(info.projectRoot, info.diffPath)}`);
53
+ };
41
54
  }
42
55
  /**
43
56
  * @deprecated internalized. Use `matchImageSnapshot` directly instead.
@@ -51,11 +64,11 @@ export function parseImageSnapshotSubject(subject) {
51
64
  return subject;
52
65
  throw new Error(`'toMatchImageSnapshot()' expects the subject to be an element, locator, or image encoded in base64 string, but got: ${subject}`);
53
66
  }
54
- async function writeSnapshot(path, image) {
67
+ async function writeSnapshot(commands, path, image) {
55
68
  const content = (await toDataURL(image)).split(',')[1];
56
69
  return commands.writeImageSnapshot(path, content);
57
70
  }
58
- async function parseImageSnapshotOptions(taskId, options) {
71
+ async function parseImageSnapshotOptions(commands, taskId, options) {
59
72
  const index = await commands.imageSnapshotNextIndex(taskId);
60
73
  const { customizeSnapshotId, ...rest } = options;
61
74
  const snapshotFileId = customizeSnapshotId(taskId, index);
@@ -2,7 +2,7 @@ export function prettifyOptions(options) {
2
2
  if (!options)
3
3
  return 'none';
4
4
  return [
5
- `failureThreshold: ${options.failureThreshold ?? 0} ${options.failureThresholdType ?? 'pixel'}`,
5
+ `failureThreshold: ${options.failureThreshold ?? 0} ${options.failureThresholdType ?? 'pixels'}`,
6
6
  options.diffOptions ? `diffOptions: ${JSON.stringify(options.diffOptions)}` : '',
7
7
  options.timeout ? `timeout: ${options.timeout} ms` : '',
8
8
  ]
@@ -0,0 +1,6 @@
1
+ import type { HasImageSnapshotAction } from './has_image_snapshot.ts';
2
+ declare module '@vitest/browser/context' {
3
+ interface BrowserPage extends HasImageSnapshotAction {
4
+ }
5
+ }
6
+ //# sourceMappingURL=augment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augment.d.ts","sourceRoot":"","sources":["../../../src/client/page/augment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAErE,OAAO,QAAQ,yBAAyB,CAAC;IACxC,UAAU,WAAY,SAAQ,sBAAsB;KAAG;CACvD"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,2 @@
1
- import { type HasImageSnapshotAction } from './has_image_snapshot.ts';
2
- declare module '@vitest/browser/context' {
3
- interface BrowserPage extends HasImageSnapshotAction {
4
- }
5
- }
1
+ import './augment.ts';
6
2
  //# sourceMappingURL=extend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../src/client/page/extend.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,sBAAsB,EAAoB,MAAM,yBAAyB,CAAA;AAEvF,OAAO,QAAQ,yBAAyB,CAAC;IACxC,UAAU,WAAY,SAAQ,sBAAsB;KAAG;CACvD"}
1
+ {"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../../src/client/page/extend.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,CAAA"}
@@ -1,3 +1,4 @@
1
1
  import { page } from '@vitest/browser/context';
2
+ import "./augment.js";
2
3
  import { hasImageSnapshot } from "./has_image_snapshot.js";
3
4
  page.extend({ hasImageSnapshot });
@@ -3,7 +3,5 @@
3
3
  *
4
4
  * @see https://github.com/vitest-dev/vitest/blob/main/packages/browser/src/client/utils.ts
5
5
  */
6
- import type { Locator } from '@vitest/browser/context';
7
- export declare function convertToSelector(elementOrLocator: Element | Locator): string;
8
6
  export declare function convertElementToCssSelector(element: Element): string;
9
7
  //# sourceMappingURL=selector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../src/client/selector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AAEtD,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAW7E;AACD,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,UAM3D"}
1
+ {"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../src/client/selector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,UAM3D"}
@@ -1,15 +1,8 @@
1
- export function convertToSelector(elementOrLocator) {
2
- if (!elementOrLocator) {
3
- throw new Error('Expected element or locator to be defined.');
4
- }
5
- if (elementOrLocator instanceof Element) {
6
- return convertElementToCssSelector(elementOrLocator);
7
- }
8
- if ('selector' in elementOrLocator) {
9
- return elementOrLocator.selector;
10
- }
11
- throw new Error('Expected element or locator to be an instance of Element or Locator.');
12
- }
1
+ /**
2
+ * Most of the code in this file is copied from Vitest.
3
+ *
4
+ * @see https://github.com/vitest-dev/vitest/blob/main/packages/browser/src/client/utils.ts
5
+ */
13
6
  export function convertElementToCssSelector(element) {
14
7
  if (!element || !(element instanceof Element)) {
15
8
  throw new Error(`Expected DOM element to be an instance of Element, received ${typeof element}`);
package/esm/commands.d.ts CHANGED
@@ -2,4 +2,6 @@ export * from './server/commands/has_image_snapshot.ts';
2
2
  export * from './server/commands/image_snapshot_next_index.ts';
3
3
  export * from './server/commands/match_image_snapshot.ts';
4
4
  export * from './server/commands/setup_vis_suite.ts';
5
+ export * from './server/commands/prepare_image_snapshot_comparison.ts';
6
+ export * from './server/commands/write_image_snapshot.ts';
5
7
  //# sourceMappingURL=commands.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,2CAA2C,CAAA;AACzD,cAAc,sCAAsC,CAAA"}
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,2CAA2C,CAAA;AACzD,cAAc,sCAAsC,CAAA;AACpD,cAAc,wDAAwD,CAAA;AACtE,cAAc,2CAA2C,CAAA"}
package/esm/commands.js CHANGED
@@ -2,3 +2,5 @@ export * from "./server/commands/has_image_snapshot.js";
2
2
  export * from "./server/commands/image_snapshot_next_index.js";
3
3
  export * from "./server/commands/match_image_snapshot.js";
4
4
  export * from "./server/commands/setup_vis_suite.js";
5
+ export * from "./server/commands/prepare_image_snapshot_comparison.js";
6
+ export * from "./server/commands/write_image_snapshot.js";
@@ -17,7 +17,7 @@ export declare function vis(options?: VisOptions): {
17
17
  hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId?: string | undefined]>;
18
18
  matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
19
19
  prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, options?: import("../commands.ts").MatchImageSnapshotOptions | undefined]>;
20
- writeImageSnapshot: import("vitest/node").BrowserCommand<[filePath: string, base64: string]>;
20
+ writeImageSnapshot: import("vitest/node").BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
21
21
  };
22
22
  };
23
23
  setupFiles: string[] | undefined;
package/esm/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ import './client/expect/augment.ts';
2
+ import './client/page/augment.ts';
1
3
  export * from './client/snapshot_options.ts';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,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,cAAc,8BAA8B,CAAA"}
package/esm/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  // `vitest-plugin-vis` provides code that can be used in test files.
2
+ import "./client/expect/augment.js";
3
+ import "./client/page/augment.js";
2
4
  export * from "./client/snapshot_options.js";
@@ -1,2 +1,3 @@
1
- import 'vitest-browser-react';
1
+ import '../client/expect/extend.ts';
2
+ import '../client/page/extend.ts';
2
3
  //# sourceMappingURL=auto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auto.d.ts","sourceRoot":"","sources":["../../src/presets/auto.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAA"}
1
+ {"version":3,"file":"auto.d.ts","sourceRoot":"","sources":["../../src/presets/auto.ts"],"names":[],"mappings":"AACA,OAAO,4BAA4B,CAAA;AACnC,OAAO,0BAA0B,CAAA"}
@@ -1,3 +1,4 @@
1
- import 'vitest-browser-react';
2
1
  import { vis } from "../setup/vis.js";
2
+ import "../client/expect/extend.js";
3
+ import "../client/page/extend.js";
3
4
  vis.presets.auto();
@@ -1,2 +1,3 @@
1
- import 'vitest-browser-react';
1
+ import '../client/expect/extend.ts';
2
+ import '../client/page/extend.ts';
2
3
  //# sourceMappingURL=manual.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"manual.d.ts","sourceRoot":"","sources":["../../src/presets/manual.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAA"}
1
+ {"version":3,"file":"manual.d.ts","sourceRoot":"","sources":["../../src/presets/manual.ts"],"names":[],"mappings":"AACA,OAAO,4BAA4B,CAAA;AACnC,OAAO,0BAA0B,CAAA"}
@@ -1,3 +1,4 @@
1
- import 'vitest-browser-react';
2
1
  import { vis } from "../setup/vis.js";
2
+ import "../client/expect/extend.js";
3
+ import "../client/page/extend.js";
3
4
  vis.presets.manual();
@@ -0,0 +1,5 @@
1
+ import type { RequiredPick } from 'type-plus';
2
+ import type { BrowserCommandContext } from 'vitest/node';
3
+ export declare function assertTestPathDefined(context: BrowserCommandContext, commandName: string): asserts context is RequiredPick<BrowserCommandContext, 'testPath'>;
4
+ export declare function assertIsRelativePath(relativeFilePath: string, propName: string): void;
5
+ //# sourceMappingURL=_assertions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_assertions.d.ts","sourceRoot":"","sources":["../../../src/server/commands/_assertions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,qBAAqB,EAC9B,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAIpE;AAED,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAI9E"}
@@ -0,0 +1,11 @@
1
+ import { isAbsolute } from 'pathe';
2
+ export function assertTestPathDefined(context, commandName) {
3
+ if (!context.testPath) {
4
+ throw new Error(`'commands.${commandName}' requires testPath to be defined`);
5
+ }
6
+ }
7
+ export function assertIsRelativePath(relativeFilePath, propName) {
8
+ if (isAbsolute(relativeFilePath)) {
9
+ throw new Error(`'${propName}' must be a relative path`);
10
+ }
11
+ }
@@ -14,6 +14,6 @@ export declare const commands: {
14
14
  hasImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, snapshotId?: string | undefined]>;
15
15
  matchImageSnapshot: import("vitest/node").BrowserCommand<[taskId: string, subject: string, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
16
16
  prepareImageSnapshotComparison: import("vitest/node").BrowserCommand<[taskId: string, snapshotId: string, options?: import("./match_image_snapshot.ts").MatchImageSnapshotOptions | undefined]>;
17
- writeImageSnapshot: import("vitest/node").BrowserCommand<[filePath: string, base64: string]>;
17
+ writeImageSnapshot: import("vitest/node").BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
18
18
  };
19
19
  //# sourceMappingURL=extend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGjD,MAAM,WAAW,uBAAuB;IACvC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACnF;AAED,eAAO,MAAM,gBAAgB,EAAE,cAAc,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAU9F,CAAA"}
1
+ {"version":3,"file":"has_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/has_image_snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,uBAAuB;IACvC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACnF;AAED,eAAO,MAAM,gBAAgB,EAAE,cAAc,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAQ9F,CAAA"}
@@ -1,7 +1,6 @@
1
1
  import { visContext } from "../vis_context.js";
2
+ import { assertTestPathDefined } from "./_assertions.js";
2
3
  export const hasImageSnapshot = async (context, taskId, snapshotId) => {
3
- if (!context.testPath) {
4
- throw new Error('Cannot take snapshot without testPath');
5
- }
4
+ assertTestPathDefined(context, 'hasImageSnapshot');
6
5
  return visContext.hasImageSnapshot(context.testPath, taskId, snapshotId);
7
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"image_snapshot_next_index.d.ts","sourceRoot":"","sources":["../../../src/server/commands/image_snapshot_next_index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGjD,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACvD;AAED,eAAO,MAAM,sBAAsB,EAAE,cAAc,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAMnE,CAAA"}
1
+ {"version":3,"file":"image_snapshot_next_index.d.ts","sourceRoot":"","sources":["../../../src/server/commands/image_snapshot_next_index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACvD;AAED,eAAO,MAAM,sBAAsB,EAAE,cAAc,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAInE,CAAA"}
@@ -1,7 +1,6 @@
1
1
  import { visContext } from "../vis_context.js";
2
+ import { assertTestPathDefined } from "./_assertions.js";
2
3
  export const imageSnapshotNextIndex = async (context, taskId) => {
3
- if (!context.testPath) {
4
- throw new Error('Cannot take snapshot without testPath');
5
- }
4
+ assertTestPathDefined(context, 'imageSnapshotNextIndex');
6
5
  return visContext.getTaskCount(context.testPath, taskId);
7
6
  };
@@ -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;AAIjD,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,CAiElF,CAAA"}
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"}
@@ -3,16 +3,15 @@ import ci from 'is-ci';
3
3
  import { resolve } from 'pathe';
4
4
  import { PNG } from 'pngjs';
5
5
  import { isBase64String } from "../../shared/base64.js";
6
+ import { compareImage } from "../../shared/compare_image.js";
6
7
  import { getMaxSize } from "../../shared/get_max_size.js";
7
8
  import { isSameSize } from "../../shared/is_same_size.js";
8
- import { compareImage } from "../compare_image.js";
9
9
  import { file } from "../file.js";
10
10
  import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot, writeSnapshotBuffer } from "../snapshot.js";
11
11
  import { visContext } from "../vis_context.js";
12
+ import { assertTestPathDefined } from "./_assertions.js";
12
13
  export const matchImageSnapshot = async (context, taskId, subject, options) => {
13
- if (!context.testPath) {
14
- throw new Error('Cannot match snapshot without testPath');
15
- }
14
+ assertTestPathDefined(context, 'matchImageSnapshot');
16
15
  // vitest:browser passes in `null` when not defined
17
16
  if (!options)
18
17
  options = {};
@@ -32,7 +31,9 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
32
31
  const baselineImage = PNG.sync.read(baselineBuffer, { skipRescale: true, checkCRC: false });
33
32
  const resultImage = PNG.sync.read(resultBuffer, { skipRescale: true, checkCRC: false });
34
33
  const [baselineAlignedImage, resultAlignedImage] = alignImageSizes(baselineImage, resultImage);
35
- const { pass, diffAmount, diffImage } = compareImage(baselineAlignedImage, resultAlignedImage, options);
34
+ const { width, height } = baselineAlignedImage;
35
+ const diffImage = new PNG({ width, height });
36
+ const { pass, diffAmount } = compareImage(baselineAlignedImage.data, resultAlignedImage.data, diffImage.data, width, height, options);
36
37
  if (pass) {
37
38
  if (sizeNotChanged(baselineImage, baselineAlignedImage) && sizeNotChanged(resultImage, resultAlignedImage)) {
38
39
  return;
@@ -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;AAKjD,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,CA4BrF,CAAA"}
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"}
@@ -3,10 +3,9 @@ import { isBase64String } from "../../shared/base64.js";
3
3
  import { file } from "../file.js";
4
4
  import { takeSnapshot, takeSnapshotByBrowser, writeSnapshot } from "../snapshot.js";
5
5
  import { visContext } from "../vis_context.js";
6
+ import { assertTestPathDefined } from "./_assertions.js";
6
7
  export const prepareImageSnapshotComparison = async (context, taskId, subject, options) => {
7
- if (!context.testPath) {
8
- throw new Error('Cannot match snapshot without testPath');
9
- }
8
+ assertTestPathDefined(context, 'prepareImageSnapshotComparison');
10
9
  // vitest:browser passes in `null` when not defined
11
10
  if (!options)
12
11
  options = {};
@@ -1 +1 @@
1
- {"version":3,"file":"setup_vis_suite.d.ts","sourceRoot":"","sources":["../../../src/server/commands/setup_vis_suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGjD,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AAED,eAAO,MAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAE5C,CAAA"}
1
+ {"version":3,"file":"setup_vis_suite.d.ts","sourceRoot":"","sources":["../../../src/server/commands/setup_vis_suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,oBAAoB;IACpC;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AAED,eAAO,MAAM,aAAa,EAAE,cAAc,CAAC,EAAE,CAI5C,CAAA"}
@@ -1,4 +1,6 @@
1
1
  import { visContext } from "../vis_context.js";
2
+ import { assertTestPathDefined } from "./_assertions.js";
2
3
  export const setupVisSuite = async (context) => {
4
+ assertTestPathDefined(context, 'setupVisSuite');
3
5
  await visContext.setupSuite(context);
4
6
  };
@@ -1,6 +1,12 @@
1
1
  import type { BrowserCommand } from 'vitest/node';
2
2
  export interface WriteImageSnapshotCommand {
3
- writeImageSnapshot(taskId: string, snapshotId?: string | undefined): Promise<boolean>;
3
+ /**
4
+ * Writes the image snapshot to the file system.
5
+ * @param relativeFilePath The file path to write the image snapshot to.
6
+ * It is relative to the project root.
7
+ * @param imageBase64 The base64 encoded image.
8
+ */
9
+ writeImageSnapshot(relativeFilePath: string, imageBase64: string): Promise<void>;
4
10
  }
5
- export declare const writeImageSnapshot: BrowserCommand<[filePath: string, base64: string]>;
11
+ export declare const writeImageSnapshot: BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
6
12
  //# sourceMappingURL=write_image_snapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"write_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/write_image_snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGjD,MAAM,WAAW,yBAAyB;IACzC,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACrF;AAED,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAUjF,CAAA"}
1
+ {"version":3,"file":"write_image_snapshot.d.ts","sourceRoot":"","sources":["../../../src/server/commands/write_image_snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,MAAM,WAAW,yBAAyB;IACzC;;;;;OAKG;IACH,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChF;AAED,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAS9F,CAAA"}
@@ -1,10 +1,9 @@
1
1
  import { mkdirp } from 'mkdirp';
2
- import { dirname } from 'pathe';
2
+ import { dirname, isAbsolute } from 'pathe';
3
3
  import { file } from "../file.js";
4
- export const writeImageSnapshot = async (context, filePath, base64) => {
5
- if (!context.testPath) {
6
- throw new Error('Cannot take snapshot without testPath');
7
- }
8
- await mkdirp(dirname(filePath));
9
- await file.writeFile(filePath, base64, { encoding: 'base64' });
4
+ import { assertIsRelativePath } from "./_assertions.js";
5
+ export const writeImageSnapshot = async (_, relativeFilePath, imageBase64) => {
6
+ assertIsRelativePath(relativeFilePath, 'relativeFilePath');
7
+ await mkdirp(dirname(relativeFilePath));
8
+ await file.writeFile(relativeFilePath, imageBase64, { encoding: 'base64' });
10
9
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBAC4iD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;CADxhD,CAAA"}
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"}
@@ -11,7 +11,7 @@ export type PartialBrowserCommandContext = {
11
11
  hookTimeout: number;
12
12
  };
13
13
  };
14
- testPath: string | undefined;
14
+ testPath: string;
15
15
  };
16
16
  export declare function createVisContext(): {
17
17
  setOptions(options?: VisOptions): void;
@@ -50,7 +50,6 @@ export declare function createVisContext(): {
50
50
  };
51
51
  };
52
52
  };
53
- export declare function getSuiteId(state: VisState, testPath: string, options: VisOptions): string;
54
53
  export declare function createSuite(state: VisState, testPath: string, options: VisOptions): {
55
54
  suiteId: string;
56
55
  suite: {
@@ -60,4 +59,5 @@ export declare function createSuite(state: VisState, testPath: string, options:
60
59
  tasks: {};
61
60
  };
62
61
  };
62
+ export declare function getSuiteId(state: VisState, testPath: string, options: VisOptions): string;
63
63
  //# 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,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,GAAG,SAAS,CAAA;CAC5B,CAAA;AAED,wBAAgB,gBAAgB;yBAMV,UAAU;;;;IAY9B;;;;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,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,UAEhF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;;;;;;;;EAWjF"}
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;yBAMV,UAAU;;;;IAY9B;;;;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,UAAU;;;;;;;;EAWjF;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,UAEhF"}