haim-io / cypress-image-diff

Visual regression test with cypress
MIT License
240 stars 62 forks source link

HTML report generation cypress-mochawesome-reporter plugin broken when updating cypress-image-diff-js from V1.26.0 to V1.30.1 #177

Closed MelvinBaaijAviva closed 10 months ago

MelvinBaaijAviva commented 10 months ago

Hi,

I am experiencing a problem. My cypress-mochawesome-reporter plugin (V3.6.0) does not generate html reports after updating cypress-image-diff-js from V1.26.0 to V1.30.1 (using Typescript and Cypress 12.7.4 ). I am not using a seperate cypress-image-diff.config.js

kien-ht commented 10 months ago

Hi. Can you share the code where you configured cypress-mochawesome-reporter and our plugin please?

kien-ht commented 10 months ago

I assume this is the Cypress multiple on events issue, https://github.com/cypress-io/cypress/issues/5240. I have taken a look at the cypress-mochawesome-reporter codebase, and interestingly they also use the after:run hook, and so does our plugin. If we register the same event more than once, Cypress will only apply the handler of the last one. We have one issue related to this, https://github.com/uktrade/cypress-image-diff/issues/172#issuecomment-1714066937.

You could wrap the on function before passing it to any plugins and forward all events. I believe there are solutions for this and cypress-plugin-init is one of them.

MelvinBaaijAviva commented 10 months ago

I assume this is the Cypress multiple on events issue, cypress-io/cypress#5240. I have taken a look at the cypress-mochawesome-reporter codebase, and interestingly they also use the after:run hook, and so does our plugin. If we register the same event more than once, Cypress will only apply the handler of the last one. We have one issue related to this, #172 (comment).

You could wrap the on function before passing it to any plugins and forward all events. I believe there are solutions for this and cypress-plugin-init is one of them.

@kien-ht thanks for the fast reply and further investigation. I implemented the cypress-plugin-init solution. I will close this issue because this fixes my problem. Thank you!