Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All WasmBuildTests use static project from assets or dotnet new, unification of browser tests #109069

Merged
merged 109 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
8c91ed8
`ConfigSrcTests`, `BuildPublishTests` ready.
ilonatommy Oct 21, 2024
a451e4e
Fix WASI build errors - WASI is not prepared for making `BrowserStruc…
ilonatommy Oct 21, 2024
afd4d5c
Non-invariatn globalization WBT: done.
ilonatommy Oct 21, 2024
f2bb8ab
Missing change to previous commit.
ilonatommy Oct 21, 2024
cd4f94d
`InvariantGlobalizationTests` done
ilonatommy Oct 21, 2024
531a197
Missing change to icu tests.
ilonatommy Oct 21, 2024
d762fb6
`InvariantTimezoneTests` done
ilonatommy Oct 21, 2024
84d1df2
Draft of `MainWithArgsTests` - does not work.
ilonatommy Oct 22, 2024
43fbb6e
Consolidate Blazor and Browser app run methods.
ilonatommy Oct 22, 2024
58d2e43
`NativeBuildTests`: done.
ilonatommy Oct 22, 2024
2f03ff1
HybridGlobalization should be disabled till removal.
ilonatommy Oct 22, 2024
31b3239
`NativeLibraryTests`: done.
ilonatommy Oct 22, 2024
1d94cf9
Blocked `SkiaSharp` test has to get refactored as well to remove buil…
ilonatommy Oct 23, 2024
1e7bf92
Fix build errors in WASI - refactor of WASI in a future PR.
ilonatommy Oct 23, 2024
970468a
Project lib extension depends on `UseWebcil` value.
ilonatommy Oct 23, 2024
8ea5538
`NoopNativeRebuildTest`: done.
ilonatommy Oct 23, 2024
df091e7
Assert test run exit code.
ilonatommy Oct 23, 2024
2500064
ToDo: `NativeRebuildTests` that still require work.
ilonatommy Oct 23, 2024
0f502df
Merge `AppTestBase` with `WasmTemplateTestBase`.
ilonatommy Oct 24, 2024
f7f0041
NativeRelink cannot be false when it's forced by other property values.
ilonatommy Oct 25, 2024
309bd9a
Fix minor mistakes in refactoring.
ilonatommy Oct 25, 2024
fe7b988
`WasmBuildAppBase`: done but reading from config fails.
ilonatommy Oct 25, 2024
bb96e7d
`WorkloadTests`, `WasmTemplateTestsBase`, `WasmSIMDTests`, `WasmRunOu…
ilonatommy Oct 25, 2024
902f6d0
Correct typo in assets path + shorten.
ilonatommy Nov 1, 2024
c1dbde6
Fix binlog location.
ilonatommy Nov 1, 2024
e05d2aa
Fix `WasmNativeDefaultsTests`
ilonatommy Nov 1, 2024
7cbec74
Merge remote-tracking branch 'origin/main' into refactor-test-main-ba…
ilonatommy Nov 1, 2024
15860cf
Block tests that should get fixed later.
ilonatommy Nov 4, 2024
a0974c7
Correct a typo.
ilonatommy Nov 4, 2024
1f74ee2
Avoid AOT long path issues in scenario-based tests on Windows.
ilonatommy Nov 4, 2024
5cf34db
Missing file in arg rename.
ilonatommy Nov 4, 2024
b3b82c1
Workaround for interpreter issues.
ilonatommy Nov 4, 2024
1a0ea6e
Improve workaround.
ilonatommy Nov 5, 2024
10dd1ab
Avoid timeouts on Windows.
ilonatommy Nov 6, 2024
c8ef33d
Missing change for the previous commit.
ilonatommy Nov 6, 2024
bc444bf
`PInvokeTableGeneratorTests`: done (with two issues).
ilonatommy Nov 8, 2024
ce03481
Merge remote-tracking branch 'origin/main' into refactor-test-main-ba…
ilonatommy Nov 8, 2024
9a1fcfb
Merge branch 'main' into refactor-test-main-based-wbt
ilonatommy Nov 8, 2024
e63800e
`NonWasmTemplateBuildTests`: done
ilonatommy Nov 8, 2024
0279b78
`SatelliteAssembliesTests`: done
ilonatommy Nov 11, 2024
79c6963
`RebuildTests`: done. `TestMainJsTestBase` is not used anymore.
ilonatommy Nov 11, 2024
42aae42
`WasmTemplateTests`: done.
ilonatommy Nov 11, 2024
2f1fd89
`NativeBuildTests`: done
ilonatommy Nov 11, 2024
58d3563
Started unifying blazor methods. `AppsettingsTests`: done.
ilonatommy Nov 11, 2024
a1ccf58
Added blazor equivalent of `WasmBasicTestApp`. `Blazor.BuildPublishTe…
ilonatommy Nov 11, 2024
902030f
Some tests should stay disabled.
ilonatommy Nov 11, 2024
a52e09b
`Blazor.CleanTests`: done
ilonatommy Nov 12, 2024
ee9c355
`Blazor.MiscTests`: done
ilonatommy Nov 12, 2024
4684136
`Blazor.MiscTests2`" done.
ilonatommy Nov 12, 2024
96b0cff
`MiscTests3`: done. Debug with aot is not supported. Added library to…
ilonatommy Nov 12, 2024
ab894fe
`NativeTests`: done
ilonatommy Nov 12, 2024
d8762cc
`NativeTests`: uncomment.
ilonatommy Nov 12, 2024
f40cf8a
`NoopNativeRebuildTest`: done
ilonatommy Nov 12, 2024
5505603
`SimpleRunTests`: done
ilonatommy Nov 12, 2024
0af3355
`Blazor.WorkloadRequiredTests`: done
ilonatommy Nov 12, 2024
262ff89
`Blazor.SimpleMultiThreadedTests`: has issues with running after build.
ilonatommy Nov 12, 2024
ffab6a3
Update README.
ilonatommy Nov 14, 2024
4380a4a
Speedup NativeRebuild tests - they don't have to use dotnet new.
ilonatommy Nov 14, 2024
1c81cfe
Speed up BuildPublishTests.
ilonatommy Nov 14, 2024
04d395d
Remove methods that are not used anymore.
ilonatommy Nov 15, 2024
62f0f8c
Nit review changes.
ilonatommy Nov 15, 2024
99a6315
`BasicTestApp` for blazor and wasm.
ilonatommy Nov 15, 2024
9812930
Remove WASI build errors
ilonatommy Nov 15, 2024
75adae8
Fix: too many replacements.
ilonatommy Nov 18, 2024
18eb807
WIP with feedback - not building correctly yet
ilonatommy Nov 18, 2024
99d14a4
Follow up for feedback - fix the WIP commit.
ilonatommy Nov 28, 2024
54a3d82
Merge branch 'main' into refactor-test-main-based-wbt
ilonatommy Nov 28, 2024
565ad73
Feedback: non-nullable _projectDir.
ilonatommy Nov 28, 2024
e5abb4a
Fix wasi build.
ilonatommy Nov 28, 2024
f875a23
Feedback: cleanup `RunOptions`.
ilonatommy Nov 28, 2024
3360519
Fix `SimpleRunTests`.
ilonatommy Nov 29, 2024
53104ba
Fix `WasmTemplateTests`
ilonatommy Nov 29, 2024
456a6c9
Fix `InvariantGlobalizationTests`
ilonatommy Nov 29, 2024
5cdf29b
Fix `PInvokeTableGeneratorTests`
ilonatommy Nov 29, 2024
d26c17c
Fix `SatelliteAssembliesTests` and other test that require 3 states o…
ilonatommy Nov 29, 2024
160797b
Fix `SatelliteLoadingTests`
ilonatommy Nov 29, 2024
bd66cf1
`RebuildTests` fix after introducing figerprinting.
ilonatommy Nov 29, 2024
7d8690c
AOT: true fails. More investigation needed.
ilonatommy Nov 29, 2024
786ece3
`ReferenceNewAssemblyRebuildTest` fix. AOT: rue, more investigation n…
ilonatommy Nov 29, 2024
b479336
Fix no-worklod tests: 1) do not double-assert `AssertRuntimePackPath`…
ilonatommy Dec 2, 2024
188a274
Fix `NativeBuildTests` - AppBundle was not asserted here originally.
ilonatommy Dec 2, 2024
6a3e770
Fix `DefaultTemplate_AOT_InProjectFile`: AOT arg was missing.
ilonatommy Dec 2, 2024
46e83e7
Avoid double asserts.
ilonatommy Dec 2, 2024
c23f523
Fix expected file order.
ilonatommy Dec 2, 2024
c969abd
Revert 7d8690c72495e10323511bf27e0ca7dec0f0a94e#diff-39b3592b9f7579ad…
ilonatommy Dec 2, 2024
68c9299
Fix cases that keep NativeBuild undefined.
ilonatommy Dec 2, 2024
f90eb74
Fix `SatelliteAssembliesTests`: correct order of `ExpectedFileType`
ilonatommy Dec 2, 2024
2f945fd
`WasmGenerateAppBundle=false` when workloads used (set in workload ma…
ilonatommy Dec 2, 2024
333d8ce
Feedback: store all assets in `testAsset` class.
ilonatommy Dec 2, 2024
8914f9b
Fix `MainWithArgsTests`. Url query can have arg key duplicates -> is …
ilonatommy Dec 2, 2024
6de35c1
Fix `WasmBuildAppTest`
ilonatommy Dec 3, 2024
fafdfc0
AppBundle was never asserted for size in `OptimizationFlagChangeTests…
ilonatommy Dec 3, 2024
10a50ab
Reading from config is a known issue.
ilonatommy Dec 5, 2024
a3f19ad
Fix `SimpleSourceChangeRebuildTest`: pass AOT arg to build methods.
ilonatommy Dec 5, 2024
f86ed8d
Fix `OptimizationFlagChangeTests`: log when requested in the query.
ilonatommy Dec 5, 2024
410141a
Fix `FlagsChangeRebuildTests`.
ilonatommy Dec 6, 2024
f9503c7
Fix `ReferenceNewAssemblyRebuildTest`: Json lib was already reference…
ilonatommy Dec 6, 2024
9d153d6
Missing change to the previous commit.
ilonatommy Dec 6, 2024
25a614f
Keep blazor workload tests together.
ilonatommy Dec 6, 2024
61890b9
Fix: `PInvokeTableGeneratorTests` on Windows.
ilonatommy Dec 6, 2024
52c12b3
Move all no-workload blazor tests to one class.
ilonatommy Dec 6, 2024
b72048a
Use more meaningful name for `MiscTests3`.
ilonatommy Dec 6, 2024
6267705
`PInvokeTableGeneratorTests` takes 2-3 times more time than average W…
ilonatommy Dec 6, 2024
8307308
Disable test failing on Windows.
ilonatommy Dec 6, 2024
651aa6f
Block the timeouting test with exisiting issue.
ilonatommy Dec 9, 2024
3268520
Try avoiding port collisions in blazor tests run on kestrel.
ilonatommy Dec 9, 2024
c94e7dd
Feedback.
ilonatommy Dec 12, 2024
81d1dff
Merge remote-tracking branch 'origin/main' into refactor-test-main-ba…
ilonatommy Dec 12, 2024
2f6c3b9
Removal of files and comments that were supposed to be deleted after …
ilonatommy Dec 12, 2024
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
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
80 changes: 40 additions & 40 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/AppsettingsTests.cs
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,44 @@ public AppsettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture
_enablePerTestCleanup = true;
}

[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));

bool existsChecked = false;
bool contentChecked = false;

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

Assert.True(existsChecked, "File '/appsettings.json' wasn't found");
Assert.True(contentChecked, "Content of '/appsettings.json' is not matched");
}
// [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 BuildProjectOptions(id, "debug", NativeFilesType.FromRuntimePack));

// bool existsChecked = false;
// bool contentChecked = false;

// await BlazorRunForBuildWithDotnetRun(new RunOptions()
// {
// Configuration = "debug",
// OnConsoleMessage = (_, msg) =>
// {
// if (msg.Text.Contains("appSettings Exists 'True'"))
// existsChecked = true;
// else if (msg.Text.Contains($"appSettings Content '{{ \"Id\": \"{id}\" }}'"))
// contentChecked = true;
// }
// });

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

This file was deleted.

This file was deleted.

152 changes: 59 additions & 93 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace Wasm.Build.Tests;

public abstract class BlazorWasmTestBase : WasmTemplateTestsBase
{
protected readonly BlazorWasmProjectProvider _provider;
protected readonly WasmSdkBasedProjectProvider _provider;
protected BlazorWasmTestBase(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext, new BlazorWasmProjectProvider(output, DefaultTargetFrameworkForBlazor))
: base(output, buildContext, new WasmSdkBasedProjectProvider(output, DefaultTargetFrameworkForBlazor))
{
_provider = GetProvider<BlazorWasmProjectProvider>();
_provider = GetProvider<WasmSdkBasedProjectProvider>();
}

public void InitBlazorWasmProjectDir(string id, string targetFramework = DefaultTargetFrameworkForBlazor)
Expand Down Expand Up @@ -54,12 +54,17 @@ public string CreateBlazorWasmTemplateProject(string id)
return Path.Combine(_projectDir!, $"{id}.csproj");
}

protected (CommandResult, string) BlazorBuild(BlazorBuildOptions options, params string[] extraArgs)
protected (CommandResult, string) BlazorBuild(BuildProjectOptions options, params string[] extraArgs)
{
if (options.WarnAsError)
extraArgs = extraArgs.Append("/warnaserror").ToArray();

(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: false, setWasmDevel: false, expectSuccess: options.ExpectSuccess, extraArgs);
(CommandResult res, string logPath) = BlazorBuildInternal(
options.Id,
options.Configuration,
setWasmDevel: false,
expectSuccess: options.ExpectSuccess,
extraArgs: extraArgs);

if (options.ExpectSuccess && options.AssertAppBundle)
{
Expand All @@ -69,17 +74,17 @@ public string CreateBlazorWasmTemplateProject(string id)
return (res, logPath);
}

protected (CommandResult, string) BlazorPublish(BlazorBuildOptions options, params string[] extraArgs)
protected (CommandResult, string) BlazorPublish(BuildProjectOptions options, params string[] extraArgs)
{
if (options.WarnAsError)
extraArgs = extraArgs.Append("/warnaserror").ToArray();

(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: true, setWasmDevel: false, expectSuccess: options.ExpectSuccess, extraArgs);
(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Configuration, publish: true, setWasmDevel: false, expectSuccess: options.ExpectSuccess, extraArgs);

if (options.ExpectSuccess && options.AssertAppBundle)
{
// Because we do relink in Release publish by default
if (options.Config == "Release")
if (options.Configuration == "Release")
options = options with { ExpectedFileType = NativeFilesType.Relinked };

AssertBundle(res.Output, options with { IsPublish = true });
Expand All @@ -99,9 +104,13 @@ public string CreateBlazorWasmTemplateProject(string id)
try
{
return BuildProjectWithoutAssert(
id,
config,
new BuildProjectOptions(CreateProject: false, UseCache: false, Publish: publish, ExpectSuccess: expectSuccess),
new BuildProjectOptions(
id,
config,
GetBlazorBinFrameworkDir(config, forPublish: publish),
UseCache: false,
IsPublish: publish,
ExpectSuccess: expectSuccess),
extraArgs.Concat(new[]
{
"-p:BlazorEnableCompression=false",
Expand All @@ -116,22 +125,22 @@ public string CreateBlazorWasmTemplateProject(string id)
}
}

public void AssertBundle(string buildOutput, BlazorBuildOptions blazorBuildOptions)
public void AssertBundle(string buildOutput, BuildProjectOptions buildOptions)
{
if (IsUsingWorkloads)
{
// In no-workload case, the path would be from a restored nuget
ProjectProviderBase.AssertRuntimePackPath(buildOutput, blazorBuildOptions.TargetFramework ?? DefaultTargetFramework, blazorBuildOptions.RuntimeType);
ProjectProviderBase.AssertRuntimePackPath(buildOutput, buildOptions.TargetFramework ?? DefaultTargetFramework, buildOptions.RuntimeType);
}

_provider.AssertBundle(blazorBuildOptions);
_provider.AssertBundle(buildOptions);

if (!blazorBuildOptions.IsPublish)
if (!buildOptions.IsPublish)
return;

// Publish specific checks

if (blazorBuildOptions.ExpectedFileType == NativeFilesType.AOT)
if (buildOptions.ExpectedFileType == NativeFilesType.AOT)
{
// check for this too, so we know the format is correct for the negative
// test for jsinterop.webassembly.dll
Expand All @@ -141,9 +150,9 @@ public void AssertBundle(string buildOutput, BlazorBuildOptions blazorBuildOptio
Assert.DoesNotContain("Microsoft.JSInterop.WebAssembly.dll -> Microsoft.JSInterop.WebAssembly.dll.bc", buildOutput);
}

string objBuildDir = Path.Combine(_projectDir!, "obj", blazorBuildOptions.Config, blazorBuildOptions.TargetFramework!, "wasm", "for-build");
string objBuildDir = Path.Combine(_projectDir!, "obj", buildOptions.Configuration, buildOptions.TargetFramework!, "wasm", "for-build");
// Check that we linked only for publish
if (blazorBuildOptions.ExpectRelinkDirWhenPublishing)
if (buildOptions.ExpectRelinkDirWhenPublishing)
Assert.True(Directory.Exists(objBuildDir), $"Could not find expected {objBuildDir}, which gets created when relinking during Build. This is likely a test authoring error");
else
Assert.False(File.Exists(Path.Combine(objBuildDir, "emcc-link.rsp")), $"Found unexpected `emcc-link.rsp` in {objBuildDir}, which gets created when relinking during Build.");
Expand All @@ -165,88 +174,45 @@ protected string CreateProjectWithNativeReference(string id)

// Keeping these methods with explicit Build/Publish in the name
// so in the test code it is evident which is being run!
public Task BlazorRunForBuildWithDotnetRun(BlazorRunOptions runOptions)
=> BlazorRunTest(runOptions with { Host = BlazorRunHost.DotnetRun });
public async Task<RunResult> BlazorRunForBuildWithDotnetRun(RunOptions runOptions)
=> await BlazorRunTest(runOptions with { Host = RunHost.DotnetRun });

public Task BlazorRunForPublishWithWebServer(BlazorRunOptions runOptions)
=> BlazorRunTest(runOptions with { Host = BlazorRunHost.WebServer });
public async Task<RunResult> BlazorRunForPublishWithWebServer(RunOptions runOptions)
=> await BlazorRunTest(runOptions with { Host = RunHost.WebServer });

public Task BlazorRunTest(BlazorRunOptions runOptions) => runOptions.Host switch
public async Task<RunResult> BlazorRunTest(RunOptions runOptions)
{
BlazorRunHost.DotnetRun =>
BlazorRunTest($"run -c {runOptions.Config} --no-build", _projectDir!, runOptions),

BlazorRunHost.WebServer =>
BlazorRunTest($"{s_xharnessRunnerCommand} wasm webserver --app=. --web-server-use-default-files",
Path.GetFullPath(Path.Combine(FindBlazorBinFrameworkDir(runOptions.Config, forPublish: true), "..")),
runOptions),

_ => throw new NotImplementedException(runOptions.Host.ToString())
};

public async Task BlazorRunTest(string runArgs,
string workingDirectory,
BlazorRunOptions runOptions)
{
if (!string.IsNullOrEmpty(runOptions.ExtraArgs))
runArgs += $" {runOptions.ExtraArgs}";

runOptions.ServerEnvironment?.ToList().ForEach(
kv => s_buildEnv.EnvVars[kv.Key] = kv.Value);

using RunCommand runCommand = new RunCommand(s_buildEnv, _testOutput);
ToolCommand cmd = runCommand.WithWorkingDirectory(workingDirectory);

await using var runner = new BrowserRunner(_testOutput);
var page = await runner.RunAsync(
cmd,
runArgs,
onConsoleMessage: OnConsoleMessage,
onServerMessage: runOptions.OnServerMessage,
onError: OnErrorMessage,
modifyBrowserUrl: browserUrl => new Uri(new Uri(browserUrl), runOptions.BrowserPath + runOptions.QueryString).ToString());

_testOutput.WriteLine("Waiting for page to load");
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded, new () { Timeout = 1 * 60 * 1000 });

if (runOptions.CheckCounter)
if (runOptions.ExecuteAfterLoaded is null)
{
await page.Locator("text=Counter").ClickAsync();
var txt = await page.Locator("p[role='status']").InnerHTMLAsync();
Assert.Equal("Current count: 0", txt);

await page.Locator("text=\"Click me\"").ClickAsync();
await Task.Delay(300);
txt = await page.Locator("p[role='status']").InnerHTMLAsync();
Assert.Equal("Current count: 1", txt);
runOptions = runOptions with { ExecuteAfterLoaded = async (runOptions, page) =>
{
if (runOptions.CheckCounter)
{
await page.Locator("text=Counter").ClickAsync();
var txt = await page.Locator("p[role='status']").InnerHTMLAsync();
Assert.Equal("Current count: 0", txt);

await page.Locator("text=\"Click me\"").ClickAsync();
await Task.Delay(300);
txt = await page.Locator("p[role='status']").InnerHTMLAsync();
Assert.Equal("Current count: 1", txt);
}
}
};
}

if (runOptions.Test is not null)
await runOptions.Test(page);

_testOutput.WriteLine($"Waiting for additional 10secs to see if any errors are reported");
await Task.Delay(10_000);

void OnConsoleMessage(IPage page, IConsoleMessage msg)
{
_testOutput.WriteLine($"[{msg.Type}] {msg.Text}");

runOptions.OnConsoleMessage?.Invoke(page, msg);

if (runOptions.DetectRuntimeFailures)
{
if (msg.Text.Contains("[MONO] * Assertion") || msg.Text.Contains("Error: [MONO] "))
throw new XunitException($"Detected a runtime failure at line: {msg.Text}");
}
}

void OnErrorMessage(string msg)
switch (runOptions.Host)
{
_testOutput.WriteLine($"[ERROR] {msg}");
runOptions.OnErrorMessage?.Invoke(msg);
case RunHost.DotnetRun:
return await BrowserRunTest($"run -c {runOptions.Configuration} --no-build", _projectDir!, runOptions);
case RunHost.WebServer:
return await BrowserRunTest($"{s_xharnessRunnerCommand} wasm webserver --app=. --web-server-use-default-files",
Path.GetFullPath(Path.Combine(GetBlazorBinFrameworkDir(runOptions.Configuration, forPublish: true), "..")),
runOptions);
default:
throw new NotImplementedException(runOptions.Host.ToString());
}
}

public string FindBlazorBinFrameworkDir(string config, bool forPublish, string framework = DefaultTargetFrameworkForBlazor, string? projectDir = null)
=> _provider.FindBinFrameworkDir(config: config, forPublish: forPublish, framework: framework, projectDir: projectDir);
public string GetBlazorBinFrameworkDir(string config, bool forPublish, string framework = DefaultTargetFrameworkForBlazor, string? projectDir = null)
=> _provider.GetBinFrameworkDir(config: config, forPublish: forPublish, framework: framework, projectDir: projectDir);
}
Loading