Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst committed Jan 10, 2025
1 parent b1b8bf8 commit 1bef219
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions TUnit.Engine/Extensions/TestApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void AddTUnit(this ITestApplicationBuilder testApplicationBuilder)

testApplicationBuilder.RegisterTestFramework(
serviceProvider => new TestFrameworkCapabilities(new TrxReportCapability(), new BannerCapability(serviceProvider.GetRequiredService<IPlatformInformation>(), serviceProvider.GetCommandLineOptions())),
(capabilities, serviceProvider) => new TUnitTestFramework(extension, serviceProvider, capabilities));
(capabilities, serviceProvider) => new TUnitTestFramework(extension, serviceProvider, capabilities, [githubReporter]));

testApplicationBuilder.AddTreeNodeFilterService(extension);
// TODO: testApplicationBuilder.CommandLine.AddProvider(() => new JsonOutputCommandProvider(extension));
Expand All @@ -34,6 +34,6 @@ public static void AddTUnit(this ITestApplicationBuilder testApplicationBuilder)
testApplicationBuilder.CommandLine.AddProvider(() => new DisableLogoCommandProvider(extension));

testApplicationBuilder.TestHost.AddDataConsumer(_ => githubReporter);
testApplicationBuilder.TestHost.AddTestApplicationLifecycleCallbacks(sp => githubReporter.WithFilter(FilterParser.StringifyFilter(sp.GetRequiredService<ITestExecutionFilter>())));
testApplicationBuilder.TestHost.AddTestApplicationLifecycleCallbacks(_ => githubReporter);
}
}
6 changes: 6 additions & 0 deletions TUnit.Engine/Framework/IFilterReceiver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TUnit.Engine.Framework;

public interface IFilterReceiver
{
string? Filter { set; }
}
10 changes: 9 additions & 1 deletion TUnit.Engine/Framework/TUnitTestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ internal sealed class TUnitTestFramework : ITestFramework, IDataProducer
private readonly IExtension _extension;
private readonly IServiceProvider _frameworkServiceProvider;
private readonly ITestFrameworkCapabilities _capabilities;
private readonly IEnumerable<IFilterReceiver> _filterReceivers;
private static readonly ConcurrentDictionary<string, TUnitServiceProvider> ServiceProvidersPerSession = [];

public TUnitTestFramework(IExtension extension,
IServiceProvider frameworkServiceProvider,
ITestFrameworkCapabilities capabilities)
ITestFrameworkCapabilities capabilities,
IEnumerable<IFilterReceiver> filterReceivers)
{
_extension = extension;
_frameworkServiceProvider = frameworkServiceProvider;
_capabilities = capabilities;
_filterReceivers = filterReceivers;
}

public Task<bool> IsEnabledAsync() => _extension.IsEnabledAsync();
Expand Down Expand Up @@ -51,6 +54,11 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
);

var stringFilter = serviceProvider.FilterParser.GetTestFilter(context);

foreach (var filterReceiver in _filterReceivers)
{
filterReceiver.Filter = stringFilter;
}

var logger = serviceProvider.Logger;

Expand Down
36 changes: 21 additions & 15 deletions TUnit.Engine/Reporters/GitHubReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.TestHost;
using TUnit.Engine.Framework;

namespace TUnit.Engine.Reporters;

public class GitHubReporter(IExtension extension) : IDataConsumer, ITestApplicationLifecycleCallbacks
public class GitHubReporter(IExtension extension) : IDataConsumer, ITestApplicationLifecycleCallbacks, IFilterReceiver
{
private const long MaxFileSizeInBytes = 1 * 1024 * 1024; // 1MB
private string _outputSummaryFilePath = null!;
Expand Down Expand Up @@ -62,22 +63,33 @@ public Task AfterRunAsync(int exitCode, CancellationToken cancellation)
{
return Task.CompletedTask;
}

var last = _updates.ToDictionary(x => x.Key, x => x.Value.Last());

var passedCount = last.Count(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is PassedTestNodeStateProperty));
var failed = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is FailedTestNodeStateProperty or ErrorTestNodeStateProperty)).ToArray();
var cancelled = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is CancelledTestNodeStateProperty)).ToArray();
var timeout = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is TimeoutTestNodeStateProperty)).ToArray();
var skipped = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is SkippedTestNodeStateProperty)).ToArray();
var inProgress = last.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is InProgressTestNodeStateProperty)).ToArray();

var passedCount = last.Count(x =>
x.Value.TestNode.Properties.AsEnumerable().Any(p => p is PassedTestNodeStateProperty));
var failed = last.Where(x =>
x.Value.TestNode.Properties.AsEnumerable()
.Any(p => p is FailedTestNodeStateProperty or ErrorTestNodeStateProperty)).ToArray();
var cancelled = last.Where(x =>
x.Value.TestNode.Properties.AsEnumerable().Any(p => p is CancelledTestNodeStateProperty)).ToArray();
var timeout = last
.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is TimeoutTestNodeStateProperty))
.ToArray();
var skipped = last
.Where(x => x.Value.TestNode.Properties.AsEnumerable().Any(p => p is SkippedTestNodeStateProperty))
.ToArray();
var inProgress = last.Where(x =>
x.Value.TestNode.Properties.AsEnumerable().Any(p => p is InProgressTestNodeStateProperty)).ToArray();

var stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"## {Assembly.GetEntryAssembly()?.GetName().Name}");

if (!string.IsNullOrEmpty(Filter))
{
stringBuilder.AppendLine($"### Filter: {Filter}");
}

stringBuilder.AppendLine();
stringBuilder.AppendLine("| Test Count | Status |");
stringBuilder.AppendLine("| --- | --- |");
Expand Down Expand Up @@ -220,11 +232,5 @@ private static string GetStatus(TestNodeStateProperty? stateProperty)
};
}

public ITestApplicationLifecycleCallbacks WithFilter(string? filter)
{
Filter = filter;
return this;
}

public string? Filter { get; set; }
}

0 comments on commit 1bef219

Please sign in to comment.