cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.04k stars 1.09k forks source link

Allow customization option for junit formatter #2265

Closed Tallyb closed 1 year ago

Tallyb commented 1 year ago

🤔 What's the problem you're trying to solve?

currently all reports generated with cucumberjs junit formatter bear the name 'cucumber-js'. It would be great to be able to customize it via format options and cli param

✨ What's your proposed solution?

format option with test suite name.

⛏ Have you considered any alternatives or workarounds?

open for suggestions...

📚 Any additional context?

On a side note, it is not really clear how to configure options in a cucumber.mjs file when there are multiple formtters defined.


format: [
  'json:e2e/reports/cucumber-report.json',
  'junit:e2e/reports/cucumber-report.xml',
  'summary'
];

Adding options to the json formatter and to the junit in a single formatOptions: {} entry is cumbersome. Probably best to make each formatter an object. 

format: [
  {type: json, output: 'json:e2e/reports/cucumber-report.json', options: {x: 1, y: false}},
  { type: 'junit', output:  'e2e/reports/cucumber-report.xml', options: {x: 1, z: true}},
  'summary'
];
davidjgoss commented 1 year ago

Adding options to the json formatter and to the junit in a single formatOptions: {} entry is cumbersome

I tend to agree, and I like your suggestion, though that would potentially end up being a significant change so let's make another issue for that.

davidjgoss commented 1 year ago

To enable this with the current options structure we'd do something like:

{
  "formatOptions": {
    "junit": {
      "suiteName": "my test suite"
    }
  }
}
davidjgoss commented 1 year ago

The line in question is here https://github.com/cucumber/cucumber-js/blob/main/src/formatter/junit_formatter.ts#L245. The options being passed into the constructor has a parsedArgvOptions prop which should be the format options from the user.

Sam-ScottLogic commented 1 year ago

May I work on this? This is my first time contributing so may have a few questions along the way!

davidjgoss commented 1 year ago

Sure @Sam-ScottLogic, go for it! Feel free to ask questions here, or join #committers-js in the Slack https://cucumber.io/docs/community/get-in-touch/

astocker-scottlogic commented 1 year ago

@Sam-ScottLogic Hi am I okay to take a look into this?

Sam-ScottLogic commented 1 year ago

@astocker-scottlogic Yes!