Skip to content

Add async implementations to the HtmlFormatter. #376

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

Merged
merged 9 commits into from
Jun 19, 2025
Merged

Conversation

clrudolphi
Copy link
Contributor

@clrudolphi clrudolphi commented Jun 2, 2025

🤔 What's changed?

Added async method implementations.

⚡️ What's your motivation?

Reqnroll will want to consume the async implementations in its implementation of Messages.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)

♻️ Anything particular you want feedback on?

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • [X ] I've changed the behaviour of the code
    • [ X] I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • [ X] 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.

@clrudolphi clrudolphi requested a review from gasparnagy June 2, 2025 15:45
Copy link
Member

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

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

Do we need to maintain both the async and the sync methods? Would it be just enough to keep the async one?

public override void Write(char[] value)
{
Write(value, 0, value.GetLength(0));
}

public async Task WriteAsync(char[] value)
Copy link
Member

Choose a reason for hiding this comment

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

Based on the warning, this method should have been done anyway.

'JsonInHtmlWriter.WriteAsync(char[])' hides inherited member 'TextWriter.WriteAsync(char[])'. Use the new keyword if hiding was intended.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was not clear with this one. This "override" is not necessary. The method in the base class is implemented in the same way, I think. So delete this method?

@mpkorstanje
Copy link
Contributor

Do we need to maintain both the async and the sync methods?

Your call. The only difference is the resulting version number. If sync is removed then it will be a major release, otherwise a minor.

@clrudolphi
Copy link
Contributor Author

clrudolphi commented Jun 3, 2025

Do we need to maintain both the async and the sync methods? Would it be just enough to keep the async one?

I put the [Obsolete] marker on the sync constructors.
We can release this as a minor and come back later to remove them completely.

@clrudolphi clrudolphi marked this pull request as ready for review June 18, 2025 01:57
@clrudolphi clrudolphi requested a review from gasparnagy June 18, 2025 01:58
Copy link
Member

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

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

Some cosmetic things...

public override void Write(char[] value)
{
Write(value, 0, value.GetLength(0));
}

public async Task WriteAsync(char[] value)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was not clear with this one. This "override" is not necessary. The method in the base class is implemented in the same way, I think. So delete this method?

string html = await RenderAsHtmlAsync();
Assert.IsTrue(html.Contains("window.CUCUMBER_MESSAGES = [];"));
}

[TestMethod]
public void ItThrowsWhenWritingAfterClose()
Copy link
Member

Choose a reason for hiding this comment

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

(GitHub didn't allow me to add this comment to line 69)

These tests (testing the sync) should be deleted or wrap the constructor call with pragmas to disable this warning explicitly, like

#pragma warning disable CS0618 // Type or member is obsolete
            MessagesToHtmlWriter messagesToHtmlWriter = new MessagesToHtmlWriter(bytes, serializer);
#pragma warning restore CS0618 // Type or member is obsolete

Same for all other warnings in this file.

In general, the compilation should produce no warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made both sets of changes per your requests.

@clrudolphi
Copy link
Contributor Author

I think this is ready to be merged, but I don't know why the javascript test is failing. Can someone take a look at that?

@mpkorstanje
Copy link
Contributor

I think this is ready to be merged, but I don't know why the javascript test is failing. Can someone take a look at that?

Looks like that was already fixed on main.

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. But a few remarks. I'll fix these right now.

@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
Copy link
Contributor

Choose a reason for hiding this comment

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

I've changed this to added. It doesn't look like anything was removed. Is that correct w.r.t the guidance on http://semver.org?

public override void Write(char[] value)
{
Write(value, 0, value.GetLength(0));
}

//public async Task WriteAsync(char[] value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be removed?

public MessagesToHtmlWriter(Stream stream, Action<StreamWriter, Envelope> streamSerializer) : this(new StreamWriter(stream), streamSerializer)
{
}
public MessagesToHtmlWriter(Stream stream, Func<StreamWriter, Envelope, Task> asyncStreamSerializer) : this(new StreamWriter(stream), asyncStreamSerializer) { }

[Obsolete("Cucumber.HtmlFormatter moving to async only operations. Please use the MessagesToHtmlWriter(StreamWriter, Func<StreamWriter, Envelope, Task>) constructor", false)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a deprecation. So this needs its own deprecated entry in the changelog. This will inform the decision for the next version number.

@mpkorstanje
Copy link
Contributor

And as a mental note, when removing the deprecated methods, please also mark the JsonInHtmlWriter as internal. That makes it less ambiguous which parts of this library are the API.

Atleast if I understood this all correctly: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/accessibility-levels

@mpkorstanje mpkorstanje merged commit a1b3995 into main Jun 19, 2025
1 check passed
@mpkorstanje mpkorstanje deleted the dotnet_async branch June 19, 2025 17:33
@mpkorstanje mpkorstanje changed the title Added async implementations to the HtmlFormatter. Add async implementations to the HtmlFormatter. Jun 19, 2025
@clrudolphi
Copy link
Contributor Author

@mpkorstanje Thanks for taking care of these items!

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.

3 participants