comparadise-utils 1.24.3 → 1.25.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -4
- package/dist/match-screenshot.d.ts +7 -1
- package/dist/match-screenshot.js +4 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -86,7 +86,7 @@ function alignImagesToSameSize(firstImage, secondImage) {
|
|
|
86
86
|
fillSizeDifference(secondImageWidth, secondImageHeight)(resizedSecond)
|
|
87
87
|
];
|
|
88
88
|
}
|
|
89
|
-
function getDiffPixels(basePath, actualPath) {
|
|
89
|
+
function getDiffPixels(basePath, actualPath, pixelMatchOptions = PIXELMATCH_OPTIONS) {
|
|
90
90
|
const rawBase = import_pngjs.PNG.sync.read(fs.readFileSync(basePath));
|
|
91
91
|
const rawActual = import_pngjs.PNG.sync.read(fs.readFileSync(actualPath));
|
|
92
92
|
const hasSizeMismatch = rawBase.height !== rawActual.height || rawBase.width !== rawActual.width;
|
|
@@ -101,7 +101,7 @@ function getDiffPixels(basePath, actualPath) {
|
|
|
101
101
|
diff.data,
|
|
102
102
|
diff.width,
|
|
103
103
|
diff.height,
|
|
104
|
-
|
|
104
|
+
pixelMatchOptions
|
|
105
105
|
);
|
|
106
106
|
return { diffPixels, diff };
|
|
107
107
|
}
|
|
@@ -127,10 +127,15 @@ function baseExists(path) {
|
|
|
127
127
|
}
|
|
128
128
|
return exists;
|
|
129
129
|
}
|
|
130
|
-
function compareScreenshots(
|
|
130
|
+
function compareScreenshots(args) {
|
|
131
|
+
const { screenshotFolder, pixelMatchOptions } = args;
|
|
131
132
|
const basePath = createImageFileName(screenshotFolder, "base");
|
|
132
133
|
const actualPath = createImageFileName(screenshotFolder, "new");
|
|
133
|
-
const { diffPixels, diff } = getDiffPixels(
|
|
134
|
+
const { diffPixels, diff } = getDiffPixels(
|
|
135
|
+
basePath,
|
|
136
|
+
actualPath,
|
|
137
|
+
pixelMatchOptions
|
|
138
|
+
);
|
|
134
139
|
if (diffPixels) {
|
|
135
140
|
fs2.writeFile(
|
|
136
141
|
createImageFileName(screenshotFolder, "diff"),
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import pixelmatch from 'pixelmatch';
|
|
2
|
+
|
|
3
|
+
type PixelMatchOptions = Parameters<typeof pixelmatch>[5];
|
|
4
|
+
|
|
1
5
|
type MatchScreenshotArgs = {
|
|
2
6
|
rawName?: string;
|
|
3
|
-
options?: Partial<Cypress.ScreenshotOptions
|
|
7
|
+
options?: Partial<Cypress.ScreenshotOptions> & {
|
|
8
|
+
pixelMatchOptions?: PixelMatchOptions;
|
|
9
|
+
};
|
|
4
10
|
};
|
|
5
11
|
declare function matchScreenshot(subject: Cypress.JQueryWithSelector | Window | Document | void, args?: MatchScreenshotArgs): void;
|
|
6
12
|
interface ExtendedCurrentRunnable extends Mocha.Runnable {
|
package/dist/match-screenshot.js
CHANGED
|
@@ -79,7 +79,7 @@ function verifyImages() {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function matchScreenshot(subject, args) {
|
|
82
|
-
const { rawName, options
|
|
82
|
+
const { rawName, options } = args || {};
|
|
83
83
|
forceFont();
|
|
84
84
|
verifyImages();
|
|
85
85
|
const { name, screenshotsFolder } = getTestFolderPathFromScripts(rawName);
|
|
@@ -96,7 +96,9 @@ function matchScreenshot(subject, args) {
|
|
|
96
96
|
);
|
|
97
97
|
return null;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
const pixelMatchOptions = options?.pixelMatchOptions;
|
|
100
|
+
const compareScreenshotsArg = { screenshotsFolder, pixelMatchOptions };
|
|
101
|
+
cy.task("compareScreenshots", compareScreenshotsArg).then((diffPixels) => {
|
|
100
102
|
if (diffPixels === 0) {
|
|
101
103
|
cy.log(`\u2705 Actual image of ${name} was the same as base`);
|
|
102
104
|
} else {
|