Skip to content

Commit f30cfc0

Browse files
authored
All WasmBuildTests use static project from assets or dotnet new, 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.
1 parent c646425 commit f30cfc0

File tree

159 files changed

+3912
-5103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+3912
-5103
lines changed

eng/testing/scenarios/BuildWasmAppsJobsList.txt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ Wasm.Build.NativeRebuild.Tests.NoopNativeRebuildTest
33
Wasm.Build.NativeRebuild.Tests.OptimizationFlagChangeTests
44
Wasm.Build.NativeRebuild.Tests.ReferenceNewAssemblyRebuildTest
55
Wasm.Build.NativeRebuild.Tests.SimpleSourceChangeRebuildTest
6-
Wasm.Build.Tests.TestAppScenarios.InterpPgoTests
6+
Wasm.Build.Tests.InterpPgoTests
77
Wasm.Build.Templates.Tests.NativeBuildTests
88
Wasm.Build.Tests.Blazor.AppsettingsTests
99
Wasm.Build.Tests.Blazor.BuildPublishTests
1010
Wasm.Build.Tests.Blazor.SimpleRunTests
1111
Wasm.Build.Tests.Blazor.CleanTests
1212
Wasm.Build.Tests.Blazor.MiscTests
13-
Wasm.Build.Tests.Blazor.MiscTests2
14-
Wasm.Build.Tests.Blazor.MiscTests3
13+
Wasm.Build.Tests.Blazor.DllImportTests
1514
Wasm.Build.Tests.Blazor.NativeTests
1615
Wasm.Build.Tests.Blazor.NoopNativeRebuildTest
1716
Wasm.Build.Tests.Blazor.WorkloadRequiredTests
18-
Wasm.Build.Tests.Blazor.IcuTests
19-
Wasm.Build.Tests.Blazor.IcuShardingTests
2017
Wasm.Build.Tests.Blazor.SignalRClientTests
2118
Wasm.Build.Tests.BuildPublishTests
2219
Wasm.Build.Tests.ConfigSrcTests
20+
Wasm.Build.Tests.DllImportTests
2321
Wasm.Build.Tests.IcuShardingTests
2422
Wasm.Build.Tests.IcuShardingTests2
2523
Wasm.Build.Tests.IcuTests
@@ -32,13 +30,13 @@ Wasm.Build.Tests.NonWasmTemplateBuildTests
3230
Wasm.Build.Tests.PInvokeTableGeneratorTests
3331
Wasm.Build.Tests.RebuildTests
3432
Wasm.Build.Tests.SatelliteAssembliesTests
35-
Wasm.Build.Tests.TestAppScenarios.AppSettingsTests
36-
Wasm.Build.Tests.TestAppScenarios.DownloadThenInitTests
37-
Wasm.Build.Tests.TestAppScenarios.LazyLoadingTests
38-
Wasm.Build.Tests.TestAppScenarios.LibraryInitializerTests
39-
Wasm.Build.Tests.TestAppScenarios.SatelliteLoadingTests
40-
Wasm.Build.Tests.TestAppScenarios.ModuleConfigTests
41-
Wasm.Build.Tests.TestAppScenarios.MemoryTests
33+
Wasm.Build.Tests.AppSettingsTests
34+
Wasm.Build.Tests.DownloadThenInitTests
35+
Wasm.Build.Tests.LazyLoadingTests
36+
Wasm.Build.Tests.LibraryInitializerTests
37+
Wasm.Build.Tests.SatelliteLoadingTests
38+
Wasm.Build.Tests.ModuleConfigTests
39+
Wasm.Build.Tests.MemoryTests
4240
Wasm.Build.Tests.AspNetCore.SignalRClientTests
4341
Wasm.Build.Tests.WasmBuildAppTest
4442
Wasm.Build.Tests.WasmNativeDefaultsTests

src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,13 @@ public record BuildProjectOptions
758758
string? TargetFramework = null,
759759
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null
760760
);
761+
762+
public record AssertBundleOptions(
763+
BuildProjectOptions BuildOptions,
764+
bool ExpectSymbolsFile = true,
765+
bool AssertIcuAssets = true,
766+
bool AssertSymbolsFile = true
767+
);
761768

762769
public enum NativeFilesType { FromRuntimePack, Relinked, AOT };
763770
}

src/mono/wasm/Wasm.Build.Tests/Common/SharedBuildPerTestClassFixture.cs renamed to src/mono/wasi/Wasi.Build.Tests/SharedBuildPerTestClassFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#nullable enable
1111

12+
// ToDo: should be common with Wasm.Build.Tests, copied here after Wasm.Build.Tests refactoring
1213
namespace Wasm.Build.Tests
1314
{
1415
public class SharedBuildPerTestClassFixture : IDisposable
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.Specialized;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
using Xunit;
11+
using Xunit.Abstractions;
12+
13+
#nullable enable
14+
15+
namespace Wasm.Build.Tests;
16+
17+
public class AppSettingsTests : WasmTemplateTestsBase
18+
{
19+
public AppSettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
20+
: base(output, buildContext)
21+
{
22+
}
23+
24+
[Theory]
25+
[InlineData("Development")]
26+
[InlineData("Production")]
27+
public async Task LoadAppSettingsBasedOnApplicationEnvironment(string applicationEnvironment)
28+
{
29+
Configuration config = Configuration.Debug;
30+
ProjectInfo info = CopyTestAsset(config, aot: false, TestAsset.WasmBasicTestApp, "AppSettingsTest");
31+
PublishProject(info, config);
32+
BrowserRunOptions options = new(
33+
config,
34+
TestScenario: "AppSettingsTest",
35+
BrowserQueryString: new NameValueCollection { { "applicationEnvironment", applicationEnvironment } }
36+
);
37+
RunResult result = await RunForPublishWithWebServer(options);
38+
Assert.Contains(result.TestOutput, m => m.Contains("'/appsettings.json' exists 'True'"));
39+
Assert.Contains(result.TestOutput, m => m.Contains($"'/appsettings.Development.json' exists '{applicationEnvironment == "Development"}'"));
40+
Assert.Contains(result.TestOutput, m => m.Contains($"'/appsettings.Production.json' exists '{applicationEnvironment == "Production"}'"));
41+
}
42+
}

src/mono/wasm/Wasm.Build.Tests/AspNetCore/SignalRClientTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public SignalRClientTests(ITestOutputHelper output, SharedBuildPerTestClassFixtu
1919

2020
[ActiveIssue("https://github.com/dotnet/runtime/issues/106807")]
2121
[ConditionalTheory(typeof(BuildTestBase), nameof(IsWorkloadWithMultiThreadingForDefaultFramework))]
22-
[InlineData("Debug", "LongPolling")]
23-
[InlineData("Release", "LongPolling")]
24-
[InlineData("Debug", "WebSockets")]
25-
[InlineData("Release", "WebSockets")]
26-
public async Task SignalRPassMessageWasmBrowser(string config, string transport) =>
22+
[InlineData(Configuration.Debug, "LongPolling")]
23+
[InlineData(Configuration.Release, "LongPolling")]
24+
[InlineData(Configuration.Debug, "WebSockets")]
25+
[InlineData(Configuration.Release, "WebSockets")]
26+
public async Task SignalRPassMessageWasmBrowser(Configuration config, string transport) =>
2727
await SignalRPassMessage("wasmclient", config, transport);
2828
}

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

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Collections.Generic;
45
using System.IO;
56
using System.Threading.Tasks;
67
using Xunit;
@@ -21,39 +22,34 @@ public AppsettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture
2122
[Fact]
2223
public async Task FileInVfs()
2324
{
24-
string id = $"blazor_{GetRandomId()}";
25-
string projectFile = CreateWasmTemplateProject(id, "blazorwasm");
26-
27-
string projectDirectory = Path.GetDirectoryName(projectFile)!;
28-
29-
File.WriteAllText(Path.Combine(projectDirectory, "wwwroot", "appsettings.json"), $"{{ \"Id\": \"{id}\" }}");
30-
31-
string programPath = Path.Combine(projectDirectory, "Program.cs");
32-
string programContent = File.ReadAllText(programPath);
33-
programContent = programContent.Replace("var builder",
34-
"""
35-
System.Console.WriteLine($"appSettings Exists '{File.Exists("/appsettings.json")}'");
36-
System.Console.WriteLine($"appSettings Content '{File.ReadAllText("/appsettings.json")}'");
37-
var builder
38-
""");
39-
File.WriteAllText(programPath, programContent);
40-
41-
BlazorBuild(new BlazorBuildOptions(id, "debug", NativeFilesType.FromRuntimePack));
25+
Configuration config = Configuration.Debug;
26+
ProjectInfo info = CreateWasmTemplateProject(Template.BlazorWasm, config, aot: false, "blazor");
27+
UpdateHomePage();
28+
string projectDirectory = Path.GetDirectoryName(info.ProjectFilePath)!;
29+
File.WriteAllText(Path.Combine(projectDirectory, "wwwroot", "appsettings.json"), $"{{ \"Id\": \"{info.ProjectName}\" }}");
30+
UpdateFile("Program.cs", new Dictionary<string, string>
31+
{
32+
{
33+
"var builder",
34+
"""
35+
System.Console.WriteLine($"appSettings Exists '{File.Exists("/appsettings.json")}'");
36+
System.Console.WriteLine($"appSettings Content '{File.ReadAllText("/appsettings.json")}'");
37+
var builder
38+
"""
39+
}
40+
});
4241

42+
(string _, string buildOutput) = BlazorBuild(info, config);
4343
bool existsChecked = false;
4444
bool contentChecked = false;
45-
46-
await BlazorRunForBuildWithDotnetRun(new BlazorRunOptions()
47-
{
48-
Config = "debug",
49-
OnConsoleMessage = (_, msg) =>
50-
{
51-
if (msg.Text.Contains("appSettings Exists 'True'"))
45+
await RunForBuildWithDotnetRun(new BlazorRunOptions(
46+
config,
47+
OnConsoleMessage: (_, msg) => {
48+
if (msg.Contains("appSettings Exists 'True'"))
5249
existsChecked = true;
53-
else if (msg.Text.Contains($"appSettings Content '{{ \"Id\": \"{id}\" }}'"))
50+
else if (msg.Contains($"appSettings Content '{{ \"Id\": \"{info.ProjectName}\" }}'"))
5451
contentChecked = true;
55-
}
56-
});
52+
}));
5753

5854
Assert.True(existsChecked, "File '/appsettings.json' wasn't found");
5955
Assert.True(contentChecked, "Content of '/appsettings.json' is not matched");

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,56 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Collections.Specialized;
67
using System.Threading.Tasks;
78
using Microsoft.Playwright;
89

910
#nullable enable
1011

11-
namespace Wasm.Build.Tests.Blazor;
12-
public record BlazorRunOptions
13-
(
14-
BlazorRunHost Host = BlazorRunHost.DotnetRun,
15-
bool DetectRuntimeFailures = true,
16-
bool CheckCounter = true,
17-
Dictionary<string, string>? ServerEnvironment = null,
18-
Func<IPage, Task>? Test = null,
19-
Action<IPage, IConsoleMessage>? OnConsoleMessage = null,
20-
Action<string>? OnServerMessage = null,
21-
Action<string>? OnErrorMessage = null,
22-
string Config = "Debug",
23-
string? ExtraArgs = null,
24-
string BrowserPath = "",
25-
string QueryString = ""
26-
);
12+
namespace Wasm.Build.Tests;
13+
public record BlazorRunOptions : RunOptions
14+
{
15+
public bool CheckCounter { get; init; }
16+
public Func<IPage, Task>? Test { get; init; }
17+
18+
public BlazorRunOptions(
19+
Configuration Configuration,
20+
bool AOT = false,
21+
RunHost Host = RunHost.DotnetRun,
22+
bool DetectRuntimeFailures = true,
23+
Dictionary<string, string>? ServerEnvironment = null,
24+
NameValueCollection? BrowserQueryString = null,
25+
Action<string, string>? OnConsoleMessage = null,
26+
Action<string>? OnServerMessage = null,
27+
Action<string>? OnErrorMessage = null,
28+
string ExtraArgs = "",
29+
string BrowserPath = "",
30+
string Locale = "en-US",
31+
int? ExpectedExitCode = 0,
32+
string CustomBundleDir = "",
33+
bool CheckCounter = true,
34+
Func<IPage, Task>? Test = null,
35+
Func<RunOptions, IPage, Task>? ExecuteAfterLoaded = null
36+
) : base(
37+
Configuration,
38+
AOT,
39+
Host,
40+
DetectRuntimeFailures,
41+
ServerEnvironment,
42+
BrowserQueryString,
43+
OnConsoleMessage,
44+
OnServerMessage,
45+
OnErrorMessage,
46+
ExtraArgs,
47+
BrowserPath,
48+
Locale,
49+
ExpectedExitCode,
50+
CustomBundleDir,
51+
ExecuteAfterLoaded
52+
)
53+
{
54+
this.CheckCounter = CheckCounter;
55+
this.Test = Test;
56+
}
57+
}
2758

28-
public enum BlazorRunHost { DotnetRun, WebServer };

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

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)