Skip to content

Commit 582e522

Browse files
authored
[wasm] Disable running blazor template projects (#79536)
* [wasm] Print browser console messages to the test output to catch blazor issues * WBT: Remove unused AppRefDir arguments * Re-enable the tests without the blazor-run parts * fix build
1 parent c1d6dd3 commit 582e522

File tree

7 files changed

+19
-23
lines changed

7 files changed

+19
-23
lines changed

src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public void DefaultTemplate_NoAOT_WithWorkload(string config)
8484
[Theory]
8585
[InlineData("Debug")]
8686
[InlineData("Release")]
87-
[ActiveIssue("https://github.com/dotnet/runtime/issues/79514")]
88-
public async Task WithDllImportInMainAssembly(string config)
87+
public void WithDllImportInMainAssembly(string config)
8988
{
9089
// Based on https://github.com/dotnet/runtime/issues/59255
9190
string id = $"blz_dllimp_{config}";
@@ -125,11 +124,12 @@ public static class MyDllImports
125124
BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked));
126125
CheckNativeFileLinked(forPublish: true);
127126

128-
await BlazorRun(config, async (page) => {
129-
await page.Locator("text=\"cpp_add\"").ClickAsync();
130-
var txt = await page.Locator("p[role='test']").InnerHTMLAsync();
131-
Assert.Equal("Output: 22", txt);
132-
});
127+
// [ActiveIssue("https://github.com/dotnet/runtime/issues/79514")]
128+
//await BlazorRun(config, async (page) => {
129+
//await page.Locator("text=\"cpp_add\"").ClickAsync();
130+
//var txt = await page.Locator("p[role='test']").InnerHTMLAsync();
131+
//Assert.Equal("Output: 22", txt);
132+
//});
133133

134134
void CheckNativeFileLinked(bool forPublish)
135135
{

src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal class BrowserRunner : IAsyncDisposable
3535
public BrowserRunner(ITestOutputHelper testOutput) => _testOutput = testOutput;
3636

3737
// FIXME: options
38-
public async Task<IPage> RunAsync(ToolCommand cmd, string args, bool headless = true)
38+
public async Task<IPage> RunAsync(ToolCommand cmd, string args, bool headless = true, Action<IConsoleMessage>? onConsoleMessage = null)
3939
{
4040
TaskCompletionSource<string> urlAvailable = new();
4141
Action<string?> outputHandler = msg =>
@@ -90,6 +90,8 @@ public async Task<IPage> RunAsync(ToolCommand cmd, string args, bool headless =
9090
});
9191

9292
IPage page = await Browser.NewPageAsync();
93+
if (onConsoleMessage is not null)
94+
page.Console += (_, msg) => onConsoleMessage(msg);
9395
await page.GotoAsync(urlAvailable.Task.Result);
9496
RunTask = runTask;
9597
return page;

src/mono/wasm/Wasm.Build.Tests/BuildEnvironment.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,18 @@ public BuildEnvironment()
7070
s_runtimePackVersions[$"net{verStr}.0"] = versionValue;
7171
}
7272

73+
DefaultBuildArgs = string.Empty;
7374
WorkloadPacksDir = Path.Combine(sdkForWorkloadPath, "packs");
7475
EnvVars = new Dictionary<string, string>();
7576
bool workloadInstalled = EnvironmentVariables.SdkHasWorkloadInstalled != null && EnvironmentVariables.SdkHasWorkloadInstalled == "true";
7677
if (workloadInstalled)
7778
{
7879
DirectoryBuildPropsContents = s_directoryBuildPropsForWorkloads;
7980
DirectoryBuildTargetsContents = s_directoryBuildTargetsForWorkloads;
80-
81-
var appRefDir = EnvironmentVariables.AppRefDir;
82-
if (string.IsNullOrEmpty(appRefDir))
83-
throw new Exception($"Cannot test with workloads without AppRefDir environment variable being set");
84-
85-
DefaultBuildArgs = $" /p:AppRefDir={appRefDir}";
8681
IsWorkload = true;
8782
}
8883
else
8984
{
90-
var appRefDir = EnvironmentVariables.AppRefDir;
91-
if (string.IsNullOrEmpty(appRefDir))
92-
throw new Exception($"Cannot test with workloads without AppRefDir environment variable being set");
93-
94-
DefaultBuildArgs = $" /p:AppRefDir={appRefDir}";
9585
DirectoryBuildPropsContents = s_directoryBuildPropsForLocal;
9686
DirectoryBuildTargetsContents = s_directoryBuildTargetsForLocal;
9787
}

src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ public async Task BlazorRun(string config, Func<IPage, Task>? test=null, string
835835
.WithWorkingDirectory(_projectDir!);
836836

837837
await using var runner = new BrowserRunner(_testOutput);
838-
var page = await runner.RunAsync(runCommand, $"run -c {config} {extraArgs}");
838+
var page = await runner.RunAsync(runCommand, $"run -c {config} {extraArgs}", onConsoleMessage: OnConsoleMessage);
839839

840840
await page.Locator("text=Counter").ClickAsync();
841841
var txt = await page.Locator("p[role='status']").InnerHTMLAsync();
@@ -847,6 +847,13 @@ public async Task BlazorRun(string config, Func<IPage, Task>? test=null, string
847847

848848
if (test is not null)
849849
await test(page);
850+
851+
void OnConsoleMessage(IConsoleMessage msg)
852+
{
853+
if (EnvironmentVariables.ShowBuildOutput)
854+
Console.WriteLine($"[{msg.Type}] {msg.Text}");
855+
_testOutput.WriteLine($"[{msg.Type}] {msg.Text}");
856+
}
850857
}
851858

852859
public static (int exitCode, string buildOutput) RunProcess(string path,

src/mono/wasm/Wasm.Build.Tests/EnvironmentVariables.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ internal static class EnvironmentVariables
1212
internal static readonly string? SdkForWorkloadTestingPath = Environment.GetEnvironmentVariable("SDK_FOR_WORKLOAD_TESTING_PATH");
1313
internal static readonly string? SdkHasWorkloadInstalled = Environment.GetEnvironmentVariable("SDK_HAS_WORKLOAD_INSTALLED");
1414
internal static readonly string? WorkloadPacksVersion = Environment.GetEnvironmentVariable("WORKLOAD_PACKS_VER");
15-
internal static readonly string? AppRefDir = Environment.GetEnvironmentVariable("AppRefDir");
1615
internal static readonly string? TestLogPath = Environment.GetEnvironmentVariable("TEST_LOG_PATH");
1716
internal static readonly string? SkipProjectCleanup = Environment.GetEnvironmentVariable("SKIP_PROJECT_CLEANUP");
1817
internal static readonly string? XHarnessCliPath = Environment.GetEnvironmentVariable("XHARNESS_CLI_PATH");

src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,4 @@ if [%HELIX_CORRELATION_PAYLOAD%] NEQ [] (
114114

115115
set "PATH=%_SDK_DIR%;%PATH%"
116116
set "SDK_FOR_WORKLOAD_TESTING_PATH=%_SDK_DIR%"
117-
set "AppRefDir=%BASE_DIR%\microsoft.netcore.app.ref"
118117
EXIT /b 0

src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ function set_env_vars()
8989

9090
export PATH=$_SDK_DIR:$PATH
9191
export SDK_FOR_WORKLOAD_TESTING_PATH=$_SDK_DIR
92-
export AppRefDir=$BASE_DIR/microsoft.netcore.app.ref
9392
}
9493

9594
export TEST_LOG_PATH=${XHARNESS_OUT}/logs

0 commit comments

Comments
 (0)