comparadise-utils 1.24.3 → 1.25.1
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 +12 -7
- package/dist/match-screenshot.d.ts +7 -1
- package/dist/match-screenshot.js +7 -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,13 +127,18 @@ function baseExists(path) {
|
|
|
127
127
|
}
|
|
128
128
|
return exists;
|
|
129
129
|
}
|
|
130
|
-
function compareScreenshots(
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
const
|
|
130
|
+
function compareScreenshots(args) {
|
|
131
|
+
const { screenshotsFolder, pixelMatchOptions } = args;
|
|
132
|
+
const basePath = createImageFileName(screenshotsFolder, "base");
|
|
133
|
+
const actualPath = createImageFileName(screenshotsFolder, "new");
|
|
134
|
+
const { diffPixels, diff } = getDiffPixels(
|
|
135
|
+
basePath,
|
|
136
|
+
actualPath,
|
|
137
|
+
pixelMatchOptions
|
|
138
|
+
);
|
|
134
139
|
if (diffPixels) {
|
|
135
140
|
fs2.writeFile(
|
|
136
|
-
createImageFileName(
|
|
141
|
+
createImageFileName(screenshotsFolder, "diff"),
|
|
137
142
|
new Uint8Array(import_pngjs2.PNG.sync.write(diff)),
|
|
138
143
|
(err) => {
|
|
139
144
|
if (err) {
|
|
@@ -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,12 @@ function matchScreenshot(subject, args) {
|
|
|
96
96
|
);
|
|
97
97
|
return null;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
const pixelMatchOptions = options?.pixelMatchOptions;
|
|
100
|
+
const compareScreenshotsArg = {
|
|
101
|
+
screenshotsFolder,
|
|
102
|
+
pixelMatchOptions
|
|
103
|
+
};
|
|
104
|
+
cy.task("compareScreenshots", compareScreenshotsArg).then((diffPixels) => {
|
|
100
105
|
if (diffPixels === 0) {
|
|
101
106
|
cy.log(`\u2705 Actual image of ${name} was the same as base`);
|
|
102
107
|
} else {
|