diff --git a/src/OmniSharp.DotNetTest/TestManager.cs b/src/OmniSharp.DotNetTest/TestManager.cs index 5510bdf17d..6b1bdb1b18 100644 --- a/src/OmniSharp.DotNetTest/TestManager.cs +++ b/src/OmniSharp.DotNetTest/TestManager.cs @@ -200,6 +200,11 @@ private static int FindFreePort() } } + protected void EmitTestComletedEvent(DotNetTestResult result) + { + EventEmitter.Emit("TestCompleted", result); + } + protected void EmitTestMessage(TestMessageLevel messageLevel, string message) { EventEmitter.Emit(TestMessageEvent.Id, diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index cedef10bb9..ebb31b3e90 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -374,7 +374,8 @@ public override async Task RunTestAsync(string[] methodNames, s var testCases = await DiscoverTestsAsync(methodNames, runSettings, targetFrameworkVersion, cancellationToken); - var testResults = new List(); + var passed = true; + var results = new List(); if (testCases.Length > 0) { @@ -400,14 +401,26 @@ public override async Task RunTestAsync(string[] methodNames, s case MessageType.TestRunStatsChange: var testRunChange = message.DeserializePayload(); - testResults.AddRange(testRunChange.NewTestResults); + var newResults = ConvertResults(testRunChange.NewTestResults); + passed = passed && !testRunChange.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed); + results.AddRange(newResults); + foreach (var result in newResults) + { + EmitTestComletedEvent(result); + } break; case MessageType.ExecutionComplete: var payload = message.DeserializePayload(); if (payload.LastRunTests != null && payload.LastRunTests.NewTestResults != null) { - testResults.AddRange(payload.LastRunTests.NewTestResults); + var lastRunResults = ConvertResults(payload.LastRunTests.NewTestResults); + passed = passed && !payload.LastRunTests.NewTestResults.Any(o => o.Outcome == TestOutcome.Failed); + results.AddRange(lastRunResults); + foreach (var result in lastRunResults) + { + EmitTestComletedEvent(result); + } } done = true; break; @@ -415,28 +428,30 @@ public override async Task RunTestAsync(string[] methodNames, s } } - var results = testResults.Select(testResult => - new DotNetTestResult - { - MethodName = testResult.TestCase.FullyQualifiedName, - Outcome = testResult.Outcome.ToString().ToLowerInvariant(), - ErrorMessage = testResult.ErrorMessage, - ErrorStackTrace = testResult.ErrorStackTrace, - StandardOutput = testResult.Messages - .Where(message => message.Category == TestResultMessage.StandardOutCategory) - .Select(message => message.Text).ToArray(), - StandardError = testResult.Messages.Where(message => message.Category == TestResultMessage.StandardErrorCategory) - .Select(message => message.Text).ToArray() - }); - return new RunTestResponse { Results = results.ToArray(), - Pass = !testResults.Any(r => r.Outcome == TestOutcome.Failed), + Pass = passed, ContextHadNoTests = false }; } + private static IEnumerable ConvertResults(IEnumerable results) + { + return results.Select(testResult => new DotNetTestResult + { + MethodName = testResult.TestCase.FullyQualifiedName, + Outcome = testResult.Outcome.ToString().ToLowerInvariant(), + ErrorMessage = testResult.ErrorMessage, + ErrorStackTrace = testResult.ErrorStackTrace, + StandardOutput = testResult.Messages + .Where(message => message.Category == TestResultMessage.StandardOutCategory) + .Select(message => message.Text).ToArray(), + StandardError = testResult.Messages.Where(message => message.Category == TestResultMessage.StandardErrorCategory) + .Select(message => message.Text).ToArray() + }); + } + private async Task DiscoverTestsAsync(string[] methodNames, string runSettings, string targetFrameworkVersion, CancellationToken cancellationToken) { SendMessage(MessageType.StartDiscovery,