Skip to content

dotnet: allow customizing resources in subclasses #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

gasparnagy
Copy link
Member

🤔 What's changed?

Made resource-loading methods virtual, so that they can be overridden in subclasses

⚡️ What's your motivation?

Allowing generating customized HTML reports.

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

Copy link
Contributor

@mpkorstanje mpkorstanje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gasparnagy what is the broader usecase for customization?

For example, to apply custom styling, I imagine that an additional resource would be needed. For that use case I'm not sure overriding would be the best solution. For more complicated customization, I imagine it would be better to fork the entire project.

And would it be possible to prefer composition over inheritance? I.e. provide the constructor with three functions to lazy-load the resources as needed. Using a rather ad-hoc override makes API evolution much more difficult.

@gasparnagy
Copy link
Member Author

gasparnagy commented Aug 4, 2025

@mpkorstanje Yes, the motivation was getting towards to enable customizations like mentioned at https://github.com/cucumber/react-components?tab=readme-ov-file#styling.

You are absolutely right, this change is really just a very basic way of customization - replace the resources with an own-compiled ones. This is basically to be able to make some experiments until the proper customization model/interfaces are figured out. So this is not going to be the advertised way of customization.

As this component is now going to be used in Reqnroll, you would need to replace quite many components in order to apply a quick fix if you would fork this. That would be a blocker for many early adapters.

@mpkorstanje
Copy link
Contributor

This is basically to be able to make some experiments until the proper customization model/interfaces are figured out. So this is not going to be the advertised way of customization.

Then I'd still prefer a solution that doesn't use extension.

IIRC .Net supports default values constructor parameters so the solution I suggested would be pretty light weight and effectively allow for the same experimentation with customization.

@gasparnagy
Copy link
Member Author

This is basically to be able to make some experiments until the proper customization model/interfaces are figured out. So this is not going to be the advertised way of customization.

Then I'd still prefer a solution that doesn't use extension.

IIRC .Net supports default values constructor parameters so the solution I suggested would be pretty light weight and effectively allow for the same experimentation with customization.

Ok. I will rework.

@gasparnagy gasparnagy marked this pull request as draft August 4, 2025 17:59
@gasparnagy gasparnagy marked this pull request as ready for review August 5, 2025 11:59
@gasparnagy gasparnagy requested a review from mpkorstanje August 5, 2025 11:59
@gasparnagy
Copy link
Member Author

@mpkorstanje What do you think?

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Aug 6, 2025

I'm a bit swamped this week. Hopefully next week.

@gasparnagy
Copy link
Member Author

I'm a bit swamped this week. Hopefully next week.

Thx. This is kind of a blocker for us, so if you happen to have a bit of time earlier to review that it is appreciated.

Copy link
Contributor

@mpkorstanje mpkorstanje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Only small remarks on API life management.

/// </summary>
/// <param name="name">The resource name</param>
/// <returns>The resource content</returns>
protected string GetResource(string name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be private now I think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// <summary>
/// Interface for providing resources to the HTML formatter
/// </summary>
public interface IResourceProvider
Copy link
Contributor

@mpkorstanje mpkorstanje Aug 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we indicate that his is an experimental API? If we're planning to do a settings object, with builder I imagine use of that object would be something like,

new Setting()
  .withCssResource(...)
  .withJavascriptResource(...)
  .withEct(...)

And with sensible defaults in place if a particular method of the builder isn't called.

The IResourceProvider doesn't support those sensible defaults and so I imagine it will be phased out again too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highlighted that this is experimental

/// Gets the HTML template
/// </summary>
/// <returns>The HTML template</returns>
string GetTemplateResource();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the template is suitable for replacement. It is not actually a mustache template, it just looks like one.

There is a hard coded assumption in the code that the template contains {{css}}, {{messages}} and {{script}} and also in that order. If that ever changes, we'd break consumers of the API.

But that is acceptable if this is marked as an experimental API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I need this for the tweaking, but the interface is marked as experimental. But you are right, in long term, we should not need this.
The theming customization might require something, but we can solve it in other ways too - let's discuss when we talk about the customizations.

@mpkorstanje
Copy link
Contributor

Superseded by #409

@gasparnagy gasparnagy deleted the dotnet-allow-customizing-resources branch August 11, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants