comparadise-utils 0.0.1 → 0.0.2
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/commands.js +1 -0
- package/dist/{src/images.js → images.js} +0 -1
- package/dist/index.d.ts +2 -10
- package/dist/index.js +13 -5
- package/dist/{src/match-screenshot.d.ts → match-screenshot.d.ts} +7 -0
- package/dist/match-screenshot.js +63 -0
- package/dist/screenshots.d.ts +2 -0
- package/dist/{src/screenshots.js → screenshots.js} +9 -20
- package/package.json +5 -3
- package/dist/index.js.map +0 -1
- package/dist/src/files.d.ts +0 -1
- package/dist/src/files.js +0 -12
- package/dist/src/files.js.map +0 -1
- package/dist/src/images.js.map +0 -1
- package/dist/src/match-screenshot.js +0 -73
- package/dist/src/match-screenshot.js.map +0 -1
- package/dist/src/on-after-screenshot.d.ts +0 -2
- package/dist/src/on-after-screenshot.js +0 -62
- package/dist/src/on-after-screenshot.js.map +0 -1
- package/dist/src/screenshots.d.ts +0 -3
- package/dist/src/screenshots.js.map +0 -1
- package/dist/src/setup-visual-tests.d.ts +0 -2
- package/dist/src/setup-visual-tests.js +0 -20
- package/dist/src/setup-visual-tests.js.map +0 -1
- /package/dist/{src/images.d.ts → images.d.ts} +0 -0
package/commands.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('./dist/match-screenshot');
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export {};
|
|
4
|
-
declare global {
|
|
5
|
-
namespace Cypress {
|
|
6
|
-
interface Chainable {
|
|
7
|
-
matchScreenshot(args?: MatchScreenshotArgs): Chainable;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
export declare function setupVisualTests(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): Cypress.PluginConfigOptions;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupVisualTests = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const screenshots_1 = require("./screenshots");
|
|
5
|
+
function setupVisualTests(on, config) {
|
|
6
|
+
on('task', {
|
|
7
|
+
baseExists: screenshots_1.baseExists,
|
|
8
|
+
compareScreenshots: screenshots_1.compareScreenshots,
|
|
9
|
+
log: (message) => {
|
|
10
|
+
console.log(message);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return config;
|
|
15
|
+
}
|
|
16
|
+
exports.setupVisualTests = setupVisualTests;
|
|
@@ -4,3 +4,10 @@ export type MatchScreenshotArgs = {
|
|
|
4
4
|
options?: Partial<Cypress.ScreenshotOptions>;
|
|
5
5
|
};
|
|
6
6
|
export declare function matchScreenshot(subject: Cypress.JQueryWithSelector | Window | Document | void, args?: MatchScreenshotArgs): void;
|
|
7
|
+
declare global {
|
|
8
|
+
namespace Cypress {
|
|
9
|
+
interface Chainable {
|
|
10
|
+
matchScreenshot(args?: MatchScreenshotArgs): Chainable;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchScreenshot = void 0;
|
|
4
|
+
function verifyImages() {
|
|
5
|
+
if (Cypress.$('img:visible').length > 0) {
|
|
6
|
+
cy.document()
|
|
7
|
+
.its('body')
|
|
8
|
+
.find('img')
|
|
9
|
+
.filter(':visible')
|
|
10
|
+
.then(images => {
|
|
11
|
+
if (images) {
|
|
12
|
+
cy.wrap(images).each($img => {
|
|
13
|
+
cy.wrap($img).should('exist').and('have.prop', 'naturalWidth');
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function forceFont() {
|
|
20
|
+
const iframe = window.parent.document.querySelector('iframe');
|
|
21
|
+
const contentDocument = iframe && iframe.contentDocument;
|
|
22
|
+
if (contentDocument) {
|
|
23
|
+
const style = contentDocument.createElement('style');
|
|
24
|
+
style.type = 'text/css';
|
|
25
|
+
style.appendChild(contentDocument.createTextNode('* { font-family: Arial !important; }'));
|
|
26
|
+
contentDocument.head.appendChild(style);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function matchScreenshot(subject, args) {
|
|
30
|
+
const { rawName, options = {} } = args || {};
|
|
31
|
+
forceFont();
|
|
32
|
+
verifyImages();
|
|
33
|
+
const { screenshotsFolder } = Cypress.config();
|
|
34
|
+
if (!screenshotsFolder) {
|
|
35
|
+
throw new Error('No screenshots folder found!');
|
|
36
|
+
}
|
|
37
|
+
const testPath = Cypress.spec.relative;
|
|
38
|
+
const lastSlashIndex = testPath.lastIndexOf('/');
|
|
39
|
+
const testPathWithoutFileName = testPath.substring(0, lastSlashIndex);
|
|
40
|
+
const screenshotPath = `${testPathWithoutFileName}/${rawName}`;
|
|
41
|
+
cy.task('baseExists', screenshotPath).then(hasBase => {
|
|
42
|
+
if (typeof hasBase !== 'boolean')
|
|
43
|
+
throw new Error('Result of baseExists task was not a boolean.');
|
|
44
|
+
const target = subject ? cy.wrap(subject) : cy;
|
|
45
|
+
target.screenshot(`${screenshotPath}/new`, { ...options, overwrite: true });
|
|
46
|
+
if (!hasBase) {
|
|
47
|
+
cy.task('log', `❌ A new base image was created at ${screenshotPath}. Add this as a new base image via Comparadise!`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
cy.task('compareScreenshots', screenshotPath).then(diffPixels => {
|
|
51
|
+
if (typeof diffPixels !== 'number')
|
|
52
|
+
throw new Error('Result of compareScreenshots task was not a number.');
|
|
53
|
+
if (diffPixels === 0) {
|
|
54
|
+
cy.log('✅ Actual image was the same as base.');
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
cy.task('log', `❌ Actual image of differed by ${diffPixels} pixels.`);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.matchScreenshot = matchScreenshot;
|
|
63
|
+
Cypress.Commands.add('matchScreenshot', { prevSubject: ['optional', 'element', 'window', 'document'] }, matchScreenshot);
|
|
@@ -23,13 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.compareScreenshots = exports.
|
|
26
|
+
exports.compareScreenshots = exports.baseExists = void 0;
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
|
+
const path_1 = require("path");
|
|
28
29
|
const pngjs_1 = require("pngjs");
|
|
29
30
|
const images_1 = require("./images");
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const fileName = (0, files_1.createImageFileName)(path, 'base');
|
|
31
|
+
function baseExists(screenshotFolder) {
|
|
32
|
+
const fileName = (0, path_1.join)(screenshotFolder, 'base.png');
|
|
33
33
|
const exists = fs.existsSync(fileName);
|
|
34
34
|
if (!exists) {
|
|
35
35
|
console.log('Base image does not exist. This means a new one will be created. If your base should exist, something went wrong.');
|
|
@@ -37,25 +37,15 @@ function baseExists(path) {
|
|
|
37
37
|
return exists;
|
|
38
38
|
}
|
|
39
39
|
exports.baseExists = baseExists;
|
|
40
|
-
function createNewScreenshot(screenshotFolder) {
|
|
41
|
-
const newImage = pngjs_1.PNG.sync.read(fs.readFileSync((0, files_1.createImageFileName)(screenshotFolder, 'new')));
|
|
42
|
-
fs.writeFile((0, files_1.createImageFileName)(screenshotFolder, 'new'), pngjs_1.PNG.sync.write(newImage), err => {
|
|
43
|
-
if (err) {
|
|
44
|
-
console.error('❌Unable to create new.png', err);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
exports.createNewScreenshot = createNewScreenshot;
|
|
50
40
|
function compareScreenshots(screenshotFolder) {
|
|
51
|
-
const basePath = (0,
|
|
52
|
-
const actualPath = (0,
|
|
41
|
+
const basePath = (0, path_1.join)(screenshotFolder, 'base.png');
|
|
42
|
+
const actualPath = (0, path_1.join)(screenshotFolder, 'new.png');
|
|
53
43
|
const { diffPixels, diff } = (0, images_1.getDiffPixels)(basePath, actualPath);
|
|
54
44
|
if (diffPixels) {
|
|
55
45
|
// Create diff.png next to base and new for review
|
|
56
|
-
fs.writeFile((0,
|
|
46
|
+
fs.writeFile((0, path_1.join)(screenshotFolder, 'diff.png'), pngjs_1.PNG.sync.write(diff), err => {
|
|
57
47
|
if (err) {
|
|
58
|
-
console.error('❌Diff exists but unable to create diff.png', err);
|
|
48
|
+
console.error('❌ Diff exists but unable to create diff.png', err);
|
|
59
49
|
}
|
|
60
50
|
});
|
|
61
51
|
}
|
|
@@ -63,11 +53,10 @@ function compareScreenshots(screenshotFolder) {
|
|
|
63
53
|
// Delete created new.png. Not needed if there's no diff
|
|
64
54
|
fs.unlink(actualPath, err => {
|
|
65
55
|
if (err) {
|
|
66
|
-
console.error('❌No diff but unable to
|
|
56
|
+
console.error('❌ No diff but unable to delete actualPath}', err);
|
|
67
57
|
}
|
|
68
58
|
});
|
|
69
59
|
}
|
|
70
60
|
return diffPixels;
|
|
71
61
|
}
|
|
72
62
|
exports.compareScreenshots = compareScreenshots;
|
|
73
|
-
//# sourceMappingURL=screenshots.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"files": [
|
|
7
|
-
"dist"
|
|
7
|
+
"dist",
|
|
8
|
+
"commands.js"
|
|
8
9
|
],
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -25,7 +26,8 @@
|
|
|
25
26
|
"@types/pngjs": "6.0.1"
|
|
26
27
|
},
|
|
27
28
|
"scripts": {
|
|
28
|
-
"build": "tsc"
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"postbuild": "echo \"require('./dist/match-screenshot');\" > commands.js"
|
|
29
31
|
},
|
|
30
|
-
"version": "0.0.
|
|
32
|
+
"version": "0.0.2"
|
|
31
33
|
}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6DAA8E;AAC9E,+DAA4D;AAAnD,sHAAA,gBAAgB,OAAA;AAWzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,WAAW,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,kCAAe,CAAC,CAAC"}
|
package/dist/src/files.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createImageFileName(path: string, type: string): string;
|
package/dist/src/files.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createImageFileName = void 0;
|
|
4
|
-
function createImageFileName(path, type) {
|
|
5
|
-
let newPath = path;
|
|
6
|
-
if (path.startsWith('/')) {
|
|
7
|
-
newPath = `.${path}`;
|
|
8
|
-
}
|
|
9
|
-
return `${newPath}/${type}.png`;
|
|
10
|
-
}
|
|
11
|
-
exports.createImageFileName = createImageFileName;
|
|
12
|
-
//# sourceMappingURL=files.js.map
|
package/dist/src/files.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/files.ts"],"names":[],"mappings":";;;AAAA,SAAgB,mBAAmB,CAAC,IAAY,EAAE,IAAY;IAC5D,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,IAAI,CAAC,UAAU,CAAC,G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gB,EAAE,UAAkB;IAChE,MAAM,OAAO,GAAG,WAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,WAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;IAE7D,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,KAAK,CAAC;IAEjG,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAE1G,MAAM,IAAI,GAAG,IAAI,WAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAEjE,MAAM,UAAU,GAAG,IAAA,oBAAU,EAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAE9G,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC9B,CAAC;AAbD,sCAaC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.matchScreenshot = void 0;
|
|
4
|
-
const PREFIX_DIFFERENTIATOR = '___';
|
|
5
|
-
const SUFFIX_TEST_IDENTIFIER = '.spec.ts';
|
|
6
|
-
const SCREENSHOTS_FOLDER_NAME = 'screenshots';
|
|
7
|
-
function getTestFolderPathFromScripts(rawName) {
|
|
8
|
-
const relativeTestPath = Cypress.spec.relative;
|
|
9
|
-
if (!relativeTestPath) {
|
|
10
|
-
throw new Error('❌ Could not find matching script in the Cypress DOM to infer the test folder path');
|
|
11
|
-
}
|
|
12
|
-
const testName = relativeTestPath.substring(relativeTestPath.lastIndexOf('/') + 1, relativeTestPath.lastIndexOf(SUFFIX_TEST_IDENTIFIER));
|
|
13
|
-
const name = rawName || testName;
|
|
14
|
-
const screenshotsFolder = `${SCREENSHOTS_FOLDER_NAME}/${relativeTestPath.substring(0, relativeTestPath.lastIndexOf(testName))}${name}`;
|
|
15
|
-
return {
|
|
16
|
-
name,
|
|
17
|
-
screenshotsFolder
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function verifyImages() {
|
|
21
|
-
if (Cypress.$('img:visible').length > 0) {
|
|
22
|
-
cy.document()
|
|
23
|
-
.its('body')
|
|
24
|
-
.find('img')
|
|
25
|
-
.filter(':visible')
|
|
26
|
-
.then(images => {
|
|
27
|
-
if (images) {
|
|
28
|
-
cy.wrap(images).each($img => {
|
|
29
|
-
cy.wrap($img).should('exist').and('have.prop', 'naturalWidth');
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function forceFont() {
|
|
36
|
-
const iframe = window.parent.document.querySelector('iframe');
|
|
37
|
-
const contentDocument = iframe?.contentDocument;
|
|
38
|
-
if (contentDocument) {
|
|
39
|
-
const style = contentDocument.createElement('style');
|
|
40
|
-
style.type = 'text/css';
|
|
41
|
-
style.appendChild(contentDocument.createTextNode('* { font-family: Arial !important; }'));
|
|
42
|
-
contentDocument.head.appendChild(style);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function matchScreenshot(subject, args) {
|
|
46
|
-
const { rawName, options = {} } = args ?? {};
|
|
47
|
-
forceFont();
|
|
48
|
-
verifyImages();
|
|
49
|
-
const { name, screenshotsFolder } = getTestFolderPathFromScripts(rawName);
|
|
50
|
-
cy.task('baseExists', screenshotsFolder).then(hasBase => {
|
|
51
|
-
const type = 'new';
|
|
52
|
-
const target = subject ? cy.wrap(subject) : cy;
|
|
53
|
-
// For easy slicing of path ignoring the root screenshot folder
|
|
54
|
-
target.screenshot(`${PREFIX_DIFFERENTIATOR}${screenshotsFolder}/${type}`, options);
|
|
55
|
-
if (!hasBase) {
|
|
56
|
-
cy.task('createNewScreenshot', screenshotsFolder).then(() => {
|
|
57
|
-
cy.task('log', `❌A new base image was created for ${name}. Create this as a new base image via Comparadise!`);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
cy.task('compareScreenshots', screenshotsFolder).then(diffPixels => {
|
|
61
|
-
if (diffPixels === 0) {
|
|
62
|
-
cy.log(`✅Actual image of ${name} was the same as base`);
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
const screenshotUrl = Cypress.env('BUILD_URL') ? `${Cypress.env('BUILD_URL')}artifact/${screenshotsFolder}` : screenshotsFolder;
|
|
66
|
-
throw new Error(`❌Actual image of ${name} differed by ${diffPixels} pixels.
|
|
67
|
-
See the diff image for more details >> ${screenshotUrl}/diff.png`);
|
|
68
|
-
});
|
|
69
|
-
return null;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
exports.matchScreenshot = matchScreenshot;
|
|
73
|
-
//# sourceMappingURL=match-screenshot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"match-screenshot.js","sourceRoot":"","sources":["../../src/match-screenshot.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,sBAAsB,GAAG,UAAU,CAAC;AAC1C,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAE9C,SAAS,4BAA4B,CAAC,OAAgB;IACpD,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;IAE/C,IAAI,CAAC,gBAAgB,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;KACt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AAC,CAAC;gBAExD,OAAO,IAAI,CAAC;aACb;YAED,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,YAAY,iBAAiB,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC;YAEhI,MAAM,IAAI,KAAK,CACb,oBAAoB,IAAI,gBAAgB,UAAU;uDACH,aAAa,WAAW,CACxE,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AApCD,0CAoCC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
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.specName.includes('visual')) {
|
|
31
|
-
return Promise.resolve({});
|
|
32
|
-
}
|
|
33
|
-
const getNewPath = (path) => {
|
|
34
|
-
let newPath = path.slice(path.lastIndexOf('___') + 3);
|
|
35
|
-
console.log(newPath);
|
|
36
|
-
if (newPath.startsWith('/')) {
|
|
37
|
-
newPath = `.${newPath}`;
|
|
38
|
-
}
|
|
39
|
-
return newPath;
|
|
40
|
-
};
|
|
41
|
-
const newPath = getNewPath(details.path);
|
|
42
|
-
const newPathDir = newPath.substring(0, newPath.lastIndexOf('/'));
|
|
43
|
-
try {
|
|
44
|
-
fs.mkdirSync(newPathDir, { recursive: true });
|
|
45
|
-
console.log('🧸 No screenshot folder found in the package. Created new screenshot folder:', newPathDir);
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
console.error('❌ Error creating new screenshot folder:', newPathDir, err);
|
|
49
|
-
}
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
fs.rename(details.path, newPath, err => {
|
|
52
|
-
if (err) {
|
|
53
|
-
reject(err);
|
|
54
|
-
}
|
|
55
|
-
// because we renamed/moved the image, resolve with the new path
|
|
56
|
-
// so it is accurate in the test results
|
|
57
|
-
resolve({ path: newPath });
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
exports.onAfterScreenshot = onAfterScreenshot;
|
|
62
|
-
//# sourceMappingURL=on-after-screenshot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"on-after-screenshot.js","sourceRoot":"","sources":["../../src/on-after-screenshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;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,gBAAwB;IACzD,MAAM,QAAQ,GAAG,IAAA,2BAAmB,EAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,IAAA,2BAAmB,EAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAChE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAA,sBAAa,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAEjE,IAAI,UAAU,EAAE;QACd,kDAAkD;QAClD,EAAE,CAAC,SAAS,CAAC,IAAA,2BAAmB,EAAC,gBAAgB,EAAE,MAAM,CAAC,EAAE,WAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE;YACtF,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAC;aAClE;QACH,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,wDAAwD;QACxD,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE;YAC1B,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,GAAG,CAAC,CAAC;aAChE;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAtBD,gDAsBC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setupVisualTests = void 0;
|
|
4
|
-
const on_after_screenshot_1 = require("./on-after-screenshot");
|
|
5
|
-
const screenshots_1 = require("./screenshots");
|
|
6
|
-
function setupVisualTests(on, config) {
|
|
7
|
-
on('after:screenshot', on_after_screenshot_1.onAfterScreenshot);
|
|
8
|
-
on('task', {
|
|
9
|
-
baseExists: screenshots_1.baseExists,
|
|
10
|
-
compareScreenshots: screenshots_1.compareScreenshots,
|
|
11
|
-
createNewScreenshot: screenshots_1.createNewScreenshot,
|
|
12
|
-
log: (message) => {
|
|
13
|
-
console.log(message);
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return config;
|
|
18
|
-
}
|
|
19
|
-
exports.setupVisualTests = setupVisualTests;
|
|
20
|
-
//# sourceMappingURL=setup-visual-tests.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-visual-tests.js","sourceRoot":"","sources":["../../src/setup-visual-tests.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAC1D,+CAAoF;AAEpF,SAAgB,gBAAgB,CAAC,EAAwB,EAAE,MAAmC;IAC5F,EAAE,CAAC,kBAAkB,EAAE,uCAAiB,CAAC,CAAC;IAC1C,EAAE,CAAC,MAAM,EAAE;QACT,UAAU,EAAV,wBAAU;QACV,kBAAkB,EAAlB,gCAAkB;QAClB,mBAAmB,EAAnB,iCAAmB;QACnB,GAAG,EAAE,CAAC,OAAe,EAAE,EAAE;YACvB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAbD,4CAaC"}
|
|
File without changes
|