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 internal static class ConsoleExtensions
{ {
public static IAnsiConsole CreateAnsiConsole(this IConsole console) => AnsiConsole.Create( private class NoopExclusivityMode : IExclusivityMode
new AnsiConsoleSettings {
{ public T Run<T>(Func<T> func) => func();
Ansi = AnsiSupport.Detect,
ColorSystem = ColorSystemSupport.Detect, public Task<T> Run<T>(Func<Task<T>> func) => func();
Out = new AnsiConsoleOutput(console.Output) }
}
); 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 public static Progress CreateProgressTicker(this IConsole console) => console
.CreateAnsiConsole() .CreateAnsiConsole()

Loading…
Cancel
Save