vitest-plugin-vis 1.0.1 → 1.0.2

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.
@@ -32,7 +32,7 @@ export const matchImageSnapshot = async (context, taskId, subject, options) => {
32
32
  : alignImageSizes(baselineImage, resultImage);
33
33
  const { pass, diffAmount, diffImage } = compareImage(baselineAlignedImage, resultAlignedImage, options);
34
34
  if (pass) {
35
- if (sizeNotChanged(baselineImage, baselineAlignedImage)) {
35
+ if (sizeNotChanged(baselineImage, baselineAlignedImage) && sizeNotChanged(resultImage, resultAlignedImage)) {
36
36
  return;
37
37
  }
38
38
  throw new Error(dedent `Snapshot \`${taskId}\` mismatched
@@ -75,13 +75,18 @@ async function writeSnapshot(subject, filePath) {
75
75
  }
76
76
  function alignImageSizes(baseline, result) {
77
77
  const size = getMaxSize(baseline, result);
78
- const baselineAligned = new PNG(size);
79
- const resultAligned = new PNG(size);
80
- baselineAligned.data.fill(0);
81
- resultAligned.data.fill(0);
82
- PNG.bitblt(baseline, baselineAligned, 0, 0, baseline.width, baseline.height);
83
- PNG.bitblt(result, resultAligned, 0, 0, result.width, result.height);
84
- return [baselineAligned, resultAligned];
78
+ if (baseline.width !== size.width || baseline.height !== size.height) {
79
+ baseline = resizeImage(baseline, size);
80
+ }
81
+ if (result.width !== size.width || result.height !== size.height) {
82
+ result = resizeImage(result, size);
83
+ }
84
+ return [baseline, result];
85
+ }
86
+ function resizeImage(image, size) {
87
+ const resized = new PNG(size);
88
+ PNG.bitblt(image, resized, 0, 0, image.width, image.height);
89
+ return resized;
85
90
  }
86
91
  function sizeNotChanged(baselineImage, baselineAlignedImage) {
87
92
  return baselineImage === baselineAlignedImage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -62,7 +62,7 @@ export const matchImageSnapshot: BrowserCommand<
62
62
 
63
63
  const { pass, diffAmount, diffImage } = compareImage(baselineAlignedImage, resultAlignedImage, options)
64
64
  if (pass) {
65
- if (sizeNotChanged(baselineImage, baselineAlignedImage)) {
65
+ if (sizeNotChanged(baselineImage, baselineAlignedImage) && sizeNotChanged(resultImage, resultAlignedImage)) {
66
66
  return
67
67
  }
68
68
  throw new Error(
@@ -123,17 +123,23 @@ async function writeSnapshot(subject: string, filePath: string) {
123
123
  function alignImageSizes(baseline: PNG, result: PNG) {
124
124
  const size = getMaxSize(baseline, result)
125
125
 
126
- const baselineAligned = new PNG(size)
127
- const resultAligned = new PNG(size)
126
+ if (baseline.width !== size.width || baseline.height !== size.height) {
127
+ baseline = resizeImage(baseline, size)
128
+ }
128
129
 
129
- baselineAligned.data.fill(0)
130
- resultAligned.data.fill(0)
130
+ if (result.width !== size.width || result.height !== size.height) {
131
+ result = resizeImage(result, size)
132
+ }
131
133
 
132
- PNG.bitblt(baseline, baselineAligned, 0, 0, baseline.width, baseline.height)
133
- PNG.bitblt(result, resultAligned, 0, 0, result.width, result.height)
134
+ return [baseline, result] as const
135
+ }
134
136
 
135
- return [baselineAligned, resultAligned] as const
137
+ function resizeImage(image: PNG, size: { width: number; height: number }) {
138
+ const resized = new PNG(size)
139
+ PNG.bitblt(image, resized, 0, 0, image.width, image.height)
140
+ return resized
136
141
  }
142
+
137
143
  function sizeNotChanged(baselineImage: PNG, baselineAlignedImage: PNG) {
138
144
  return baselineImage === baselineAlignedImage
139
145
  }