UNPKG

@cake-hub/cake-screenshot_diffs

Version:

A CAKE Screenshot diffing tool that includes a setup to comapre two given resources by screenshots taken from the available pages.

101 lines (85 loc) 2.85 kB
const deepMerge = require ("deepmerge"); const path = require ("path"); class BackstopConfiguration { static preparePath (configValue, defaultValue) { configValue = configValue || defaultValue; if (path.isAbsolute (configValue)) { return configValue; } return path.resolve (process.cwd (), configValue); } get ABSOLUTE_REPORT_PATH () { return BackstopConfiguration.preparePath (this._configuration.reportPath, "./backstop_report"); } get REPORT_PATH () { let reportPath = this.ABSOLUTE_REPORT_PATH; reportPath = path.relative (path.resolve (__dirname, "../"), reportPath); return reportPath; } get DEFAULT_CONFIGURATION () { return { id: "cake_showroom", paths: { bitmaps_test: path.join (this.REPORT_PATH, "/bitmaps_test"), bitmaps_reference: path.join (this.REPORT_PATH, "/bitmaps_reference"), engine_scripts: path.relative (path.resolve (this.ABSOLUTE_REPORT_PATH, "../"), path.resolve (__dirname, "./engine_scripts")), html_report: path.join (this.REPORT_PATH, "/html_report"), }, report: [ "browser" ], engine: "puppeteer", onReadyScript: "on-ready-script.js", asyncCaptureLimit: 10, asyncCompareLimit: 50, debug: false, debugWindow: false, }; } constructor (configuration = {}) { this._configuration = configuration; } _keyList (keyPath) { return keyPath.split ("."); } update (object) { this._configuration = deepMerge ( this._configuration, object ); } updateKey (keyPath, value) { let schema = this._configuration; // a moving reference to internal objects within obj const pList = this._keyList (keyPath); const len = pList.length; // ensure the deepest object exists for(let i = 0; i < len - 1; i++) { const elem = pList [i]; if(!schema [elem]) { schema [elem] = {}; } schema = schema [elem]; } schema [pList [len - 1]] = value; } removeKey (keyPath) { this.updateKey (keyPath, undefined); } getKey (keyPath) { let value = this._configuration; for (const key of this._keyList (keyPath)) { if (typeof value [key] === undefined) { return null; } value = value [key]; } return value; } getConfiguration () { return deepMerge ( this.DEFAULT_CONFIGURATION, this._configuration ); } } module.exports = BackstopConfiguration;