Workaround for Spectre parallelization issue in tests

pull/678/head
Tyrrrz 3 years ago
parent ec0494c038
commit 28de1053f6

@ -7,14 +7,31 @@ namespace DiscordChatExporter.Cli.Utils.Extensions
{
internal static class ConsoleExtensions
{
public static IAnsiConsole CreateAnsiConsole(this IConsole console) => AnsiConsole.Create(
new AnsiConsoleSettings
{
Ansi = AnsiSupport.Detect,
ColorSystem = ColorSystemSupport.Detect,
Out = new AnsiConsoleOutput(console.Output)
}
);
private class NoopExclusivityMode : IExclusivityMode
{
public T Run<T>(Func<T> func) => func();
public Task<T> Run<T>(Func<Task<T>> func) => func();
}
public static IAnsiConsole CreateAnsiConsole(this IConsole console)
{
// Don't require exclusivity in tests.
// Workaround for: https://github.com/spectreconsole/spectre.console/issues/494
var exclusivityMode = console is FakeConsole
? new NoopExclusivityMode()
: null;
return AnsiConsole.Create(
new AnsiConsoleSettings
{
Ansi = AnsiSupport.Detect,
ColorSystem = ColorSystemSupport.Detect,
Out = new AnsiConsoleOutput(console.Output),
ExclusivityMode = exclusivityMode
}
);
}
public static Progress CreateProgressTicker(this IConsole console) => console
.CreateAnsiConsole()

Loading…
Cancel
Save