Skip to content

Commit

Permalink
All WasmBuildTests use static project from assets or dotnet new, …
Browse files Browse the repository at this point in the history
…unification of browser tests (#109069)

* Fix build errors in WASI - refactor of WASI in a future PR.

* Fix binlog location.

* Update README.

* Feedback: non-nullable _projectDir.

* Fix `SatelliteAssembliesTests` and other test that require 3 states of `WasmBuildNative`

* `RebuildTests` fix after introducing figerprinting.

* Fix no-worklod tests: 1) do not double-assert `AssertRuntimePackPath` in blazor 2) `AssertRuntimePackPath` is correct  only when workload is there 3) NativeBuild should allow undefined in blazor tests as well.

* Fix `NativeBuildTests` - AppBundle was not asserted here originally.

* `WasmGenerateAppBundle=false` when workloads used (set in workload manifest). The check is incorrect in the current process of testing.

* Fix `MainWithArgsTests`. Url query can have arg key duplicates -> is better represented by `NameValueCollection` than `Dictionary`

* AppBundle was never asserted for size in `OptimizationFlagChangeTests` + use statistics that are fingerprinting insensitive.

* Reading from config is a known issue.

* Fix `ReferenceNewAssemblyRebuildTest`: Json lib was already referenced before the change in the test. Use Cryptography lib instead.

* Keep blazor workload tests together.

* Fix: `PInvokeTableGeneratorTests` on Windows.

* Move all no-workload blazor tests to one class.

* Use more meaningful name for `MiscTests3`.

* `PInvokeTableGeneratorTests` takes 2-3 times more time than average WBT class, divide it.

* Block the timeouting test with exisiting issue.

* Try avoiding port collisions in blazor tests run on kestrel.

* Removal of files and comments that were supposed to be deleted after approval.
  • Loading branch information
ilonatommy authored Dec 12, 2024
1 parent c646425 commit f30cfc0
Show file tree
Hide file tree
Showing 159 changed files with 3,912 additions and 5,103 deletions.
22 changes: 10 additions & 12 deletions eng/testing/scenarios/BuildWasmAppsJobsList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ Wasm.Build.NativeRebuild.Tests.NoopNativeRebuildTest
Wasm.Build.NativeRebuild.Tests.OptimizationFlagChangeTests
Wasm.Build.NativeRebuild.Tests.ReferenceNewAssemblyRebuildTest
Wasm.Build.NativeRebuild.Tests.SimpleSourceChangeRebuildTest
Wasm.Build.Tests.TestAppScenarios.InterpPgoTests
Wasm.Build.Tests.InterpPgoTests
Wasm.Build.Templates.Tests.NativeBuildTests
Wasm.Build.Tests.Blazor.AppsettingsTests
Wasm.Build.Tests.Blazor.BuildPublishTests
Wasm.Build.Tests.Blazor.SimpleRunTests
Wasm.Build.Tests.Blazor.CleanTests
Wasm.Build.Tests.Blazor.MiscTests
Wasm.Build.Tests.Blazor.MiscTests2
Wasm.Build.Tests.Blazor.MiscTests3
Wasm.Build.Tests.Blazor.DllImportTests
Wasm.Build.Tests.Blazor.NativeTests
Wasm.Build.Tests.Blazor.NoopNativeRebuildTest
Wasm.Build.Tests.Blazor.WorkloadRequiredTests
Wasm.Build.Tests.Blazor.IcuTests
Wasm.Build.Tests.Blazor.IcuShardingTests
Wasm.Build.Tests.Blazor.SignalRClientTests
Wasm.Build.Tests.BuildPublishTests
Wasm.Build.Tests.ConfigSrcTests
Wasm.Build.Tests.DllImportTests
Wasm.Build.Tests.IcuShardingTests
Wasm.Build.Tests.IcuShardingTests2
Wasm.Build.Tests.IcuTests
Expand All @@ -32,13 +30,13 @@ Wasm.Build.Tests.NonWasmTemplateBuildTests
Wasm.Build.Tests.PInvokeTableGeneratorTests
Wasm.Build.Tests.RebuildTests
Wasm.Build.Tests.SatelliteAssembliesTests
Wasm.Build.Tests.TestAppScenarios.AppSettingsTests
Wasm.Build.Tests.TestAppScenarios.DownloadThenInitTests
Wasm.Build.Tests.TestAppScenarios.LazyLoadingTests
Wasm.Build.Tests.TestAppScenarios.LibraryInitializerTests
Wasm.Build.Tests.TestAppScenarios.SatelliteLoadingTests
Wasm.Build.Tests.TestAppScenarios.ModuleConfigTests
Wasm.Build.Tests.TestAppScenarios.MemoryTests
Wasm.Build.Tests.AppSettingsTests
Wasm.Build.Tests.DownloadThenInitTests
Wasm.Build.Tests.LazyLoadingTests
Wasm.Build.Tests.LibraryInitializerTests
Wasm.Build.Tests.SatelliteLoadingTests
Wasm.Build.Tests.ModuleConfigTests
Wasm.Build.Tests.MemoryTests
Wasm.Build.Tests.AspNetCore.SignalRClientTests
Wasm.Build.Tests.WasmBuildAppTest
Wasm.Build.Tests.WasmNativeDefaultsTests
Expand Down
7 changes: 7 additions & 0 deletions src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,13 @@ public record BuildProjectOptions
string? TargetFramework = null,
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null
);

public record AssertBundleOptions(
BuildProjectOptions BuildOptions,
bool ExpectSymbolsFile = true,
bool AssertIcuAssets = true,
bool AssertSymbolsFile = true
);

public enum NativeFilesType { FromRuntimePack, Relinked, AOT };
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#nullable enable

// ToDo: should be common with Wasm.Build.Tests, copied here after Wasm.Build.Tests refactoring
namespace Wasm.Build.Tests
{
public class SharedBuildPerTestClassFixture : IDisposable
Expand Down
42 changes: 42 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/AppSettingsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

#nullable enable

namespace Wasm.Build.Tests;

public class AppSettingsTests : WasmTemplateTestsBase
{
public AppSettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
{
}

[Theory]
[InlineData("Development")]
[InlineData("Production")]
public async Task LoadAppSettingsBasedOnApplicationEnvironment(string applicationEnvironment)
{
Configuration config = Configuration.Debug;
ProjectInfo info = CopyTestAsset(config, aot: false, TestAsset.WasmBasicTestApp, "AppSettingsTest");
PublishProject(info, config);
BrowserRunOptions options = new(
config,
TestScenario: "AppSettingsTest",
BrowserQueryString: new NameValueCollection { { "applicationEnvironment", applicationEnvironment } }
);
RunResult result = await RunForPublishWithWebServer(options);
Assert.Contains(result.TestOutput, m => m.Contains("'/appsettings.json' exists 'True'"));
Assert.Contains(result.TestOutput, m => m.Contains($"'/appsettings.Development.json' exists '{applicationEnvironment == "Development"}'"));
Assert.Contains(result.TestOutput, m => m.Contains($"'/appsettings.Production.json' exists '{applicationEnvironment == "Production"}'"));
}
}
10 changes: 5 additions & 5 deletions src/mono/wasm/Wasm.Build.Tests/AspNetCore/SignalRClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public SignalRClientTests(ITestOutputHelper output, SharedBuildPerTestClassFixtu

[ActiveIssue("https://github.com/dotnet/runtime/issues/106807")]
[ConditionalTheory(typeof(BuildTestBase), nameof(IsWorkloadWithMultiThreadingForDefaultFramework))]
[InlineData("Debug", "LongPolling")]
[InlineData("Release", "LongPolling")]
[InlineData("Debug", "WebSockets")]
[InlineData("Release", "WebSockets")]
public async Task SignalRPassMessageWasmBrowser(string config, string transport) =>
[InlineData(Configuration.Debug, "LongPolling")]
[InlineData(Configuration.Release, "LongPolling")]
[InlineData(Configuration.Debug, "WebSockets")]
[InlineData(Configuration.Release, "WebSockets")]
public async Task SignalRPassMessageWasmBrowser(Configuration config, string transport) =>
await SignalRPassMessage("wasmclient", config, transport);
}
52 changes: 24 additions & 28 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/AppsettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit;
Expand All @@ -21,39 +22,34 @@ public AppsettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture
[Fact]
public async Task FileInVfs()
{
string id = $"blazor_{GetRandomId()}";
string projectFile = CreateWasmTemplateProject(id, "blazorwasm");

string projectDirectory = Path.GetDirectoryName(projectFile)!;

File.WriteAllText(Path.Combine(projectDirectory, "wwwroot", "appsettings.json"), $"{{ \"Id\": \"{id}\" }}");

string programPath = Path.Combine(projectDirectory, "Program.cs");
string programContent = File.ReadAllText(programPath);
programContent = programContent.Replace("var builder",
"""
System.Console.WriteLine($"appSettings Exists '{File.Exists("/appsettings.json")}'");
System.Console.WriteLine($"appSettings Content '{File.ReadAllText("/appsettings.json")}'");
var builder
""");
File.WriteAllText(programPath, programContent);

BlazorBuild(new BlazorBuildOptions(id, "debug", NativeFilesType.FromRuntimePack));
Configuration config = Configuration.Debug;
ProjectInfo info = CreateWasmTemplateProject(Template.BlazorWasm, config, aot: false, "blazor");
UpdateHomePage();
string projectDirectory = Path.GetDirectoryName(info.ProjectFilePath)!;
File.WriteAllText(Path.Combine(projectDirectory, "wwwroot", "appsettings.json"), $"{{ \"Id\": \"{info.ProjectName}\" }}");
UpdateFile("Program.cs", new Dictionary<string, string>
{
{
"var builder",
"""
System.Console.WriteLine($"appSettings Exists '{File.Exists("/appsettings.json")}'");
System.Console.WriteLine($"appSettings Content '{File.ReadAllText("/appsettings.json")}'");
var builder
"""
}
});

(string _, string buildOutput) = BlazorBuild(info, config);
bool existsChecked = false;
bool contentChecked = false;

await BlazorRunForBuildWithDotnetRun(new BlazorRunOptions()
{
Config = "debug",
OnConsoleMessage = (_, msg) =>
{
if (msg.Text.Contains("appSettings Exists 'True'"))
await RunForBuildWithDotnetRun(new BlazorRunOptions(
config,
OnConsoleMessage: (_, msg) => {
if (msg.Contains("appSettings Exists 'True'"))
existsChecked = true;
else if (msg.Text.Contains($"appSettings Content '{{ \"Id\": \"{id}\" }}'"))
else if (msg.Contains($"appSettings Content '{{ \"Id\": \"{info.ProjectName}\" }}'"))
contentChecked = true;
}
});
}));

Assert.True(existsChecked, "File '/appsettings.json' wasn't found");
Assert.True(contentChecked, "Content of '/appsettings.json' is not matched");
Expand Down
25 changes: 0 additions & 25 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorBuildOptions.cs

This file was deleted.

64 changes: 47 additions & 17 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorRunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,56 @@

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading.Tasks;
using Microsoft.Playwright;

#nullable enable

namespace Wasm.Build.Tests.Blazor;
public record BlazorRunOptions
(
BlazorRunHost Host = BlazorRunHost.DotnetRun,
bool DetectRuntimeFailures = true,
bool CheckCounter = true,
Dictionary<string, string>? ServerEnvironment = null,
Func<IPage, Task>? Test = null,
Action<IPage, IConsoleMessage>? OnConsoleMessage = null,
Action<string>? OnServerMessage = null,
Action<string>? OnErrorMessage = null,
string Config = "Debug",
string? ExtraArgs = null,
string BrowserPath = "",
string QueryString = ""
);
namespace Wasm.Build.Tests;
public record BlazorRunOptions : RunOptions
{
public bool CheckCounter { get; init; }
public Func<IPage, Task>? Test { get; init; }

public BlazorRunOptions(
Configuration Configuration,
bool AOT = false,
RunHost Host = RunHost.DotnetRun,
bool DetectRuntimeFailures = true,
Dictionary<string, string>? ServerEnvironment = null,
NameValueCollection? BrowserQueryString = null,
Action<string, string>? OnConsoleMessage = null,
Action<string>? OnServerMessage = null,
Action<string>? OnErrorMessage = null,
string ExtraArgs = "",
string BrowserPath = "",
string Locale = "en-US",
int? ExpectedExitCode = 0,
string CustomBundleDir = "",
bool CheckCounter = true,
Func<IPage, Task>? Test = null,
Func<RunOptions, IPage, Task>? ExecuteAfterLoaded = null
) : base(
Configuration,
AOT,
Host,
DetectRuntimeFailures,
ServerEnvironment,
BrowserQueryString,
OnConsoleMessage,
OnServerMessage,
OnErrorMessage,
ExtraArgs,
BrowserPath,
Locale,
ExpectedExitCode,
CustomBundleDir,
ExecuteAfterLoaded
)
{
this.CheckCounter = CheckCounter;
this.Test = Test;
}
}

public enum BlazorRunHost { DotnetRun, WebServer };
32 changes: 0 additions & 32 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmProjectProvider.cs

This file was deleted.

Loading

0 comments on commit f30cfc0

Please sign in to comment.