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,20 @@
1
+ import pixelmatch from 'pixelmatch'
2
+ import { convertThresholdUnit } from './convert_threshold_unit.ts'
3
+ import type { ImageSnapshotCompareOptions } from './types.ts'
4
+
5
+ export function compareImage(
6
+ img1: Uint8ClampedArray | Buffer,
7
+ img2: Uint8ClampedArray | Buffer,
8
+ output: Uint8ClampedArray | Buffer,
9
+ width: number,
10
+ height: number,
11
+ { failureThreshold = 0, failureThresholdType = 'pixel', diffOptions }: ImageSnapshotCompareOptions = {},
12
+ ) {
13
+ const pixelDiff = pixelmatch(img1, img2, output, width, height, diffOptions)
14
+ const diffAmount = convertThresholdUnit({ failureThresholdType, width, height }, pixelDiff)
15
+
16
+ return {
17
+ pass: diffAmount <= failureThreshold,
18
+ diffAmount,
19
+ }
20
+ }
@@ -0,0 +1,4 @@
1
+ import { stub } from 'type-plus'
2
+ import type { BrowserCommandContext } from 'vitest/node'
3
+
4
+ export const stubBrowserCommandContext = stub.build<BrowserCommandContext>({})
package/src/testing.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './testing/constants.ts'
2
+ export * from './testing/stubBrowserCommandContext.ts'
@@ -1,7 +0,0 @@
1
- import type { ImageSnapshotCompareOptions } from '../shared/types.ts';
2
- export declare function compareImage(baselineImage: ImageData, resultImage: ImageData, { failureThreshold, failureThresholdType, diffOptions }?: ImageSnapshotCompareOptions): {
3
- pass: boolean;
4
- diffAmount: number;
5
- diffImage: ImageData;
6
- };
7
- //# sourceMappingURL=compare_image.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare_image.d.ts","sourceRoot":"","sources":["../../src/client/compare_image.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAErE,wBAAgB,YAAY,CAC3B,aAAa,EAAE,SAAS,EACxB,WAAW,EAAE,SAAS,EACtB,EAAE,gBAAoB,EAAE,oBAA8B,EAAE,WAAW,EAAE,GAAE,2BAAgC;;;;EAavG"}
@@ -1,13 +0,0 @@
1
- import pixelmatch from 'pixelmatch';
2
- import { convertThresholdUnit } from "../shared/convert_threshold_unit.js";
3
- export function compareImage(baselineImage, resultImage, { failureThreshold = 0, failureThresholdType = 'pixel', diffOptions } = {}) {
4
- const { width, height } = resultImage;
5
- const diffImage = new ImageData(width, height);
6
- const pixelDiff = pixelmatch(resultImage.data, baselineImage.data, diffImage.data, width, height, diffOptions);
7
- const diffAmount = convertThresholdUnit({ failureThresholdType, width, height }, pixelDiff);
8
- return {
9
- pass: diffAmount <= failureThreshold,
10
- diffAmount,
11
- diffImage,
12
- };
13
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=is_ci.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is_ci.d.ts","sourceRoot":"","sources":["../../../src/server/commands/is_ci.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- // import ci from 'is-ci'
2
- export {};
3
- // export interface IsCICommand {
4
- // isCI: () => Promise<boolean>
5
- // }
6
- // export const isCI = async () => ci
@@ -1,8 +0,0 @@
1
- import { PNG } from 'pngjs';
2
- import type { ImageSnapshotCompareOptions } from '../shared/types.ts';
3
- export declare function compareImage(baselineImage: PNG, resultImage: PNG, { failureThreshold, failureThresholdType, diffOptions }?: ImageSnapshotCompareOptions): {
4
- pass: boolean;
5
- diffAmount: number;
6
- diffImage: PNG;
7
- };
8
- //# sourceMappingURL=compare_image.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compare_image.d.ts","sourceRoot":"","sources":["../../src/server/compare_image.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAErE,wBAAgB,YAAY,CAC3B,aAAa,EAAE,GAAG,EAClB,WAAW,EAAE,GAAG,EAChB,EAAE,gBAAoB,EAAE,oBAA8B,EAAE,WAAW,EAAE,GAAE,2BAAgC;;;;EAyBvG"}
@@ -1,16 +0,0 @@
1
- import pixelmatch from 'pixelmatch';
2
- import { PNG } from 'pngjs';
3
- import { convertThresholdUnit } from "../shared/convert_threshold_unit.js";
4
- export function compareImage(baselineImage, resultImage, { failureThreshold = 0, failureThresholdType = 'pixel', diffOptions } = {}) {
5
- const diffImage = new PNG({
6
- width: baselineImage.width,
7
- height: baselineImage.height,
8
- });
9
- const pixelDiff = pixelmatch(resultImage.data, baselineImage.data, diffImage.data, baselineImage.width, baselineImage.height, diffOptions);
10
- const diffAmount = convertThresholdUnit({ failureThresholdType, width: baselineImage.width, height: baselineImage.height }, pixelDiff);
11
- return {
12
- pass: diffAmount <= failureThreshold,
13
- diffAmount,
14
- diffImage,
15
- };
16
- }
@@ -1,21 +0,0 @@
1
- import pixelmatch from 'pixelmatch'
2
- import { convertThresholdUnit } from '../shared/convert_threshold_unit.ts'
3
- import type { ImageSnapshotCompareOptions } from '../shared/types.ts'
4
-
5
- export function compareImage(
6
- baselineImage: ImageData,
7
- resultImage: ImageData,
8
- { failureThreshold = 0, failureThresholdType = 'pixel', diffOptions }: ImageSnapshotCompareOptions = {},
9
- ) {
10
- const { width, height } = resultImage
11
- const diffImage = new ImageData(width, height)
12
-
13
- const pixelDiff = pixelmatch(resultImage.data, baselineImage.data, diffImage.data, width, height, diffOptions)
14
- const diffAmount = convertThresholdUnit({ failureThresholdType, width, height }, pixelDiff)
15
-
16
- return {
17
- pass: diffAmount <= failureThreshold,
18
- diffAmount,
19
- diffImage,
20
- }
21
- }
@@ -1,7 +0,0 @@
1
- // import ci from 'is-ci'
2
-
3
- // export interface IsCICommand {
4
- // isCI: () => Promise<boolean>
5
- // }
6
-
7
- // export const isCI = async () => ci
@@ -1,34 +0,0 @@
1
- import pixelmatch from 'pixelmatch'
2
- import { PNG } from 'pngjs'
3
- import { convertThresholdUnit } from '../shared/convert_threshold_unit.ts'
4
- import type { ImageSnapshotCompareOptions } from '../shared/types.ts'
5
-
6
- export function compareImage(
7
- baselineImage: PNG,
8
- resultImage: PNG,
9
- { failureThreshold = 0, failureThresholdType = 'pixel', diffOptions }: ImageSnapshotCompareOptions = {},
10
- ) {
11
- const diffImage = new PNG({
12
- width: baselineImage.width,
13
- height: baselineImage.height,
14
- })
15
-
16
- const pixelDiff = pixelmatch(
17
- resultImage.data,
18
- baselineImage.data,
19
- diffImage.data,
20
- baselineImage.width,
21
- baselineImage.height,
22
- diffOptions,
23
- )
24
- const diffAmount = convertThresholdUnit(
25
- { failureThresholdType, width: baselineImage.width, height: baselineImage.height },
26
- pixelDiff,
27
- )
28
-
29
- return {
30
- pass: diffAmount <= failureThreshold,
31
- diffAmount,
32
- diffImage,
33
- }
34
- }