Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3e5bcda
Started implementing a DataCollector
GeorchW Jun 9, 2020
2aa35dc
Implement basic TCP server in the extension
GeorchW Jun 9, 2020
e8cfd4e
Tidying up executor, part 1
GeorchW Jun 9, 2020
429f945
Tidying up executor, part 2
GeorchW Jun 9, 2020
b58f8bd
Add code to set the server port for the subprocess
GeorchW Jun 9, 2020
5f277ad
Add publish dir to .gitignore
GeorchW Jun 9, 2020
edddb24
Add process env back in
GeorchW Jun 9, 2020
ce6b03f
Add data collector arguments to dotnet test
GeorchW Jun 9, 2020
b84e3a1
Send some slightly less nonsense data
GeorchW Jun 9, 2020
8b2fc4f
Send data as JSON
GeorchW Jun 9, 2020
4511b76
Make Executor.exec awaitable
GeorchW Jun 9, 2020
0d665bb
Make use of the received data
GeorchW Jun 9, 2020
a0db0fd
Use Logger instead of DataCollector API
GeorchW Jun 10, 2020
b4db6e3
Minor corrections
GeorchW Jun 10, 2020
560222f
Tidy up a little
GeorchW Jun 10, 2020
37353bc
Don't parse trx
GeorchW Jun 10, 2020
79527ef
Rename ITestResult => ITestResults
GeorchW Jun 10, 2020
3abb168
Fix event surface
GeorchW Jun 10, 2020
2bee683
Remove testResultsFile
GeorchW Jun 10, 2020
7062995
Clean up TestResult class
GeorchW Jun 10, 2020
3e7a541
Make an interface out of TestResult
GeorchW Jun 10, 2020
3a77b44
Use logger for test discovery
GeorchW Jun 10, 2020
d3e96f8
Remove unused usings
GeorchW Jun 11, 2020
50bfeee
Notify watcher of start/end of test run
GeorchW Jun 11, 2020
358bc47
Rework tree code
GeorchW Jun 11, 2020
8df96c9
Clean up subprocess logging
GeorchW Jun 11, 2020
acacf60
Spam less output
GeorchW Jun 11, 2020
c83800b
Apply old test results after discovery
GeorchW Jun 11, 2020
974ae83
Fix watch, remove tests that are not found
GeorchW Jun 11, 2020
8e96ffd
Fix gotoTest
GeorchW Jun 11, 2020
3d3df54
Log child process output by default
GeorchW Jun 11, 2020
044955c
Fix weird XUnit names
GeorchW Jun 11, 2020
d410eeb
Replace then with async/await
GeorchW Jun 11, 2020
5403938
Send messages asynchronously
GeorchW Jun 12, 2020
579e9d0
Rebuild tree when tests are removed
GeorchW Jun 12, 2020
09f7e83
Add proper names
GeorchW Jun 12, 2020
18effd7
Update language version
GeorchW Feb 26, 2022
f6fef75
Update packages
GeorchW Feb 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ npm-debug.log
yarn.*
[Bb]in/
[Oo]bj/
lcov.info
lcov.info
logger/publish/
87 changes: 87 additions & 0 deletions logger/VscodeLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Linq;
using System;
using System.Net.Sockets;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using System.Collections.Generic;

namespace VscodeTestExplorer.Logger;

[FriendlyName("VsCodeLogger")]
[ExtensionUri("this://is/a/random/path/that/vstest/apparently/expects/whatever/VscodeLogger")]
public class VsCodeLogger : ITestLoggerWithParameters
{
int port;
public void Initialize(TestLoggerEvents events, string testRunDirectory) { }
public void Initialize(TestLoggerEvents events, Dictionary<string, string> parameters)
{
Console.WriteLine(parameters.Count);
foreach (var kvp in parameters)
Console.WriteLine($"{kvp.Key}: {kvp.Value}");

port = int.Parse(parameters["port"]);
Console.WriteLine($"Data collector initialized; writing to port {port}.");

events.TestRunStart += (sender, e) => StartSendJson(new { type = "testRunStarted" });
events.TestRunComplete += (sender, e) =>
{
StartSendJson(new { type = "testRunComplete" });
Flush();
};

events.DiscoveredTests += (sender, e)
=> StartSendJson(new
{
type = "discovery",
discovered = e.DiscoveredTestCases.Select(GetFullName).ToArray()
});
events.DiscoveryComplete += (sender, e) => Flush();

events.TestResult += (sender, e) => StartSendJson(new
{
type = "result",
fullName = GetFullName(e.Result.TestCase),
outcome = e.Result.Outcome.ToString(),
message = e.Result.ErrorMessage,
stackTrace = e.Result.ErrorStackTrace,
});
}

static string GetFullName(TestCase testCase)
=> testCase.GetProperties().Any(kvp => kvp.Key.Id == "XunitTestCase") ?
testCase.DisplayName : testCase.FullyQualifiedName;

async Task SendString(string str)
{
// Console.WriteLine("Sending: " + str);

using TcpClient client = new TcpClient();
await client.ConnectAsync("localhost", port);
await client.GetStream().WriteAsync(Encoding.UTF8.GetBytes(str));
}

List<Task> tasks = new List<Task>();
void StartSendJson<T>(T obj)
{
var task = SendString(JsonSerializer.Serialize(obj));
lock (tasks)
{
tasks.Add(task);
}
}

void Flush()
{
Task[] _tasks;
lock (tasks)
{
_tasks = tasks.ToArray();
tasks.Clear();
}
Task.WaitAll(_tasks);
}
}
12 changes: 12 additions & 0 deletions logger/VscodeTestExplorer.testlogger.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="16.6.1" />
</ItemGroup>

</Project>
Loading