adamgruber / mochawesome

A Gorgeous HTML/CSS Reporter for Mocha.js
https://gitter.im/mochawesome/general
MIT License
1.06k stars 160 forks source link

How to use Relative path instead of Absolute path for failed screenshot due to cypress-image-snapshot #388

Open 787681277 opened 1 year ago

787681277 commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Cannot see failed screenshot in mochareports/report.html after run testing in pipeline

Because failed screenshot use Absolute path, and redundant path "/script" is displayed after run testing in pipeline: "See diff for details: /scripts/cypress/snapshots/chrome/tab/tab.component.cy.ts/__diff_output__/activeIndex-1.diff.png"

Code Reproduce Link to repo where the issue can reliably be reproduced:

//Inject cypress-image-snapshot diff images to Mochawesome reports const addContext = require('mochawesome/addContext'); Cypress.on('test:after:run', (test, runnable) => { if(test.state === 'failed') { let screenshot; screenshot = ${Cypress.config('screenshotsFolder')}/${Cypress.spec.name}/${runnable.parent.title} -- ${test.title} (failed).png; if(test.err.message.includes('See diff')) { // If the test failed due to cypress-image-snapshot the message will always be the same and the plugin gives you in the message the url of the path screenshot = test.err.parsedStack[1].message.replace('See diff for details: ', ''); } addContext({test}, { title: 'Image', value: screenshot }); } })

Expected behavior A clear and concise description of what you expected to happen.

Use Relative path for failed screenshots due to cypress-image-snapshot , the failed screenshot can be seen after run testing in piepline

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context Add any other context about the problem here.