Skip to content
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

Add dotnet implementation of the htmlformatter #352

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

clrudolphi
Copy link

Port of the Java implementation to .NET.

🤔 What's changed?

Added .NET implementation of htmlformatter and test suite, based port of the Java implementation.
Added lines to the global Make file to push the javascript build artifacts to the dotnet Resources folder.

⚡️ What's your motivation?

Intended for inclusion with Reqnroll reporting.

🏷️ What kind of change is this?

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

♻️ Anything particular you want feedback on?

Will need assistance in getting the Nuget package publishing set-up.

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • 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.

Added Unreleased note about the addition of the .NET impl
@mpkorstanje mpkorstanje self-requested a review February 17, 2025 08:26
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cucumber.Messages" Version="27.0.2" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use a version range here? The html formatter is fairly backwards compatible with older messages.

Copy link
Author

Choose a reason for hiding this comment

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

I put in a range to go back to R26. That was when I updated the Messages code generation approach to use the current system (retiring the old protobuf method). Assuming there was a risk that I broke something there, that is as far back as I'm comfortable.

Copy link
Author

Choose a reason for hiding this comment

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

I had to correct that to only r27.0 as the minimum. R27 introduced a new enumeration type (HookType) and the serializer needs to know about all such enumerations for proper conversion.

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, on first quick review I don't see anything too surprising.

Do you need help setting up automated tests on Github? The messages and or Gherkins repos might provide inspiration

Copy link
Contributor

@davidjgoss davidjgoss left a comment

Choose a reason for hiding this comment

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

More of a question, but the root of the .NET impl here is dotnet/htmlformatter, where with Gherkin for example it's just under dotnet (basing this on where the .sln file is in each one). Could/should we squash this up to match Gherkin's structure?

@clrudolphi
Copy link
Author

clrudolphi commented Feb 17, 2025

More of a question, but the root of the .NET impl here is dotnet/htmlformatter, where with Gherkin for example it's just under dotnet (basing this on where the .sln file is in each one). Could/should we squash this up to match Gherkin's structure?

Hmm, there are some inconsistencies then across the Cucumber/dotnet landscape. In Messages, the source and .sln are in ./dotnet/Cucumber.Messages (that is, not directly under the dotnet folder).

Which would you prefer? The Gherkin structure is much older. I created the Messages one. So I don't mind changing both.

Corrected .gitignore files and CHANGELOG.md
Reference to Messages nuget package updated to use a range specifier (going back to r26)
@mpkorstanje
Copy link
Contributor

Hmm, there are some inconsistencies then across the Cucumber/dotnet landscape. In Messages, the source and .sln are in ./dotnet/Cucumber.Messages (that is, not directly under the dotnet folder).

Not sure I'm following that one.

There is

So I would expect there to be something like dotnet/Html.Formatter.sln

@clrudolphi
Copy link
Author

Hmm, there are some inconsistencies then across the Cucumber/dotnet landscape. In Messages, the source and .sln are in ./dotnet/Cucumber.Messages (that is, not directly under the dotnet folder).

Not sure I'm following that one.

There is

So I would expect there to be something like dotnet/Html.Formatter.sln

Oh, I see. I thought you were commenting the directory structure per se; not merely the location of the .sln file. I'll fix that.

Removed the intermediary htmlformatter folder in order to match other Cucumber project's structures.
Corrected nuget dependency range on Messages to [27.0,28.0).
@clrudolphi
Copy link
Author

I'll fix that.

Fixed. Intermediary folder removed.

Updated the .csproj file to include information for Nuget publication of the htmlformatter assembly.
Adopted .github/workflow/*.yml from the Messages repo for .NET build and publication.
@clrudolphi
Copy link
Author

clrudolphi commented Feb 17, 2025

Added CI build files in .github/workflows, based upon what was used in Messages.
This fails as we need a .snk (Strong Name Key) file for html-formatter.

Does the github build system invoke the Make before invoking each of the individual platform github build/test yml workflows? (just want to ensure the generated assets are in place...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Mostly a question: What are the .net standards for file names? The gherkin and messages projects seem to be using pascal case for these files and . in place of non-az characters.

Copy link
Author

Choose a reason for hiding this comment

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

More of a convention than a standard, yes. I will change them.
In terms of project naming, do you want me to follow the lead of the java implementation and simply call it Htmlformatter? Or should I follow the lead of Messages and call it Cucumber.Htmlformatter?

Copy link
Contributor

Choose a reason for hiding this comment

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

That depends!

For Java the full name is io.cucumber:html-formatter.

Looks like NuGet doesn't have namespaces. So the produced artifact should be Cucumber.HtmlFormatter.

Then I would expect the project files to follow the artifact name. Unless there is a strong convention in the .Net world that recommends otherwise. In which case the files in our other projects should be renamed.

Copy link
Author

Choose a reason for hiding this comment

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

Ok. Changed to Cucumber.Htmlformatter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not in Pascal case?

Copy link
Author

Choose a reason for hiding this comment

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

OK. Done.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Feb 17, 2025

This fails as we need a .snk (Strong Name Key) file for html-formatter.

I get the impression we are following this advice:

If you are an open-source developer and you want the identity benefits of a strong-named assembly for better compatibility with .NET Framework, consider checking in the private key associated with an assembly to your source control system.

But I'm not sure, I can't read the .snkfiles from Gherkin and Messages to compare.

Changed capitalization of names of files to match convention used in other projects.
Added a .snk file for the nuget publishing.
@clrudolphi
Copy link
Author

This fails as we need a .snk (Strong Name Key) file for html-formatter.

I get the impression we are following this advice:

If you are an open-source developer and you want the identity benefits of a strong-named assembly for better compatibility with .NET Framework, consider checking in the private key associated with an assembly to your source control system.

But I'm not sure, I can't read the .snkfiles from Gherkin and Messages to compare.

Talked to Gaspar, and checked in a .snk file.

Further correction based upon feedback
Again; to make it Pascal cased.
Copy link
Author

@clrudolphi clrudolphi left a comment

Choose a reason for hiding this comment

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

the test-dotnet is failing with a pathing problem. Would you have time to take a look?
The project file "/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/Cucumber.HtmlFormatter.csproj" was not found.

@mpkorstanje
Copy link
Contributor

@charlierudolph are you using a case insensitive file system?

Screenshot_20250217-213427

@clrudolphi
Copy link
Author

@charlierudolph are you using a case insensitive file system?

Well that sucks.

That doesn't match what is in my local repo.

I'm on Windows if that matters.

@mpkorstanje
Copy link
Contributor

Then your filesystem is case insensitive by default.

https://learn.microsoft.com/en-us/windows/wsl/case-sensitivity

I'm going to modify the files. Then you'll probably want to delete your repo and clone it again.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Feb 17, 2025

Now it works.

Just some warnings and complaints in the output.

Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/MessagesToHtmlWriter.cs(30,48): warning CS8625: Cannot convert null literal to non-nullable reference type. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/Cucumber.HtmlFormatter.csproj]
Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/MessagesToHtmlWriter.cs(39,62): warning CS8625: Cannot convert null literal to non-nullable reference type. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/Cucumber.HtmlFormatter.csproj]
  Cucumber.HtmlFormatter -> /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/bin/Debug/netstandard2.0/Cucumber.HtmlFormatter.dll
  The package Cucumber.HtmlFormatter.21.9.0 is missing a readme. Go to https://aka.ms/nuget/authoring-best-practices/readme to learn why package readmes are important.
  Successfully created package '/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/bin/Debug/NuGet/Cucumber.HtmlFormatter.21.9.0.nupkg'.
Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/CucumberMessageEnumConverter.cs(20,29): warning CS8605: Unboxing a possibly null value. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/Cucumber.HtmlFormatterTest.csproj]
Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/CucumberMessageEnumConverter.cs(31,46): warning CS8604: Possible null reference argument for parameter 'key' in 'bool Dictionary<string, T>.TryGetValue(string key, out T value)'. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/Cucumber.HtmlFormatterTest.csproj]

@clrudolphi
Copy link
Author

clrudolphi commented Feb 17, 2025

Now it works.

Just some warnings and complaints in the output.

Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/MessagesToHtmlWriter.cs(30,48): warning CS8625: Cannot convert null literal to non-nullable reference type. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/Cucumber.HtmlFormatter.csproj]
Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/MessagesToHtmlWriter.cs(39,62): warning CS8625: Cannot convert null literal to non-nullable reference type. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/Cucumber.HtmlFormatter.csproj]
  Cucumber.HtmlFormatter -> /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/bin/Debug/netstandard2.0/Cucumber.HtmlFormatter.dll
  The package Cucumber.HtmlFormatter.21.9.0 is missing a readme. Go to https://aka.ms/nuget/authoring-best-practices/readme to learn why package readmes are important.
  Successfully created package '/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatter/bin/Debug/NuGet/Cucumber.HtmlFormatter.21.9.0.nupkg'.
Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/CucumberMessageEnumConverter.cs(20,29): warning CS8605: Unboxing a possibly null value. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/Cucumber.HtmlFormatterTest.csproj]
Warning: /home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/CucumberMessageEnumConverter.cs(31,46): warning CS8604: Possible null reference argument for parameter 'key' in 'bool Dictionary<string, T>.TryGetValue(string key, out T value)'. [/home/runner/work/html-formatter/html-formatter/dotnet/HtmlFormatterTest/Cucumber.HtmlFormatterTest.csproj]

EDIT: I've addressed the compilation warnings.
I'll address the read.me nag tomorrow.

Added README.md and included it in the nuget package definition.
@clrudolphi clrudolphi marked this pull request as ready for review February 18, 2025 22:22
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.

I'm fine with it generally. I have made a few minor code-style related comments.

<None Remove="Resources\index.mustache.html" />
<None Remove="Resources\main.css" />
<None Remove="Resources\main.js" />
<None Remove="Resources\main.js.LICENSE.txt" />
Copy link
Member

Choose a reason for hiding this comment

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

As far as I know, you don't have to remove the items from the None group (because it is not doing anything anyway)

Copy link
Author

Choose a reason for hiding this comment

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

Deleted

@mpkorstanje mpkorstanje changed the title Initial Commit of dotnet implementation of the htmlformatter Add dotnet implementation of the htmlformatter Feb 19, 2025
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.

I don't know if anything is still open from the others, but from my perspective this is good to go, thx!

@mpkorstanje mpkorstanje self-requested a review February 19, 2025 23:22
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.

4 participants