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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import { MatchScreenshotArgs } from './match-screenshot.js';
2
+ import 'pixelmatch';
2
3
 
3
4
  declare function setupVisualTests(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): Cypress.PluginConfigOptions;
4
5
  declare global {
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
- PIXELMATCH_OPTIONS
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(screenshotFolder) {
131
- const basePath = createImageFileName(screenshotFolder, "base");
132
- const actualPath = createImageFileName(screenshotFolder, "new");
133
- const { diffPixels, diff } = getDiffPixels(basePath, actualPath);
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(screenshotFolder, "diff"),
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 {
@@ -79,7 +79,7 @@ function verifyImages() {
79
79
  }
80
80
  }
81
81
  function matchScreenshot(subject, args) {
82
- const { rawName, options = {} } = args || {};
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
- cy.task("compareScreenshots", screenshotsFolder).then((diffPixels) => {
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 {
package/package.json CHANGED
@@ -27,7 +27,7 @@
27
27
  "peerDependencies": {
28
28
  "cypress": ">=12"
29
29
  },
30
- "version": "1.24.3",
30
+ "version": "1.25.1",
31
31
  "scripts": {
32
32
  "build": "tsup",
33
33
  "postbuild": "echo \"require('./dist/match-screenshot');\" > commands.js",