-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
205 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
GitHubActionsTestLogger/Templates/MarkdownRazorTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using RazorBlade; | ||
|
||
namespace GitHubActionsTestLogger.Templates; | ||
|
||
internal abstract class MarkdownRazorTemplate<T> : PlainTextTemplate<T> | ||
{ | ||
protected MarkdownRazorTemplate(T model) | ||
: base(model) | ||
{ | ||
} | ||
|
||
// In order to produce HTML that's also valid Markdown, we need to | ||
// remove some whitespace inside literals. | ||
public new void WriteLiteral(string? literal) | ||
{ | ||
if (!string.IsNullOrEmpty(literal)) | ||
{ | ||
base.WriteLiteral( | ||
literal | ||
// Remove indentation | ||
.Replace(" ", "") | ||
// Remove linebreaks | ||
.Replace("\r", "").Replace("\n", "") | ||
); | ||
} | ||
else | ||
{ | ||
base.WriteLiteral(literal); | ||
} | ||
} | ||
|
||
// Using params here to write multiple lines as a workaround | ||
// for the fact that Razor does not support raw string literals. | ||
protected void WriteMarkdown(params string?[] lines) | ||
{ | ||
// Two line breaks are required to separate markdown from HTML | ||
base.WriteLiteral("\n\n"); | ||
|
||
foreach (var line in lines) | ||
{ | ||
base.WriteLiteral(line); | ||
base.WriteLiteral("\n"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace GitHubActionsTestLogger.Templates; | ||
|
||
internal class TestSummaryContext | ||
{ | ||
public required TestLoggerOptions Options { get; init; } | ||
|
||
public required string TestSuite { get; init; } | ||
|
||
public required string TargetFramework { get; init; } | ||
|
||
public required TestRunResult TestRunResult { get; init; } | ||
} |
11 changes: 11 additions & 0 deletions
11
GitHubActionsTestLogger/Templates/TestSummaryDetailsTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace GitHubActionsTestLogger.Templates; | ||
|
||
// Workaround for: | ||
// https://github.com/ltrzesniewski/RazorBlade/issues/10 | ||
internal partial class TestSummaryDetailsTemplate | ||
{ | ||
public TestSummaryDetailsTemplate(TestSummaryContext context) | ||
: base(context) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace GitHubActionsTestLogger.Templates; | ||
|
||
// Workaround for: | ||
// https://github.com/ltrzesniewski/RazorBlade/issues/10 | ||
internal partial class TestSummaryTemplate | ||
{ | ||
public TestSummaryTemplate(TestSummaryContext context) | ||
: base(context) | ||
{ | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
GitHubActionsTestLogger/Templates/TestSummaryTemplate.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@using Microsoft.VisualStudio.TestPlatform.ObjectModel | ||
|
||
@inherits MarkdownRazorTemplate<TestSummaryContext> | ||
|
||
@{ | ||
string FormatTestOutcome(TestOutcome outcome) => outcome switch | ||
{ | ||
TestOutcome.Passed => "🟢", | ||
TestOutcome.Failed => "🔴", | ||
_ => "🟡" | ||
}; | ||
} | ||
|
||
@if (Model.Options.SummaryCompactLayout) | ||
{ | ||
// Have to yield raw HTML | ||
<details> | ||
<summary> | ||
<b>@FormatTestOutcome(Model.TestRunResult.OverallOutcome) @Model.TestSuite</b> (@Model.TargetFramework) | ||
</summary> | ||
|
||
@* This adds a margin that is smaller than <br> *@ | ||
<p></p> | ||
|
||
@(new TestSummaryDetailsTemplate(Model)) | ||
</details> | ||
} | ||
else | ||
{ | ||
<h2> | ||
@FormatTestOutcome(Model.TestRunResult.OverallOutcome) @Model.TestSuite <sub><sup>(@Model.TargetFramework)</sup></sub> | ||
</h2> | ||
|
||
@(new TestSummaryDetailsTemplate(Model)) | ||
|
||
<hr /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.