LironEr / cypress-mochawesome-reporter

Zero config Mochawesome reporter for Cypress with screenshots and videos
MIT License
158 stars 49 forks source link

feat: add support for cypress-cucumber-preprocessor #172

Closed mistic100 closed 8 months ago

mistic100 commented 8 months ago

This solves #130

Users of cypress-cucumber-preprocessor will be able to import cucumberSupport in their steps in order to store the gherkin AST in the test context. During the report generation the context will be used to remplace the code by the actual gherkin.

I tried to keep the modification as light as possible without adding any required dependencies.

All of this is optionnal allowing to mix Cucumber features and standard tests in the same suite.


There is still need to add tests, for now I cannot tell when I will be able to do it.

LironEr commented 8 months ago

Hey, thanks for the PR. It looks great!

I started to add example & some changes to the README file, but I don't have permissions to the fork, can you please give me push permissions? If that's a problem please look at this commit https://github.com/LironEr/cypress-mochawesome-reporter/commit/1c476b5012460351eb05a3fd3b02806285c1ac63

If you could add some scenarios (some success and some fail), I can create the tests afterward - as I'm unfamiliar with cucumber.

Also just wanted to make sure that this is the output you want image

Thanks.

mistic100 commented 8 months ago

Hey, thanks for the PR. It looks great!

Thank for taking time to look at this :)

I started to add example & some changes to the README file, but I don't have permissions to the fork, can you please give me push permissions?

It seems this is not possible from forks made on an organization https://github.com/orgs/community/discussions/5634

You could cherry-pick my commits and just discard this PR once it is done. I don't really care.

If you could add some scenarios (some success and some fail), I can create the tests afterward - as I'm unfamiliar with cucumber.

Yes of course. I'll try to that for next week.

Also just wanted to make sure that this is the output you want

Yes that's what I expect. The code highlight is not working because it expects JS/TS but that's not really critical, at least for my needs. And it's something to fix/configure in mochawesome anyway, not in the reporter.

mistic100 commented 8 months ago

I just saw that there is not need to grab the gherkinDocument from window.

It is already passed to Before hooks https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/cucumber-basics.md#scenario-hooks

mistic100 commented 8 months ago

@LironEr I added a base example. Tried to understand how your output test works but got no luck :)

I added a note on the README to suggest to use cypress-on-fix module because cypress-cucumber-preprocessor uses the same hooks as cypress-mochawesome-reporter. It is possible to do it manually but much more simplier with this module.

I also have a issue to fix : on the failed job I see the Cucumber source AND the __cucumber_source__ context. I wonder if this is because there is a retry.

Capture d’écran du 2023-12-21 11-34-01

mistic100 commented 8 months ago

Fixed the mentionned issue : it was caused by duplicate context variable (one for each attempt)

Also added a "Scenario Outline" to test this specific case

mistic100 commented 8 months ago

Had a case where "context" was not an array but a single item (it was a non cucumber failing test)

"context": "{\n  \"title\": \"cypress-mochawesome-reporter-screenshots\",\n  \"value\": [\n    [\n      \"/plugins.cy.ts/plugins -- jms (failed).png\"\n    ]\n  ]\n}",

I added a condition in enhanceReport.js to handle this case

LironEr commented 8 months ago

Thank you @mistic100