comparadise-utils 0.0.6 → 0.0.8

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.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupVisualTests = void 0;
4
4
  const screenshots_1 = require("./screenshots");
5
+ const on_after_screenshot_1 = require("./on-after-screenshot");
5
6
  function setupVisualTests(on, config) {
6
7
  on('task', {
7
8
  baseExists: screenshots_1.baseExists,
@@ -11,6 +12,7 @@ function setupVisualTests(on, config) {
11
12
  return null;
12
13
  }
13
14
  });
15
+ on('after:screenshot', on_after_screenshot_1.onAfterScreenshot);
14
16
  return config;
15
17
  }
16
18
  exports.setupVisualTests = setupVisualTests;
@@ -0,0 +1,2 @@
1
+ /// <reference types="cypress" />
2
+ export declare function onAfterScreenshot(details: Cypress.ScreenshotDetails): Promise<Cypress.AfterScreenshotReturnObject>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.onAfterScreenshot = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ function onAfterScreenshot(details) {
29
+ console.log('🧸 Screenshot was saved to:', details.path);
30
+ if (!details.path.match('visual')) {
31
+ return Promise.resolve({});
32
+ }
33
+ const newPath = details.path.substring(details.path.lastIndexOf('cypress/screenshots'));
34
+ const newPathDir = newPath.substring(0, newPath.lastIndexOf('/'));
35
+ try {
36
+ fs.mkdirSync(newPathDir, { recursive: true });
37
+ console.log('🧸 No screenshot folder found in the package. Created new screenshot folder:', newPathDir);
38
+ }
39
+ catch (err) {
40
+ console.error('❌ Error creating new screenshot folder:', newPathDir, err);
41
+ }
42
+ return new Promise((resolve, reject) => {
43
+ fs.rename(details.path, newPath, err => {
44
+ if (err) {
45
+ reject(err);
46
+ }
47
+ resolve({ path: newPath });
48
+ });
49
+ });
50
+ }
51
+ exports.onAfterScreenshot = onAfterScreenshot;
@@ -30,10 +30,9 @@ const pngjs_1 = require("pngjs");
30
30
  const images_1 = require("./images");
31
31
  function baseExists(screenshotFolder) {
32
32
  const fileName = (0, path_1.join)(screenshotFolder, 'base.png');
33
- const relativePath = (0, path_1.relative)(fileName, __dirname);
34
- const exists = fs.existsSync(relativePath);
33
+ const exists = fs.existsSync(fileName);
35
34
  if (!exists) {
36
- console.log(`Base image does not exist at ${relativePath}. This means a new one will be created. If your base should exist, something went wrong.`);
35
+ console.log(`Base image does not exist at ${fileName}. This means a new one will be created. If your base should exist, something went wrong.`);
37
36
  }
38
37
  return exists;
39
38
  }
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "build": "tsc",
30
30
  "postbuild": "echo \"require('./dist/match-screenshot');\" > commands.js"
31
31
  },
32
- "version": "0.0.6"
32
+ "version": "0.0.8"
33
33
  }