Skip to content
Open
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
30 changes: 30 additions & 0 deletions .generated.NoMobile.sln
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Extensions.AI.Tests"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly.Tests", "test\Sentry.AspNetCore.Blazor.WebAssembly.Tests\Sentry.AspNetCore.Blazor.WebAssembly.Tests.csproj", "{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp", "test\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp.csproj", "{010F29C9-EF49-436B-811E-832195330364}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests", "test\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.csproj", "{CC357377-2429-4ED0-95E2-A8604B722514}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1372,6 +1376,30 @@ Global
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}.Release|x64.Build.0 = Release|Any CPU
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}.Release|x86.ActiveCfg = Release|Any CPU
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}.Release|x86.Build.0 = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|Any CPU.Build.0 = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x64.ActiveCfg = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x64.Build.0 = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x86.ActiveCfg = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x86.Build.0 = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|Any CPU.ActiveCfg = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|Any CPU.Build.0 = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x64.ActiveCfg = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x64.Build.0 = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x86.ActiveCfg = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x86.Build.0 = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x64.ActiveCfg = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x64.Build.0 = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x86.ActiveCfg = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x86.Build.0 = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|Any CPU.Build.0 = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x64.ActiveCfg = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x64.Build.0 = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x86.ActiveCfg = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1473,5 +1501,7 @@ Global
{AE461926-00B8-4FDD-A41D-3C83C2D9A045} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
{28D6E004-DC64-464F-91BE-BC0B3A8E543F} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{010F29C9-EF49-436B-811E-832195330364} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{CC357377-2429-4ED0-95E2-A8604B722514} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
EndGlobalSection
EndGlobal
30 changes: 30 additions & 0 deletions Sentry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Extensions.AI.Tests"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly.Tests", "test\Sentry.AspNetCore.Blazor.WebAssembly.Tests\Sentry.AspNetCore.Blazor.WebAssembly.Tests.csproj", "{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp", "test\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp.csproj", "{010F29C9-EF49-436B-811E-832195330364}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests", "test\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.csproj", "{CC357377-2429-4ED0-95E2-A8604B722514}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1372,6 +1376,30 @@ Global
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}.Release|x64.Build.0 = Release|Any CPU
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}.Release|x86.ActiveCfg = Release|Any CPU
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA}.Release|x86.Build.0 = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|Any CPU.Build.0 = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x64.ActiveCfg = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x64.Build.0 = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x86.ActiveCfg = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Debug|x86.Build.0 = Debug|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|Any CPU.ActiveCfg = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|Any CPU.Build.0 = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x64.ActiveCfg = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x64.Build.0 = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x86.ActiveCfg = Release|Any CPU
{010F29C9-EF49-436B-811E-832195330364}.Release|x86.Build.0 = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x64.ActiveCfg = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x64.Build.0 = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x86.ActiveCfg = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Debug|x86.Build.0 = Debug|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|Any CPU.Build.0 = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x64.ActiveCfg = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x64.Build.0 = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x86.ActiveCfg = Release|Any CPU
{CC357377-2429-4ED0-95E2-A8604B722514}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1473,5 +1501,7 @@ Global
{AE461926-00B8-4FDD-A41D-3C83C2D9A045} = {230B9384-90FD-4551-A5DE-1A5C197F25B6}
{28D6E004-DC64-464F-91BE-BC0B3A8E543F} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{705223D7-FEE3-485B-8DFB-3F9B29DAC6CA} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{010F29C9-EF49-436B-811E-832195330364} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
{CC357377-2429-4ED0-95E2-A8604B722514} = {6987A1CC-608E-4868-A02C-09D30C8B7B2D}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions SentryAspNetCore.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"src\\Sentry.Serilog\\Sentry.Serilog.csproj",
"src\\Sentry\\Sentry.csproj",
"test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj",
"test\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp.csproj",
"test\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.csproj",
"test\\Sentry.AspNetCore.Blazor.WebAssembly.Tests\\Sentry.AspNetCore.Blazor.WebAssembly.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
2 changes: 2 additions & 0 deletions SentryNoMobile.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"src\\Sentry\\Sentry.csproj",
"test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj",
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
"test\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp.csproj",
"test\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.csproj",
"test\\Sentry.AspNetCore.Blazor.WebAssembly.Tests\\Sentry.AspNetCore.Blazor.WebAssembly.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
1 change: 1 addition & 0 deletions SentryNoSamples.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj",
"test\\Sentry.Android.AssemblyReader.Tests\\Sentry.Android.AssemblyReader.Tests.csproj",
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
"test\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests\\Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.csproj",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestApp project missing from SentryNoSamples solution filter

Low Severity

The SentryNoSamples.slnf filter includes the PlaywrightTests project but omits its build dependency PlaywrightTests.TestApp. Both SentryAspNetCore.slnf and SentryNoMobile.slnf correctly include both projects. This inconsistency means the TestApp won't be visible when opening this solution filter in the IDE, despite being a ProjectReference dependency of the included test project.

Additional Locations (2)

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By design — SentryNoSamples.slnf excludes **/*TestApp* which catches the TestApp project. MSBuild still resolves it as a ProjectReference dependency of the PlaywrightTests project, so builds work correctly. The filter just controls what's visible in the IDE.

"test\\Sentry.AspNetCore.Blazor.WebAssembly.Tests\\Sentry.AspNetCore.Blazor.WebAssembly.Tests.csproj",
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
Expand Down
7 changes: 7 additions & 0 deletions scripts/generate-solution-filters-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ groupConfigs:
trimTests:
- "**/Sentry.TrimTest.csproj"
- "**/Sentry.MauiTrimTest.csproj"
playwrightTests:
- "**/*PlaywrightTests*.csproj"
mobileOnly:
- "**/*Android*.csproj"
- "**/*Ios*.csproj"
Expand All @@ -50,6 +52,7 @@ filterConfigs:
- "windowsOnly"
- "artefacts"
- "trimTests"
- "playwrightTests"
patterns:
- "**/*AndroidTestApp.csproj"
- "**/*DeviceTests*.csproj"
Expand All @@ -67,6 +70,7 @@ filterConfigs:
- "artefacts"
- "trimTests"
- "mobileOnly"
- "playwrightTests"
patterns:
- "**/*Android*.csproj"
- "**/*DeviceTests*.csproj"
Expand All @@ -83,6 +87,7 @@ filterConfigs:
groups:
- "artefacts"
- "trimTests"
- "playwrightTests"
patterns:
- "**/*AndroidTestApp.csproj"
- "**/*DeviceTests*.csproj"
Expand All @@ -100,6 +105,7 @@ filterConfigs:
- "macOnly"
- "artefacts"
- "trimTests"
- "playwrightTests"
patterns:
- "**/*AndroidTestApp.csproj"
# AssemblyReader tests are flaky on Windows: https://github.com/getsentry/sentry-dotnet/issues/4091
Expand All @@ -121,6 +127,7 @@ filterConfigs:
- "macOnly"
- "artefacts"
- "trimTests"
- "playwrightTests"
patterns:
- "**/*AndroidTestApp.csproj"
# AssemblyReader tests are flaky on Windows: https://github.com/getsentry/sentry-dotnet/issues/4091
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Shared.MainLayout)" />
</Found>
<NotFound>
<p>Not found</p>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page "/"

<h1 id="page-title">Home</h1>
<a href="second" id="nav-second">Go to Second</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page "/second"

<h1 id="page-title">Second Page</h1>
<a href="trigger-capture" id="nav-trigger">Go to Trigger</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@page "/trigger-capture"

<h1 id="page-title">Trigger Capture</h1>
<button id="btn-capture" @onclick="Capture">Capture Message</button>

@code {
private void Capture()
{
SentrySdk.CaptureMessage("playwright-test");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.UseSentry(options =>
{
// Fake DSN — Playwright intercepts requests before they reach the network
options.Dsn = "https://key@o0.ingest.sentry.io/0";
options.AutoSessionTracking = false;
});

builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsTestProject>false</IsTestProject>
<IsPackable>false</IsPackable>
</PropertyGroup>

<!-- Remove test-only global usings inherited from test/Directory.Build.props -->
<ItemGroup>
<Using Remove="Sentry.DsnSamples" />
<Using Remove="Sentry.Testing" />
<Using Remove="Sentry.Protocol" />
<Using Remove="FluentAssertions" />
<Using Remove="FluentAssertions.Execution" />
<Using Remove="NSubstitute" />
<Using Remove="NSubstitute.Core" />
<Using Remove="NSubstitute.ExceptionExtensions" />
<Using Remove="NSubstitute.ReturnsExtensions" />
<Using Remove="Xunit" />
<Using Remove="Xunit.Abstractions" />
<Using Remove="VerifyXunit" />
</ItemGroup>
Comment on lines +11 to +25
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TestApp project sits under test/ and will inherit test/Directory.Build.props package references (e.g., xUnit/NSubstitute/FluentAssertions). Removing the global Usings avoids compile issues, but the unnecessary package references are still restored and can bloat the WASM app / slow builds. Consider also removing those inherited PackageReferences here (or making the test-only package references in test/Directory.Build.props conditional on $(IsTestProject) so non-test host apps don’t pick them up).

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already handled — the Using Remove entries in the csproj strip the test-specific global usings. The inherited package references (xUnit, NSubstitute, etc.) are harmless since the TestApp doesn't reference them in code.


<!-- Exclude test SDK auto-generated entry point -->
<PropertyGroup>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0" PrivateAssets="all" />
<ProjectReference Include="..\..\src\Sentry.AspNetCore.Blazor.WebAssembly\Sentry.AspNetCore.Blazor.WebAssembly.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@inherits LayoutComponentBase

<main>
@Body
</main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp
@using Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp.Shared
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Playwright Test App</title>
<base href="/" />
</head>

<body>
<div id="app">Loading...</div>
<script src="_framework/blazor.webassembly.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;

namespace Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests;

internal sealed class BlazorWasmTestApp : IAsyncDisposable
{
private Process? _process;
private readonly ConcurrentQueue<string> _output = new();

public string BaseUrl { get; private set; } = null!;

public async Task StartAsync()
{
var port = GetFreePort();
BaseUrl = $"http://localhost:{port}";

var projectPath = Path.GetFullPath(
Path.Combine(AppContext.BaseDirectory,
"..", "..", "..", "..",
"Sentry.AspNetCore.Blazor.WebAssembly.PlaywrightTests.TestApp"));

_process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project \"{projectPath}\" --urls {BaseUrl}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
}
};
_process.OutputDataReceived += (_, e) => { if (e.Data != null) _output.Enqueue($"[stdout] {e.Data}"); };
_process.ErrorDataReceived += (_, e) => { if (e.Data != null) _output.Enqueue($"[stderr] {e.Data}"); };
_process.Start();
_process.BeginOutputReadLine();
_process.BeginErrorReadLine();

using var http = new HttpClient();
var timeout = TimeSpan.FromSeconds(180);
var sw = Stopwatch.StartNew();
while (sw.Elapsed < timeout)
{
if (_process.HasExited)
{
var logs = string.Join(Environment.NewLine, _output);
throw new InvalidOperationException(
$"Blazor WASM test app exited with code {_process.ExitCode} before becoming ready. Output:{Environment.NewLine}{logs}");
}

try
{
var response = await http.GetAsync(BaseUrl);
if (response.IsSuccessStatusCode)
{
return;
}
}
catch
{
// Server not ready yet
}
await Task.Delay(500);
}

var timeoutLogs = string.Join(Environment.NewLine, _output);
throw new TimeoutException(
$"Blazor WASM test app did not start within {(int)timeout.TotalSeconds}s at {BaseUrl}. Output:{Environment.NewLine}{timeoutLogs}");
}

private static int GetFreePort()
{
using var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
listener.Stop();
return port;
}

public async ValueTask DisposeAsync()
{
if (_process is { HasExited: false })
{
_process.Kill(entireProcessTree: true);
await _process.WaitForExitAsync();
}
_process?.Dispose();
}
}
Loading
Loading