comparadise-utils 1.24.2 → 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 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
@@ -43,7 +43,12 @@ var fs = __toESM(require("fs"));
43
43
  var import_pngjs = require("pngjs");
44
44
  var import_pixelmatch = __toESM(require("pixelmatch"));
45
45
  var PIXELMATCH_OPTIONS = {
46
- threshold: 0.3
46
+ alpha: 0.3,
47
+ // defaults to 0.1
48
+ threshold: 0.5,
49
+ // defaults to 0.1
50
+ includeAA: false
51
+ // defaults to true
47
52
  };
48
53
  var createImageResizer = (width, height) => (source) => {
49
54
  const resized = new import_pngjs.PNG({ width, height, fill: true });
@@ -81,7 +86,7 @@ function alignImagesToSameSize(firstImage, secondImage) {
81
86
  fillSizeDifference(secondImageWidth, secondImageHeight)(resizedSecond)
82
87
  ];
83
88
  }
84
- function getDiffPixels(basePath, actualPath) {
89
+ function getDiffPixels(basePath, actualPath, pixelMatchOptions = PIXELMATCH_OPTIONS) {
85
90
  const rawBase = import_pngjs.PNG.sync.read(fs.readFileSync(basePath));
86
91
  const rawActual = import_pngjs.PNG.sync.read(fs.readFileSync(actualPath));
87
92
  const hasSizeMismatch = rawBase.height !== rawActual.height || rawBase.width !== rawActual.width;
@@ -96,7 +101,7 @@ function getDiffPixels(basePath, actualPath) {
96
101
  diff.data,
97
102
  diff.width,
98
103
  diff.height,
99
- PIXELMATCH_OPTIONS
104
+ pixelMatchOptions
100
105
  );
101
106
  return { diffPixels, diff };
102
107
  }
@@ -122,10 +127,15 @@ function baseExists(path) {
122
127
  }
123
128
  return exists;
124
129
  }
125
- function compareScreenshots(screenshotFolder) {
130
+ function compareScreenshots(args) {
131
+ const { screenshotFolder, pixelMatchOptions } = args;
126
132
  const basePath = createImageFileName(screenshotFolder, "base");
127
133
  const actualPath = createImageFileName(screenshotFolder, "new");
128
- const { diffPixels, diff } = getDiffPixels(basePath, actualPath);
134
+ const { diffPixels, diff } = getDiffPixels(
135
+ basePath,
136
+ actualPath,
137
+ pixelMatchOptions
138
+ );
129
139
  if (diffPixels) {
130
140
  fs2.writeFile(
131
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 {
@@ -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,9 @@ 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 = { 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 {
package/package.json CHANGED
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/pngjs": "6.0.5",
24
- "cypress": "14.0.3",
25
- "tsup": "8.3.6"
24
+ "cypress": "14.1.0",
25
+ "tsup": "8.4.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "cypress": ">=12"
29
29
  },
30
- "version": "1.24.2",
30
+ "version": "1.25.0",
31
31
  "scripts": {
32
32
  "build": "tsup",
33
33
  "postbuild": "echo \"require('./dist/match-screenshot');\" > commands.js",