@o3r/testing 13.0.0-next.23 → 13.0.0-next.25
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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@o3r/testing",
|
3
|
-
"version": "13.0.0-next.
|
3
|
+
"version": "13.0.0-next.25",
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
@@ -100,12 +100,12 @@
|
|
100
100
|
"@material/slider": "^14.0.0",
|
101
101
|
"@ngrx/store": "^20.0.0",
|
102
102
|
"@ngx-translate/core": "^15.0.0 || ~16.0.4",
|
103
|
-
"@o3r/core": "^13.0.0-next.
|
104
|
-
"@o3r/localization": "^13.0.0-next.
|
105
|
-
"@o3r/schematics": "^13.0.0-next.
|
103
|
+
"@o3r/core": "^13.0.0-next.25",
|
104
|
+
"@o3r/localization": "^13.0.0-next.25",
|
105
|
+
"@o3r/schematics": "^13.0.0-next.25",
|
106
106
|
"@playwright/test": "^1.49.0",
|
107
107
|
"@schematics/angular": "^20.0.0",
|
108
|
-
"pixelmatch": "^
|
108
|
+
"pixelmatch": "^7.0.0",
|
109
109
|
"pngjs": "^7.0.0",
|
110
110
|
"rxjs": "^7.8.1",
|
111
111
|
"temporal-polyfill": "^0.3.0",
|
@@ -167,7 +167,7 @@
|
|
167
167
|
}
|
168
168
|
},
|
169
169
|
"dependencies": {
|
170
|
-
"@o3r/schematics": "^13.0.0-next.
|
170
|
+
"@o3r/schematics": "^13.0.0-next.25",
|
171
171
|
"esbuild": "~0.25.1",
|
172
172
|
"module-from-string": "^3.2.0",
|
173
173
|
"tslib": "^2.6.2"
|
@@ -194,17 +194,17 @@
|
|
194
194
|
"@ngx-translate/core": "~16.0.4",
|
195
195
|
"@nx/eslint-plugin": "~21.3.11",
|
196
196
|
"@nx/jest": "~21.3.11",
|
197
|
-
"@o3r/build-helpers": "^13.0.0-next.
|
198
|
-
"@o3r/core": "^13.0.0-next.
|
199
|
-
"@o3r/eslint-plugin": "^13.0.0-next.
|
200
|
-
"@o3r/localization": "^13.0.0-next.
|
201
|
-
"@o3r/test-helpers": "^13.0.0-next.
|
197
|
+
"@o3r/build-helpers": "^13.0.0-next.25",
|
198
|
+
"@o3r/core": "^13.0.0-next.25",
|
199
|
+
"@o3r/eslint-plugin": "^13.0.0-next.25",
|
200
|
+
"@o3r/localization": "^13.0.0-next.25",
|
201
|
+
"@o3r/test-helpers": "^13.0.0-next.25",
|
202
202
|
"@playwright/test": "~1.51.0",
|
203
203
|
"@schematics/angular": "~20.0.0",
|
204
|
-
"@stylistic/eslint-plugin": "~
|
204
|
+
"@stylistic/eslint-plugin": "~5.2.0",
|
205
205
|
"@swc/helpers": "~0.5.0",
|
206
206
|
"@types/jest": "~29.5.2",
|
207
|
-
"@types/node": "^
|
207
|
+
"@types/node": "^22.0.0",
|
208
208
|
"@types/pixelmatch": "^5.2.3",
|
209
209
|
"@types/pngjs": "^6.0.0",
|
210
210
|
"@typescript-eslint/parser": "~8.37.0",
|
@@ -213,15 +213,15 @@
|
|
213
213
|
"cpy-cli": "^5.0.0",
|
214
214
|
"eslint": "~9.31.0",
|
215
215
|
"eslint-import-resolver-node": "~0.3.9",
|
216
|
-
"eslint-import-resolver-typescript": "~
|
216
|
+
"eslint-import-resolver-typescript": "~4.4.0",
|
217
217
|
"eslint-plugin-import": "~2.32.0",
|
218
218
|
"eslint-plugin-import-newlines": "~1.4.0",
|
219
|
-
"eslint-plugin-jest": "~
|
220
|
-
"eslint-plugin-jsdoc": "~
|
219
|
+
"eslint-plugin-jest": "~29.0.0",
|
220
|
+
"eslint-plugin-jsdoc": "~52.0.0",
|
221
221
|
"eslint-plugin-prefer-arrow": "~1.2.3",
|
222
|
-
"eslint-plugin-unicorn": "~
|
222
|
+
"eslint-plugin-unicorn": "~60.0.0",
|
223
223
|
"eslint-plugin-unused-imports": "~4.1.4",
|
224
|
-
"globals": "^
|
224
|
+
"globals": "^16.0.0",
|
225
225
|
"isomorphic-fetch": "~3.0.0",
|
226
226
|
"jest": "~29.7.0",
|
227
227
|
"jest-environment-jsdom": "~29.7.0",
|
@@ -230,7 +230,7 @@
|
|
230
230
|
"jsonc-eslint-parser": "~2.4.0",
|
231
231
|
"nx": "~21.3.11",
|
232
232
|
"pid-from-port": "^1.1.3",
|
233
|
-
"pixelmatch": "^
|
233
|
+
"pixelmatch": "^7.0.0",
|
234
234
|
"pngjs": "^7.0.0",
|
235
235
|
"rxjs": "^7.8.1",
|
236
236
|
"semver": "^7.5.2",
|
@@ -250,7 +250,7 @@
|
|
250
250
|
"migrations": "./migration.json"
|
251
251
|
},
|
252
252
|
"engines": {
|
253
|
-
"node": "^20.19.0 || ^22.
|
253
|
+
"node": "^20.19.0 || ^22.17.0 || ^24.0.0"
|
254
254
|
},
|
255
255
|
"contributors": [
|
256
256
|
{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../schematics/add-functions-to-fixture/models.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../schematics/add-functions-to-fixture/models.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,eAAe,GACpC,SAAS,GACT,eAAe,GACf,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,kBAAkB,CAAC;AAEvB;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;CAQwB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;CA0CuB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../schematics/add-functions-to-fixture/models.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../schematics/add-functions-to-fixture/models.ts"],"names":[],"mappings":";;;AAWA;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EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB;sBAEb,gBAAgB,aAAa,gBAAgB;;;;EA+BlE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,kBAAkB,SAAqB,QASjK;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,oBAAoB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,QAYxI;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,gBAAgB,CA4B9I;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,wBAAwB,EAAE,MAAM,EAChC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,oBAAoB,SAAY,EAChC,SAAS,SAAI,EACb,YAAY,UAAQ,EACpB,sBAAsB,SAA0B,oBAUjD"}
|
@@ -8,7 +8,7 @@ exports.compareScreenshot = compareScreenshot;
|
|
8
8
|
exports.o3rVisualTest = o3rVisualTest;
|
9
9
|
var fs = require("node:fs");
|
10
10
|
var path = require("node:path");
|
11
|
-
var
|
11
|
+
var pixelmatch_1 = require("pixelmatch");
|
12
12
|
var pngjs_1 = require("pngjs");
|
13
13
|
var utils_1 = require("./utils");
|
14
14
|
Object.defineProperty(exports, "prepareVisualTesting", { enumerable: true, get: function () { return utils_1.prepareVisualTesting; } });
|
@@ -121,7 +121,7 @@ function compareScreenshot(screenshot, baseImagePath, threshold, pathToScenarioR
|
|
121
121
|
var diffDirName = path.basename(baseImagePath, '.png');
|
122
122
|
var result = void 0;
|
123
123
|
try {
|
124
|
-
result =
|
124
|
+
result = (0, pixelmatch_1.default)(baseImage.data, currentImg.data, diff.data, width, height, { threshold: 0.1 });
|
125
125
|
}
|
126
126
|
catch (err) {
|
127
127
|
if (!err.toString().includes('Image sizes do not match.')) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"visual-test.js","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":";;;AAqDA,kDAgCC;AAaD,wCASC;AAWD,oDAYC;AAUD,8CA4BC;AAcD,sCAkBC;AAxMD,4BAA8B;AAC9B,gCAAkC;AAClC,uCAAyC;AACzC,+BAEe;AAEf,iCAGiB;AAFf,6GAAA,oBAAoB,OAAA;AACpB,kHAAA,yBAAyB,OAAA;AAiB3B,uDAAuD;AAC1C,QAAA,kBAAkB,GAAgC;IAC7D,UAAU,EAAE,+BAA+B;IAC3C,WAAW,EAAE,oDAAoD;IACjE,eAAe,EAAE,iCAAiC;IAClD,OAAO,EAAE,wBAAwB;IACjC,YAAY,EAAE,iCAAiC;CACvC,CAAC;AAgBX;;;GAGG;AACH,SAAgB,mBAAmB;IACjC,OAAO;QACL,OAAO,EAAE,UAAC,MAAwB,EAAE,SAA2B;YAC7D,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;gBACxB,OAAO;oBACL,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,0BAAkB,CAAC,YAAY;iBACzC,CAAC;YACJ,CAAC;YACD,IAAI,MAAM,CAAC,sBAAsB,EAAE,CAAC;gBAClC,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,UAAG,0BAAkB,CAAC,eAAe,cAAI,MAAM,CAAC,sBAAsB,CAAC,kBAAkB,CAAE;iBAAE,CAAC;YAC3G,CAAC;YACD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,OAAO;oBACL,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,UAAG,0B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B,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QACvF,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,WAAA,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE,CAAC;IAC9E,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,sBAAsB,EAAE,EAAE,kBAAkB,EAAE,aAAa,EAAE,EAAE,CAAC;IAC3E,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAC3B,aAAqB,EACrB,wBAAgC,EAChC,MAAc,EACd,YAAoB,EACpB,oBAAgC,EAChC,SAAa,EACb,YAAoB,EACpB,sBAAgD;IAHhD,qCAAA,EAAA,gCAAgC;IAChC,0BAAA,EAAA,aAAa;IACb,6BAAA,EAAA,oBAAoB;IACpB,uCAAA,EAAA,gDAAgD;IAEhD,IAAI,YAAY,EAAE,CAAC;QACjB,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,wBAAwB,CAAC,CAAC;QAC9E,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,IAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,YAAY,EAAE,MAAM,EAAE,UAAG,wBAAwB,SAAM,CAAC,CAAC;QACpH,IAAM,gBAAgB,GAAG,iBAAiB,CAAC,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;QAC1G,OAAO,gBAAgB,CAAC;IAC1B,CAAC;AACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as pixelmatch from 'pixelmatch';\nimport {\n PNG,\n} from 'pngjs';\n\nexport {\n prepareVisualTesting,\n toggleVisualTestingRender,\n} from './utils';\n\n/** Error types returned by visual testing comparison */\nexport interface VisualTestMessage {\n /** Error message when base image and actual image have different sizes */\n imagesSize: string;\n /** Error message when base screensot not found */\n baseImgNotFound: string;\n /** Error message when the threshold is passed */\n diffMessage: string;\n /** The message in case of success */\n success: string;\n /** The message in case of generate mode run */\n generateMode: string;\n}\n\n/** Error messages in case of visual testing failure */\nexport const visualTestMessages: Readonly<VisualTestMessage> = {\n imagesSize: 'Image sizes do not match for:',\n diffMessage: 'Diff between images is greater than threshold for:',\n baseImgNotFound: 'Base screenshot file not found:',\n success: 'Visual test successful',\n generateMode: 'Run in generate screenshot mode'\n} as const;\n\n/**\n * Object returned by a visual test operation\n */\nexport interface VisualTestResult {\n /** Error object when base image and actual image have different sizes; Contains the screenshot ffile name */\n imagesSize?: { screenshotName: string };\n /** Error object when base screensot not found. Contains the not found path as a string */\n baseScreenshotNotFound?: { baseScreenshotPath: string };\n /** Object containing the actual diff between images as percentage, the threshold and screenshot file name */\n diff?: { actualDiff: number; threshold: number; screenshotName: string };\n /** Run only generation of screenshots */\n generateMode?: boolean;\n}\n\n/**\n * Visual test matcher\n * Based on the VisualTestResult object return by compareScreenshots function, this matcher will compute the error messages\n */\nexport function toBeVisuallySimilar() {\n return {\n compare: (actual: VisualTestResult, _expected: VisualTestResult) => {\n if (actual.generateMode) {\n return {\n pass: true,\n message: visualTestMessages.generateMode\n };\n }\n if (actual.baseScreenshotNotFound) {\n return {\n pass: false,\n message: `${visualTestMessages.baseImgNotFound} ${actual.baseScreenshotNotFound.baseScreenshotPath}` };\n }\n if (actual.imagesSize) {\n return {\n pass: false,\n message: `${visualTestMessages.imagesSize} ${actual.imagesSize.screenshotName}`\n };\n }\n if (actual.diff && actual.diff.actualDiff > actual.diff.threshold) {\n return {\n pass: false,\n message: `${actual.diff.actualDiff} > ${actual.diff.threshold} : ${visualTestMessages.diffMessage} ${actual.diff.screenshotName}`\n };\n }\n return {\n pass: true,\n message: visualTestMessages.success\n };\n }\n };\n}\n\n/**\n * It will create a file for the passed screenshot object.\n * The path of the new file will be calculated using the parameters\n * Ex: ./dist-screenshots\\OWBooking\\windows_chrome_91\\fare-page-after-click-on-continue-0.png\n * distScreenshotsDir/scenarionName/device/filenameWithoutExtension.png\n * @param screenshot The screenshot object captured. Ex: for protractor - browser.takeScreenshot()\n * @param scenarioName E2e Scenario class name\n * @param device Details of the platform on which the test is run. If there are spaces the helper will do the concatenation. Ex: `Windows 10 chrome 89`\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param distScreenshotsDir Name of the directory to save the screenshots\n */\nexport function saveScreenshot(screenshot: string, scenarioName: string, device: string, filenameWithoutExtension: string, distScreenshotsDir = 'dist-screenshots') {\n const screenshotsDir = path.resolve(distScreenshotsDir, scenarioName, `${device.replace(/ +/g, '_')}`);\n if (!fs.existsSync(screenshotsDir)) {\n fs.mkdirSync(screenshotsDir, { recursive: true });\n }\n const fullFileName = `${filenameWithoutExtension}.png`;\n const stream = fs.createWriteStream(path.resolve(screenshotsDir, fullFileName));\n stream.write(Buffer.from(screenshot, 'base64'));\n stream.end();\n}\n\n/**\n * Write the 3 images (base/new/diff) on the reports folder\n * The path inside the reports forlder will be calculated using the parameters\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder\n * @param screenshotsDirName Name of the directory which will contain the 3 images\n * @param diff diff image\n * @param baseImage the base image\n * @param currentImg the actual taken screenshot image\n */\nexport function writeScreenshotsDiff(pathToScenarioReport: string, screenshotsDirName: string, diff: PNG, baseImage: PNG, currentImg: PNG) {\n const destScreenshotsDiffDir = path.join(pathToScenarioReport, 'screenshots-diff', screenshotsDirName);\n if (!fs.existsSync(destScreenshotsDiffDir)) {\n fs.mkdirSync(destScreenshotsDiffDir, { recursive: true });\n }\n\n const diffPath = path.resolve(destScreenshotsDiffDir, 'diff.png');\n const oldPath = path.resolve(destScreenshotsDiffDir, 'old.png');\n const newPath = path.resolve(destScreenshotsDiffDir, 'new.png');\n fs.writeFileSync(diffPath, PNG.sync.write(diff));\n fs.writeFileSync(oldPath, PNG.sync.write(baseImage));\n fs.writeFileSync(newPath, PNG.sync.write(currentImg));\n}\n\n/**\n * Compare images helper function. If the comparison fails the 3 images (base/new/diff) will be written inside the reports folder of the actual scenario\n * @param screenshot Actual captured screenshot object\n * @param baseImagePath The path to the base screenshot\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder. Used to compute the path to write diff images in case there is a diff at comparison\n * @returns An object of visual test result type\n */\nexport function compareScreenshot(screenshot: string, baseImagePath: string, threshold: number, pathToScenarioReport: string): VisualTestResult {\n const baseImageExists = fs.existsSync(baseImagePath);\n if (baseImageExists) {\n const baseImage = PNG.sync.read(fs.readFileSync(baseImagePath));\n const { width, height } = baseImage;\n const diff = new PNG({ width, height });\n\n const screenshotBuffer = Buffer.from(screenshot, 'base64');\n const currentImg = PNG.sync.read(screenshotBuffer);\n const diffDirName = path.basename(baseImagePath, '.png');\n let result;\n try {\n result = pixelmatch(baseImage.data, currentImg.data, diff.data, width, height, { threshold: 0.1 });\n } catch (err: any) {\n if (!err.toString().includes('Image sizes do not match.')) {\n throw err;\n }\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n return { imagesSize: { screenshotName: diffDirName } };\n }\n const pr = Math.round(100 * 100 * result / (width * height)) / 100;\n if (pr > threshold) {\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n }\n return { diff: { actualDiff: pr, threshold, screenshotName: diffDirName } };\n } else {\n return { baseScreenshotNotFound: { baseScreenshotPath: baseImagePath } };\n }\n}\n\n/**\n * Helper function to perform a visual test operation\n * @param screenshotObj Ex: for protractor browser.takeScreenshot()\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param device os followed by browser version - ex: `Windows 10 chrome 89`\n * @param scenarioName E2e Scenario class name\n * @param pathToScenarioReport Path used in compare mode for saving the base,new,diff images in reports in case there is a diff\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * If the diff is bigger, 3 png files will be created: base screenshot, new screenshot and diff image\n * @param generateMode If true it will generate the screenshot file without screenshots comparison\n * @param baseScreenshotsDirPath The folder path to search base screenshots; used only in compare mode\n */\nexport function o3rVisualTest(\n screenshotObj: string,\n filenameWithoutExtension: string,\n device: string,\n scenarioName: string,\n pathToScenarioReport = 'reports',\n threshold = 0,\n generateMode = false,\n baseScreenshotsDirPath = 'dist-screenshots-base'\n) {\n if (generateMode) {\n saveScreenshot(screenshotObj, scenarioName, device, filenameWithoutExtension);\n return { generateMode: true };\n } else {\n const baseImagePath = path.resolve(baseScreenshotsDirPath, scenarioName, device, `${filenameWithoutExtension}.png`);\n const visualTestResult = compareScreenshot(screenshotObj, baseImagePath, threshold, pathToScenarioReport);\n return visualTestResult;\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"visual-test.js","sourceRoot":"","sources":["../../src/visual-test/visual-test.ts"],"names":[],"mappings":";;;AAqDA,kDAiCC;AAaD,wCASC;AAWD,oDAYC;AAUD,8CA4BC;AAcD,sCAkBC;AAzMD,4BAA8B;AAC9B,gCAAkC;AAClC,yCAAoC;AACpC,+BAEe;AAEf,iCAGiB;AAFf,6GAAA,oBAAoB,OAAA;AACpB,kHAAA,yBAAyB,OAAA;AAiB3B,uDAAuD;AAC1C,QAAA,kBAAkB,GAAgC;IAC7D,UAAU,EAAE,+BAA+B;IAC3C,WAAW,EAAE,oDAAoD;IACjE,eAAe,EAAE,iCAAiC;IAClD,OAAO,EAAE,wBAAwB;IACjC,YAAY,EAAE,iCAAiC;CACvC,CAAC;AAgBX;;;GAGG;AACH,SAAgB,mBAAmB;IACjC,OAAO;QACL,OAAO,EAAE,UAAC,MAAwB,EAAE,SAA2B;YAC7D,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;gBACxB,OAAO;oBACL,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,0BAAkB,CAAC,YAAY;iBACzC,CAAC;YACJ,CAAC;YACD,IAAI,MAAM,CAAC,sBAAsB,EAAE,CAAC;gBAClC,OAAO;oBACL,IAAI,EAAE,KAAK;o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ACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport pixelmatch from 'pixelmatch';\nimport {\n PNG,\n} from 'pngjs';\n\nexport {\n prepareVisualTesting,\n toggleVisualTestingRender,\n} from './utils';\n\n/** Error types returned by visual testing comparison */\nexport interface VisualTestMessage {\n /** Error message when base image and actual image have different sizes */\n imagesSize: string;\n /** Error message when base screensot not found */\n baseImgNotFound: string;\n /** Error message when the threshold is passed */\n diffMessage: string;\n /** The message in case of success */\n success: string;\n /** The message in case of generate mode run */\n generateMode: string;\n}\n\n/** Error messages in case of visual testing failure */\nexport const visualTestMessages: Readonly<VisualTestMessage> = {\n imagesSize: 'Image sizes do not match for:',\n diffMessage: 'Diff between images is greater than threshold for:',\n baseImgNotFound: 'Base screenshot file not found:',\n success: 'Visual test successful',\n generateMode: 'Run in generate screenshot mode'\n} as const;\n\n/**\n * Object returned by a visual test operation\n */\nexport interface VisualTestResult {\n /** Error object when base image and actual image have different sizes; Contains the screenshot ffile name */\n imagesSize?: { screenshotName: string };\n /** Error object when base screensot not found. Contains the not found path as a string */\n baseScreenshotNotFound?: { baseScreenshotPath: string };\n /** Object containing the actual diff between images as percentage, the threshold and screenshot file name */\n diff?: { actualDiff: number; threshold: number; screenshotName: string };\n /** Run only generation of screenshots */\n generateMode?: boolean;\n}\n\n/**\n * Visual test matcher\n * Based on the VisualTestResult object return by compareScreenshots function, this matcher will compute the error messages\n */\nexport function toBeVisuallySimilar() {\n return {\n compare: (actual: VisualTestResult, _expected: VisualTestResult) => {\n if (actual.generateMode) {\n return {\n pass: true,\n message: visualTestMessages.generateMode\n };\n }\n if (actual.baseScreenshotNotFound) {\n return {\n pass: false,\n message: `${visualTestMessages.baseImgNotFound} ${actual.baseScreenshotNotFound.baseScreenshotPath}`\n };\n }\n if (actual.imagesSize) {\n return {\n pass: false,\n message: `${visualTestMessages.imagesSize} ${actual.imagesSize.screenshotName}`\n };\n }\n if (actual.diff && actual.diff.actualDiff > actual.diff.threshold) {\n return {\n pass: false,\n message: `${actual.diff.actualDiff} > ${actual.diff.threshold} : ${visualTestMessages.diffMessage} ${actual.diff.screenshotName}`\n };\n }\n return {\n pass: true,\n message: visualTestMessages.success\n };\n }\n };\n}\n\n/**\n * It will create a file for the passed screenshot object.\n * The path of the new file will be calculated using the parameters\n * Ex: ./dist-screenshots\\OWBooking\\windows_chrome_91\\fare-page-after-click-on-continue-0.png\n * distScreenshotsDir/scenarionName/device/filenameWithoutExtension.png\n * @param screenshot The screenshot object captured. Ex: for protractor - browser.takeScreenshot()\n * @param scenarioName E2e Scenario class name\n * @param device Details of the platform on which the test is run. If there are spaces the helper will do the concatenation. Ex: `Windows 10 chrome 89`\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param distScreenshotsDir Name of the directory to save the screenshots\n */\nexport function saveScreenshot(screenshot: string, scenarioName: string, device: string, filenameWithoutExtension: string, distScreenshotsDir = 'dist-screenshots') {\n const screenshotsDir = path.resolve(distScreenshotsDir, scenarioName, `${device.replace(/ +/g, '_')}`);\n if (!fs.existsSync(screenshotsDir)) {\n fs.mkdirSync(screenshotsDir, { recursive: true });\n }\n const fullFileName = `${filenameWithoutExtension}.png`;\n const stream = fs.createWriteStream(path.resolve(screenshotsDir, fullFileName));\n stream.write(Buffer.from(screenshot, 'base64'));\n stream.end();\n}\n\n/**\n * Write the 3 images (base/new/diff) on the reports folder\n * The path inside the reports forlder will be calculated using the parameters\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder\n * @param screenshotsDirName Name of the directory which will contain the 3 images\n * @param diff diff image\n * @param baseImage the base image\n * @param currentImg the actual taken screenshot image\n */\nexport function writeScreenshotsDiff(pathToScenarioReport: string, screenshotsDirName: string, diff: PNG, baseImage: PNG, currentImg: PNG) {\n const destScreenshotsDiffDir = path.join(pathToScenarioReport, 'screenshots-diff', screenshotsDirName);\n if (!fs.existsSync(destScreenshotsDiffDir)) {\n fs.mkdirSync(destScreenshotsDiffDir, { recursive: true });\n }\n\n const diffPath = path.resolve(destScreenshotsDiffDir, 'diff.png');\n const oldPath = path.resolve(destScreenshotsDiffDir, 'old.png');\n const newPath = path.resolve(destScreenshotsDiffDir, 'new.png');\n fs.writeFileSync(diffPath, PNG.sync.write(diff));\n fs.writeFileSync(oldPath, PNG.sync.write(baseImage));\n fs.writeFileSync(newPath, PNG.sync.write(currentImg));\n}\n\n/**\n * Compare images helper function. If the comparison fails the 3 images (base/new/diff) will be written inside the reports folder of the actual scenario\n * @param screenshot Actual captured screenshot object\n * @param baseImagePath The path to the base screenshot\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * @param pathToScenarioReport Path where the scenario report is saved inside reports folder. Used to compute the path to write diff images in case there is a diff at comparison\n * @returns An object of visual test result type\n */\nexport function compareScreenshot(screenshot: string, baseImagePath: string, threshold: number, pathToScenarioReport: string): VisualTestResult {\n const baseImageExists = fs.existsSync(baseImagePath);\n if (baseImageExists) {\n const baseImage = PNG.sync.read(fs.readFileSync(baseImagePath));\n const { width, height } = baseImage;\n const diff = new PNG({ width, height });\n\n const screenshotBuffer = Buffer.from(screenshot, 'base64');\n const currentImg = PNG.sync.read(screenshotBuffer);\n const diffDirName = path.basename(baseImagePath, '.png');\n let result;\n try {\n result = pixelmatch(baseImage.data, currentImg.data, diff.data, width, height, { threshold: 0.1 });\n } catch (err: any) {\n if (!err.toString().includes('Image sizes do not match.')) {\n throw err;\n }\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n return { imagesSize: { screenshotName: diffDirName } };\n }\n const pr = Math.round(100 * 100 * result / (width * height)) / 100;\n if (pr > threshold) {\n writeScreenshotsDiff(pathToScenarioReport, diffDirName, diff, baseImage, currentImg);\n }\n return { diff: { actualDiff: pr, threshold, screenshotName: diffDirName } };\n } else {\n return { baseScreenshotNotFound: { baseScreenshotPath: baseImagePath } };\n }\n}\n\n/**\n * Helper function to perform a visual test operation\n * @param screenshotObj Ex: for protractor browser.takeScreenshot()\n * @param filenameWithoutExtension file name to save the screenshot - .png will be added at the end\n * @param device os followed by browser version - ex: `Windows 10 chrome 89`\n * @param scenarioName E2e Scenario class name\n * @param pathToScenarioReport Path used in compare mode for saving the base,new,diff images in reports in case there is a diff\n * @param threshold The diff between base screenshot and the current one should not be bigger than this value.\n * If the diff is bigger, 3 png files will be created: base screenshot, new screenshot and diff image\n * @param generateMode If true it will generate the screenshot file without screenshots comparison\n * @param baseScreenshotsDirPath The folder path to search base screenshots; used only in compare mode\n */\nexport function o3rVisualTest(\n screenshotObj: string,\n filenameWithoutExtension: string,\n device: string,\n scenarioName: string,\n pathToScenarioReport = 'reports',\n threshold = 0,\n generateMode = false,\n baseScreenshotsDirPath = 'dist-screenshots-base'\n) {\n if (generateMode) {\n saveScreenshot(screenshotObj, scenarioName, device, filenameWithoutExtension);\n return { generateMode: true };\n } else {\n const baseImagePath = path.resolve(baseScreenshotsDirPath, scenarioName, device, `${filenameWithoutExtension}.png`);\n const visualTestResult = compareScreenshot(screenshotObj, baseImagePath, threshold, pathToScenarioReport);\n return visualTestResult;\n }\n}\n"]}
|