{ "version": 3, "sources": ["../../cypress-visual-regression/dist/command.mjs"], "sourcesContent": ["// src/command.ts\nfunction addCompareSnapshotCommand(screenshotOptions) {\n Cypress.Commands.add(\n \"compareSnapshot\",\n { prevSubject: [\"optional\", \"element\"] },\n function(subject, name, commandOptions) {\n if (name === void 0 || name === \"\") {\n throw new Error(\"Snapshot name must be specified\");\n }\n const screenshotOptionsObject = { ...screenshotOptions };\n const commandOptionsObject = typeof commandOptions === \"number\" ? { errorThreshold: commandOptions } : { ...commandOptions };\n const visualRegressionOptions = prepareOptions(name, screenshotOptionsObject, commandOptionsObject);\n const folderAndName = `${Cypress.spec.relative}/${name}`;\n return takeScreenshot(subject, folderAndName, visualRegressionOptions.screenshotOptions).then(\n (screenshotPath) => {\n visualRegressionOptions.screenshotAbsolutePath = screenshotPath;\n visualRegressionOptions.spec = Cypress.spec;\n switch (visualRegressionOptions.type) {\n case \"regression\":\n return compareScreenshots(subject, visualRegressionOptions);\n case \"base\":\n return updateSnapshots(subject, visualRegressionOptions);\n default:\n throw new Error(\n `The 'type' environment variable is invalid. Expected: 'regression' or 'base' instead of '${visualRegressionOptions.type}'`\n );\n }\n }\n );\n }\n );\n}\nfunction prepareOptions(name, screenshotOptions, commandOptions) {\n if (Cypress.env(\"visualRegressionType\") === void 0) {\n throw new Error(\"The 'type' environment variable is missing. Expected values: 'regression' or 'base'\");\n }\n const defaultCommandOptions = {\n errorThreshold: 0,\n failSilently: false,\n pixelmatchOptions: { threshold: 0.1 }\n };\n const options = {\n type: Cypress.env(\"visualRegressionType\"),\n screenshotName: name,\n screenshotAbsolutePath: \"null\",\n // will be set after takeScreenshot\n pluginOptions: defaultCommandOptions,\n screenshotOptions: {},\n baseDirectory: \"cypress/snapshots/base\",\n diffDirectory: \"cypress/snapshots/diff\",\n generateDiff: \"fail\",\n spec: Cypress.spec\n };\n if (screenshotOptions.pixelmatchOptions !== void 0) {\n options.pluginOptions.pixelmatchOptions = screenshotOptions.pixelmatchOptions;\n }\n if (screenshotOptions.errorThreshold !== void 0) {\n options.pluginOptions.errorThreshold = screenshotOptions.errorThreshold;\n }\n if (screenshotOptions.failSilently !== void 0) {\n options.pluginOptions.failSilently = screenshotOptions.failSilently;\n }\n options.screenshotOptions = { ...screenshotOptions, ...commandOptions };\n if (Cypress.env(\"visualRegressionBaseDirectory\") !== void 0) {\n options.baseDirectory = Cypress.env(\"visualRegressionBaseDirectory\");\n }\n if (Cypress.env(\"visualRegressionDiffDirectory\") !== void 0) {\n options.diffDirectory = Cypress.env(\"visualRegressionDiffDirectory\");\n }\n if (Cypress.env(\"visualRegressionGenerateDiff\") !== void 0) {\n options.generateDiff = Cypress.env(\"visualRegressionGenerateDiff\");\n }\n if (Cypress.env(\"visualRegressionFailSilently\") !== void 0) {\n options.pluginOptions.failSilently = Cypress.env(\"visualRegressionFailSilently\");\n }\n if (commandOptions.failSilently !== void 0) {\n options.pluginOptions.failSilently = commandOptions.failSilently;\n }\n if (commandOptions.errorThreshold !== void 0) {\n options.pluginOptions.errorThreshold = commandOptions.errorThreshold;\n }\n if (commandOptions.pixelmatchOptions !== void 0) {\n options.pluginOptions.pixelmatchOptions = commandOptions.pixelmatchOptions;\n }\n return options;\n}\nfunction takeScreenshot(subject, name, screenshotOptions) {\n const objToOperateOn = subject !== void 0 ? cy.get(subject) : cy;\n let screenshotDetails;\n return objToOperateOn.screenshot(name, {\n ...screenshotOptions,\n log: false,\n onAfterScreenshot(_el, props) {\n screenshotDetails = props.path;\n screenshotOptions?.onAfterScreenshot?.(_el, props);\n }\n }).then(() => screenshotDetails);\n}\nfunction compareScreenshots(subject, options) {\n return cy.task(\"compareSnapshots\", options, { log: false }).then((result) => {\n const log = Cypress.log({\n type: \"parent\",\n name: \"compareScreenshots\",\n displayName: \"compareScreenshots\",\n message: \"captureMode: 'fullPage'\",\n consoleProps: () => {\n return {\n Options: options,\n Result: result\n };\n }\n });\n if (subject != null) {\n log.set(\"$el\", subject);\n log.set(\"message\", subject.selector);\n log.set(\"type\", \"child\");\n } else if (options.screenshotOptions?.capture !== void 0) {\n log.set(\"message\", `captureMode: ${options.screenshotOptions.capture}`);\n }\n if (result.error !== void 0 && !options.pluginOptions.failSilently) {\n if (result.error.includes(\"image is different\") && top !== null) {\n const random = Math.random();\n result.error += ` - [Show Difference](#visualRegressionPopup${random})`;\n Cypress.$(top.document.body).on(\"click\", `a[href^=\"#visualRegressionPopup${random}\"]`, (e) => {\n e.preventDefault();\n if (top === null) {\n throw Error(\"Cypress runner not properly initialized\");\n }\n Cypress.$(getVisual(result.images)).appendTo(top.document.body);\n if (result.images.diff === void 0) {\n Cypress.$(\"#diffContainer\", top.document.body).remove();\n }\n const popup = Cypress.$(\"#visualRegressionPopup\", top.document.body);\n popup.on(\"click\", 'button[data-type=\"close\"]', () => {\n popup.remove();\n });\n popup.on(\"click\", function(e2) {\n if (e2.target === this) {\n popup.remove();\n }\n });\n return false;\n });\n }\n throw constructCypressError(log, new Error(result.error));\n }\n return result;\n });\n}\nfunction updateSnapshots(subject, options) {\n return cy.task(\"updateSnapshot\", options, { log: false }).then((result) => {\n const log = Cypress.log({\n type: \"parent\",\n name: \"compareScreenshots\",\n displayName: \"compareScreenshots\",\n message: \"base generation\",\n consoleProps: () => {\n return {\n Options: options,\n Result: result\n };\n }\n });\n if (subject != null) {\n log.set(\"$el\", subject);\n log.set(\"type\", \"child\");\n }\n return result;\n });\n}\nvar constructCypressError = (log, err) => {\n ;\n err.onFail = (err2) => log.error(err2);\n return err;\n};\nfunction getVisual(images) {\n return `\n
\n
\n
\n \n
\n
\n
\n
\n \"Actual\n \"Base\n
\n
\n
\n \"Diff\n
\n
\n
\n
\n
\n\n`;\n}\nexport {\n addCompareSnapshotCommand\n};\n"], "mappings": ";;;AACA,SAAS,0BAA0B,mBAAmB;AACpD,UAAQ,SAAS;AAAA,IACf;AAAA,IACA,EAAE,aAAa,CAAC,YAAY,SAAS,EAAE;AAAA,IACvC,SAAS,SAAS,MAAM,gBAAgB;AACtC,UAAI,SAAS,UAAU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