Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Microsoft.Testing.Platform.OutputDevice.Terminal.TerminalProgressMessageState.Te
Microsoft.Testing.Platform.OutputDevice.Terminal.TerminalProgressMessageState.Version.get -> long
Microsoft.Testing.Platform.OutputDevice.Terminal.TerminalTestReporter.UpdateProgressMessage(string! executionId, string! instanceId, string! producerUid, string! key, string? message) -> void
Microsoft.Testing.Platform.OutputDevice.Terminal.TerminalTestReporter.ClearProgressMessages() -> void
virtual Microsoft.Testing.Platform.OutputDevice.SimplifiedConsoleOutputDeviceBase.DisplayActiveTestProgress.get -> bool
static Microsoft.Testing.Platform.OutputDevice.Terminal.TerminalTestReporterCommandLineOptionsProvider.IsProgressEnabled(Microsoft.Testing.Platform.CommandLine.ICommandLineOptions! commandLineOptions) -> bool
const Microsoft.Testing.Platform.OutputDevice.Terminal.TestProgressStateAwareTerminal.MaximumVisibleProgressMessages = 5 -> int
Microsoft.Testing.Platform.OutputDevice.Terminal.TestProgressStateAwareTerminal.UpdateProgressMessage(string! executionId, string! instanceId, string! producerUid, string! key, string? message) -> void
Microsoft.Testing.Platform.OutputDevice.Terminal.TestProgressStateAwareTerminal.ClearProgressMessages() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;

using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.OutputDevice.Terminal;
using Microsoft.Testing.Platform.Services;

namespace Microsoft.Testing.Platform.OutputDevice;
Expand All @@ -15,16 +17,20 @@ namespace Microsoft.Testing.Platform.OutputDevice;
[SupportedOSPlatform("browser")]
internal sealed partial class BrowserOutputDevice : SimplifiedConsoleOutputDeviceBase
{
private readonly bool _displayActiveTestProgress;

public BrowserOutputDevice(
IConsole console,
ITestApplicationModuleInfo testApplicationModuleInfo,
IAsyncMonitor asyncMonitor,
IRuntimeFeature runtimeFeature,
IEnvironment environment,
IPlatformInformation platformInformation,
ICommandLineOptions commandLineOptions,
Comment thread
Evangelink marked this conversation as resolved.
Resolved
IStopPoliciesService policiesService)
: base(console, testApplicationModuleInfo, asyncMonitor, runtimeFeature, environment, platformInformation, policiesService)
{
_displayActiveTestProgress = IsProgressEnabled(commandLineOptions);
}

/// <inheritdoc />
Expand All @@ -33,6 +39,8 @@ public BrowserOutputDevice(
/// <inheritdoc />
public override string Description => "Test Platform browser console service using JavaScript interop";

protected override bool DisplayActiveTestProgress => _displayActiveTestProgress;

[JSImport("globalThis.console.warn")]
private static partial void JSConsoleWarn(string? message);

Expand All @@ -47,6 +55,9 @@ public BrowserOutputDevice(
protected override void ConsoleError(string? message) => JSConsoleError(message);

protected override void ConsoleLog(string? message) => JSConsoleLog(message);

private static bool IsProgressEnabled(ICommandLineOptions commandLineOptions)
=> TerminalTestReporterCommandLineOptionsProvider.IsProgressEnabled(commandLineOptions);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static IPlatformOutputDevice GetDefaultTerminalOutputDevice(ServiceProvid
serviceProvider.GetRuntimeFeature(),
serviceProvider.GetEnvironment(),
serviceProvider.GetPlatformInformation(),
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetRequiredService<IStopPoliciesService>());
#else
throw new PlatformNotSupportedException(PlatformResources.BrowserPlatformNotSupportedOnOlderFrameworks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public async Task InitializeAsync()

protected abstract void ConsoleLog(string? message);

protected virtual bool DisplayActiveTestProgress => false;

public async Task DisplayBannerAsync(string? bannerMessage, CancellationToken cancellationToken)
{
using (await _asyncMonitor.LockAsync(TimeoutHelper.DefaultHangTimeSpanTimeout).ConfigureAwait(false))
Expand Down Expand Up @@ -342,39 +344,64 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo
}

TimeSpan? duration = timingProp?.GlobalTiming.Duration;
bool testCompleted = false;

switch (nodeStateProp)
{
case InProgressTestNodeStateProperty:
if (DisplayActiveTestProgress)
{
return DisplayAsync(
this,
new ProgressMessageOutputDeviceData(
testNodeStateChanged.TestNode.Uid.Value,
$"running {testNodeStateChanged.TestNode.DisplayName}"),
cancellationToken);
}

break;

case ErrorTestNodeStateProperty errorState:
OnFailedTest(testNodeStateChanged, errorState, errorState.Exception, duration);
testCompleted = true;
break;

case FailedTestNodeStateProperty failedState:
OnFailedTest(testNodeStateChanged, failedState, failedState.Exception, duration);
testCompleted = true;
break;

case TimeoutTestNodeStateProperty timeoutState:
OnFailedTest(testNodeStateChanged, timeoutState, timeoutState.Exception, duration);
testCompleted = true;
break;

#pragma warning disable CS0618, MTP0001 // Type or member is obsolete
case CancelledTestNodeStateProperty cancelledState:
#pragma warning restore CS0618, MTP0001 // Type or member is obsolete
OnFailedTest(testNodeStateChanged, cancelledState, cancelledState.Exception, duration);
testCompleted = true;
break;

case PassedTestNodeStateProperty:
_passedTests++;
testCompleted = true;
break;

case SkippedTestNodeStateProperty:
_skippedTests++;
testCompleted = true;
break;
}

if (testCompleted && DisplayActiveTestProgress)
{
return DisplayAsync(
this,
new ProgressMessageOutputDeviceData(testNodeStateChanged.TestNode.Uid.Value, message: null),
cancellationToken);
}

// Tracked by https://github.com/microsoft/testfx/issues/8086:
// surface per-test file artifacts in the simplified console output once the format is defined.
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineO
_ => throw ApplicationStateGuard.Unreachable(),
};

internal static bool IsProgressEnabled(ICommandLineOptions commandLineOptions)
=> commandLineOptions.TryGetOptionArgumentList(ProgressOption, out string[]? arguments)
&& arguments is { Length: > 0 }
? !CommandLineOptionArgumentValidator.IsOffValue(arguments[0])
: !commandLineOptions.IsOptionSet(NoProgressOption);

private static bool IsValidShowOutputArgument(string argument)
=> ShowOutputAllArgument.Equals(argument, StringComparison.OrdinalIgnoreCase)
|| ShowOutputFailedArgument.Equals(argument, StringComparison.OrdinalIgnoreCase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,18 @@ await _policiesService.RegisterOnAbortCallbackAsync(
// --progress <auto|on|off> is the modern, positive form. When present it wins over the legacy
// --no-progress flag. --no-progress keeps working as a deprecated alias for --progress off and
// emits a single deprecation warning per process.
bool noProgress;
if (_commandLineOptions.TryGetOptionArgumentList(TerminalTestReporterCommandLineOptionsProvider.ProgressOption, out string[]? progressArguments)
&& progressArguments is { Length: > 0 })
bool progressOptionSet = _commandLineOptions.TryGetOptionArgumentList(
TerminalTestReporterCommandLineOptionsProvider.ProgressOption,
out string[]? progressArguments)
&& progressArguments is { Length: > 0 };

// 'on' and 'auto' currently behave the same: progress is shown unless the terminal is not capable
// of in-place updates (NoAnsi/SimpleAnsi) or we are a test-host controller, --list-tests, or server
// mode. A dedicated heartbeat renderer for the non-cursor modes is tracked by #9125.
bool noProgress = !TerminalTestReporterCommandLineOptionsProvider.IsProgressEnabled(_commandLineOptions);
if (!progressOptionSet
&& _commandLineOptions.IsOptionSet(TerminalTestReporterCommandLineOptionsProvider.NoProgressOption))
{
// 'on' and 'auto' currently behave the same: progress is shown unless the terminal is not capable
// of in-place updates (NoAnsi/SimpleAnsi) or we are a test-host controller, --list-tests, or server
// mode. A dedicated heartbeat renderer for the non-cursor modes is tracked by #9125.
noProgress = CommandLineOptionArgumentValidator.IsOffValue(progressArguments[0]);
}
else if (_commandLineOptions.IsOptionSet(TerminalTestReporterCommandLineOptionsProvider.NoProgressOption))
{
noProgress = true;

// The deprecation warning is a nudge for interactive users to move to --progress off. We deliberately
// do not emit it in CI: it is invisible noise there, and build infrastructure (e.g. the Arcade SDK test
// runner) passes --no-progress unconditionally, so emitting to stderr would surface as a build error in
Expand All @@ -124,10 +123,6 @@ await _policiesService.RegisterOnAbortCallbackAsync(
await WriteToStandardErrorAsync(PlatformResources.TerminalNoProgressDeprecatedWarning).ConfigureAwait(false);
}
}
else
{
noProgress = false;
}

// _runtimeFeature.IsHotReloadEnabled is not set to true here, even if the session will be HotReload,
// we need to postpone that decision until the first test result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ public async Task BrowserWasmExecution_RunsTestsUnderNode()
combined.Contains("failed: 1", StringComparison.Ordinal),
$"Expected 1 failed test in the browser-wasm run summary.{Environment.NewLine}{combined}");

foreach (string testName in new[] { "PassingTest", "AnotherPassingTest", "FailingTest" })
{
Assert.IsTrue(
combined.Contains($"running {testName}", StringComparison.Ordinal),
$"Expected browser-wasm progress output to identify '{testName}' before it ran.{Environment.NewLine}{combined}");
}

// Assert the exact "at least one test failed" exit code (2). A generic non-zero check would
// also pass for a post-run crash or other MTP failure; requiring AtLeastOneTestFailed keeps
// those from masquerading as the expected failing-test outcome.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,70 @@ public async Task DisplayAsync_ProgressMessageAfterSessionFinishes_WritesSameVal
Assert.AreSequenceEqual(new[] { "Restoring", "Restoring" }, device.Messages);
}

private static RecordingSimplifiedOutputDevice CreateOutputDevice(IAsyncMonitor asyncMonitor)
[TestMethod]
public async Task ConsumeAsync_InProgressTestNode_WhenActiveTestProgressEnabled_WritesActiveTestDisplayNameOnce()
{
using var asyncMonitor = new SystemAsyncMonitor();
RecordingSimplifiedOutputDevice device = CreateOutputDevice(asyncMonitor, displayActiveTestProgress: true);
TestNodeUpdateMessage update = CreateTestNodeUpdate(InProgressTestNodeStateProperty.CachedInstance);

await device.ConsumeAsync(null!, update, CancellationToken.None);
await device.ConsumeAsync(null!, update, CancellationToken.None);

Assert.AreSequenceEqual(new[] { "running BrowserTests.HangingTest" }, device.Messages);
}

[TestMethod]
public async Task ConsumeAsync_InProgressTestNode_WhenActiveTestProgressDisabled_DoesNotWrite()
{
using var asyncMonitor = new SystemAsyncMonitor();
RecordingSimplifiedOutputDevice device = CreateOutputDevice(asyncMonitor);

await device.ConsumeAsync(
null!,
CreateTestNodeUpdate(InProgressTestNodeStateProperty.CachedInstance),
CancellationToken.None);

Assert.IsEmpty(device.Messages);
}

[TestMethod]
public async Task ConsumeAsync_CompletedTestNode_AllowsSameTestToReportProgressAgain()
{
using var asyncMonitor = new SystemAsyncMonitor();
RecordingSimplifiedOutputDevice device = CreateOutputDevice(asyncMonitor, displayActiveTestProgress: true);

await device.ConsumeAsync(
null!,
CreateTestNodeUpdate(InProgressTestNodeStateProperty.CachedInstance),
CancellationToken.None);
await device.ConsumeAsync(
null!,
CreateTestNodeUpdate(PassedTestNodeStateProperty.CachedInstance),
CancellationToken.None);
await device.ConsumeAsync(
null!,
CreateTestNodeUpdate(InProgressTestNodeStateProperty.CachedInstance),
CancellationToken.None);

Assert.AreSequenceEqual(
new[] { "running BrowserTests.HangingTest", "running BrowserTests.HangingTest" },
device.Messages);
}

private static TestNodeUpdateMessage CreateTestNodeUpdate(TestNodeStateProperty state)
=> new(
default,
new TestNode
{
Uid = "hanging-test",
DisplayName = "BrowserTests.HangingTest",
Properties = new PropertyBag(state),
});

private static RecordingSimplifiedOutputDevice CreateOutputDevice(
IAsyncMonitor asyncMonitor,
bool displayActiveTestProgress = false)
{
var moduleInfo = new Mock<ITestApplicationModuleInfo>();
moduleInfo.Setup(x => x.GetDisplayName()).Returns("testhost");
Expand All @@ -81,21 +144,26 @@ private static RecordingSimplifiedOutputDevice CreateOutputDevice(IAsyncMonitor
Mock.Of<IRuntimeFeature>(),
Mock.Of<IEnvironment>(),
Mock.Of<IPlatformInformation>(),
Mock.Of<IStopPoliciesService>());
Mock.Of<IStopPoliciesService>(),
displayActiveTestProgress);
}

private sealed class RecordingSimplifiedOutputDevice : SimplifiedConsoleOutputDeviceBase
{
private readonly bool _displayActiveTestProgress;

public RecordingSimplifiedOutputDevice(
IConsole console,
ITestApplicationModuleInfo testApplicationModuleInfo,
IAsyncMonitor asyncMonitor,
IRuntimeFeature runtimeFeature,
IEnvironment environment,
IPlatformInformation platformInformation,
IStopPoliciesService policiesService)
IStopPoliciesService policiesService,
bool displayActiveTestProgress)
: base(console, testApplicationModuleInfo, asyncMonitor, runtimeFeature, environment, platformInformation, policiesService)
{
_displayActiveTestProgress = displayActiveTestProgress;
}

public List<string?> Messages { get; } = [];
Expand All @@ -104,6 +172,8 @@ public RecordingSimplifiedOutputDevice(

public override string Description => nameof(RecordingSimplifiedOutputDevice);

protected override bool DisplayActiveTestProgress => _displayActiveTestProgress;

protected override void ConsoleWarn(string? message) => Messages.Add(message);

protected override void ConsoleError(string? message) => Messages.Add(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,51 @@ public void GetCommandLineOptions_StillIncludesNoProgressOption()
Assert.IsTrue(option.IsBuiltIn);
}

[TestMethod]
[DataRow("auto", true)]
[DataRow("on", true)]
[DataRow("off", false)]
public void IsProgressEnabled_ProgressOption_ReturnsRequestedState(string argument, bool expected)
{
var options = new Helpers.TestCommandLineOptions(new Dictionary<string, string[]>
{
[TerminalTestReporterCommandLineOptionsProvider.ProgressOption] = [argument],
});

Assert.AreEqual(expected, TerminalTestReporterCommandLineOptionsProvider.IsProgressEnabled(options));
}

[TestMethod]
public void IsProgressEnabled_NoProgressOption_ReturnsFalse()
{
var options = new Helpers.TestCommandLineOptions(new Dictionary<string, string[]>
{
[TerminalTestReporterCommandLineOptionsProvider.NoProgressOption] = [],
});

Assert.IsFalse(TerminalTestReporterCommandLineOptionsProvider.IsProgressEnabled(options));
}

[TestMethod]
public void IsProgressEnabled_NoProgressOptions_ReturnsTrue()
{
var options = new Helpers.TestCommandLineOptions([]);

Assert.IsTrue(TerminalTestReporterCommandLineOptionsProvider.IsProgressEnabled(options));
}

[TestMethod]
public void IsProgressEnabled_ProgressOption_TakesPrecedenceOverNoProgressOption()
{
var options = new Helpers.TestCommandLineOptions(new Dictionary<string, string[]>
{
[TerminalTestReporterCommandLineOptionsProvider.ProgressOption] = ["on"],
[TerminalTestReporterCommandLineOptionsProvider.NoProgressOption] = [],
});

Assert.IsTrue(TerminalTestReporterCommandLineOptionsProvider.IsProgressEnabled(options));
}

[TestMethod]
[DataRow("1")]
[DataRow("5")]
Expand Down
Loading