Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Library.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)strongname.snk</AssemblyOriginatorKeyFile>
<PublicKey>0024000004800000940000000602000000240000525341310004000001000100698a70398fa0b2230c5a72e3bd9d56b48f809f6173e49a19fbb942d621be93ad48c5566b47b28faabc359b9ad3ff4e00bbdea88f5bdfa250f391fedd28182b2e37b55d429c0151a42a98ea7a5821818cd15a79fef9903e8607a88304cf3e0317bf86ec96e32e1381535a6582251e5a6eed40b5a3ed82bc444598b1269cce57a7</PublicKey>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions TUnit.Core/Attributes/TestMetadata/ExcludeOnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace TUnit.Core;
/// }
///
/// // Skip on all supported platforms (essentially always skips the test)
/// [Test, ExcludeOn(OS.Windows | OS.Linux | OS.MacOs)]
/// [Test, ExcludeOn(OS.Windows | OS.Linux | OS.MacOs | OS.Browser)]
/// public void NeverRunTest()
/// {
/// // This test will not run on any supported platform
Expand All @@ -57,8 +57,9 @@ public override Task<bool> ShouldSkip(TestRegisteredContext context)
// Only validate Linux and macOS on .NET 5+ where these OS flags are available
|| (OperatingSystem.HasFlag(OS.Linux) && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|| (OperatingSystem.HasFlag(OS.MacOs) && RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|| (OperatingSystem.HasFlag(OS.Browser) && System.OperatingSystem.IsBrowser())
#endif
|| true;
;

// Return true if the test should be skipped (if we're on an excluded OS)
return Task.FromResult(shouldSkip);
Expand Down
8 changes: 7 additions & 1 deletion TUnit.Core/Attributes/TestMetadata/RunOnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace TUnit.Core;
/// }
///
/// // Run on all supported platforms
/// [Test, RunOn(OS.Windows | OS.Linux | OS.MacOs)]
/// [Test, RunOn(OS.Windows | OS.Linux | OS.MacOs | OS.Browser)]
/// public void AllPlatformsTest()
/// {
/// // This test will run on all supported platforms
Expand Down Expand Up @@ -64,6 +64,12 @@ public override Task<bool> ShouldSkip(TestRegisteredContext context)
{
return Task.FromResult(false);
}

// Check for Browser platform (WebAssembly)
if (OperatingSystem.HasFlag(OS.Browser) && System.OperatingSystem.IsBrowser())
{
return Task.FromResult(false);
}
#endif

return Task.FromResult(true);
Expand Down
20 changes: 18 additions & 2 deletions TUnit.Core/EngineCancellationToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ internal void Initialise(CancellationToken cancellationToken)
CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
Token = CancellationTokenSource.Token;

Console.CancelKeyPress += OnCancelKeyPress;
// Console.CancelKeyPress is not supported on browser platforms
#if NET5_0_OR_GREATER
if (!OperatingSystem.IsBrowser())
{
#endif
Console.CancelKeyPress += OnCancelKeyPress;
#if NET5_0_OR_GREATER
}
#endif
}

private void OnCancelKeyPress(object? sender, ConsoleCancelEventArgs e)
Expand Down Expand Up @@ -68,7 +76,15 @@ private void OnCancelKeyPress(object? sender, ConsoleCancelEventArgs e)
/// </summary>
public void Dispose()
{
Console.CancelKeyPress -= OnCancelKeyPress;
// Console.CancelKeyPress is not supported on browser platforms
#if NET5_0_OR_GREATER
if (!OperatingSystem.IsBrowser())
{
#endif
Console.CancelKeyPress -= OnCancelKeyPress;
#if NET5_0_OR_GREATER
}
#endif
_forcefulExitCts?.Cancel();
_forcefulExitCts?.Dispose();
CancellationTokenSource.Dispose();
Expand Down
12 changes: 10 additions & 2 deletions TUnit.Core/Enums/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// [RunOn(OS.Windows | OS.Linux)]
///
/// // Specify a test should run on all supported platforms
/// [RunOn(OS.Windows | OS.Linux | OS.MacOs)]
/// [RunOn(OS.Windows | OS.Linux | OS.MacOs | OS.Browser)]
/// </code>
/// </example>
/// <seealso cref="RunOnAttribute"/>
Expand Down Expand Up @@ -51,5 +51,13 @@ public enum OS
/// <remarks>
/// Tests with this flag will be executed on macOS platforms when used with <see cref="RunOnAttribute"/>.
/// </remarks>
MacOs = 4
MacOs = 4,

/// <summary>
/// Represents the Browser platform (WebAssembly).
/// </summary>
/// <remarks>
/// Tests with this flag will be executed on Browser platforms when used with <see cref="RunOnAttribute"/>.
/// </remarks>
Browser = 8
}
9 changes: 9 additions & 0 deletions TUnit.Core/Executors/DedicatedThreadExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ public class DedicatedThreadExecutor : GenericAbstractExecutor, ITestRegisteredE
{
protected sealed override async ValueTask ExecuteAsync(Func<ValueTask> action)
{
// On browser platforms, threading is not supported, so fall back to direct execution
#if NET5_0_OR_GREATER
if (OperatingSystem.IsBrowser())
{
await action();
return;
}
#endif

var tcs = new TaskCompletionSource<object?>();

var thread = new Thread(() =>
Expand Down
9 changes: 9 additions & 0 deletions TUnit.Engine/Logging/TUnitFrameworkLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ private static ConsoleColor GetConsoleColor(LogLevel logLevel)
return ConsoleColor.DarkRed;
}

// Console.ForegroundColor is not supported on browser platforms
#if NET5_0_OR_GREATER
if (!OperatingSystem.IsBrowser())
{
return Console.ForegroundColor;
}
return ConsoleColor.Gray; // Default color for browser platforms
#else
return Console.ForegroundColor;
#endif
}

public bool IsEnabled(LogLevel logLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ namespace .Enums
Linux = 1,
Windows = 2,
MacOs = 4,
Browser = 8,
}
public enum Priority
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ namespace .Enums
Linux = 1,
Windows = 2,
MacOs = 4,
Browser = 8,
}
public enum Priority
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,7 @@ namespace .Enums
Linux = 1,
Windows = 2,
MacOs = 4,
Browser = 8,
}
public enum Priority
{
Expand Down
Loading
Loading