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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return [
|
|
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
|
@@ -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
|
-
|
|
127
|
-
|
|
126
|
+
if (baseline.width !== size.width || baseline.height !== size.height) {
|
|
127
|
+
baseline = resizeImage(baseline, size)
|
|
128
|
+
}
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
if (result.width !== size.width || result.height !== size.height) {
|
|
131
|
+
result = resizeImage(result, size)
|
|
132
|
+
}
|
|
131
133
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
return [baseline, result] as const
|
|
135
|
+
}
|
|
134
136
|
|
|
135
|
-
|
|
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
|
}
|