UNPKG

@mmisty/cypress-allure-adapter

Version:

cypress allure adapter to generate allure results during tests execution (Allure TestOps compatible)

45 lines (44 loc) 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerScreenshotHandler = void 0; const helper_1 = require("./helper"); const common_1 = require("../common"); const deb = 'cypress-allure:screenshots'; const registerScreenshotHandler = (message, testMsg) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const originalHandler = Cypress.Screenshot.onAfterScreenshot; const debug = (0, helper_1.logClient)(deb); // eslint-disable-next-line @typescript-eslint/no-explicit-any Cypress.Screenshot.onAfterScreenshot = (_$el, ...args) => { debug('Screenshot handler'); // testAttemptIndex, takenAt, name, specName, testFailure const [screensArgs] = args; const [{ path }] = args; if (path) { const win = window; if (win.allureAttachToStep) { debug(`Attaching to step: ${path}`); message.message({ task: 'screenshotAttachment', arg: screensArgs, }); Cypress.Allure.fileAttachment((0, common_1.basename)(path), path, (0, common_1.getContentType)(path)); testMsg(`cypress:screenshot:${(0, common_1.basename)(path)}`); } else { debug(`Attaching to test: ${path}`); message.message({ task: 'screenshotAttachment', arg: screensArgs, }); Cypress.Allure.testFileAttachment((0, common_1.basename)(path), path, (0, common_1.getContentType)(path)); testMsg(`cypress:screenshot:test:${(0, common_1.basename)(path)}`); } } else { debug(`No path: ${JSON.stringify(args)}`); } originalHandler(_$el, ...args); }; }; exports.registerScreenshotHandler = registerScreenshotHandler;