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

[wasm] Add test for blazor/sdk fix for lazy loaded assemblies #60673

Merged
merged 5 commits into from
Nov 5, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

#nullable enable

Expand Down Expand Up @@ -225,6 +227,56 @@ void CheckNativeFileLinked(bool forPublish)
}
}

[ConditionalFact(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
public void BugRegression_60479_WithRazorClassLib()
{
string id = "blz_razor_lib_top";
InitBlazorWasmProjectDir(id);

string wasmProjectDir = Path.Combine(_projectDir!, "wasm");
string wasmProjectFile = Path.Combine(wasmProjectDir, "wasm.csproj");
Directory.CreateDirectory(wasmProjectDir);
new DotNetCommand(s_buildEnv, useDefaultArgs: false)
.WithWorkingDirectory(wasmProjectDir)
.ExecuteWithCapturedOutput("new blazorwasm")
.EnsureSuccessful();


string razorProjectDir = Path.Combine(_projectDir!, "RazorClassLibrary");
Directory.CreateDirectory(razorProjectDir);
new DotNetCommand(s_buildEnv, useDefaultArgs: false)
.WithWorkingDirectory(razorProjectDir)
.ExecuteWithCapturedOutput("new razorclasslib")
.EnsureSuccessful();

AddItemsPropertiesToProject(wasmProjectFile, extraItems:@"
<ProjectReference Include=""..\RazorClassLibrary\RazorClassLibrary.csproj"" />
<BlazorWebAssemblyLazyLoad Include=""RazorClassLibrary.dll"" />
");

_projectDir = wasmProjectDir;
string config = "Release";
// No relinking, no AOT
BlazorBuild(id, config, NativeFilesType.FromRuntimePack);

// will relink
BlazorPublish(id, config, NativeFilesType.Relinked);

// publish/wwwroot/_framework/blazor.boot.json
string frameworkDir = FindBlazorBinFrameworkDir(config, forPublish: true);
string bootJson = Path.Combine(frameworkDir, "blazor.boot.json");

Assert.True(File.Exists(bootJson), $"Could not find {bootJson}");
var jdoc = JsonDocument.Parse(File.ReadAllText(bootJson));
if (!jdoc.RootElement.TryGetProperty("resources", out JsonElement resValue) ||
!resValue.TryGetProperty("lazyAssembly", out JsonElement lazyVal))
{
throw new XunitException($"Could not find resources.lazyAssembly object in {bootJson}");
}

Assert.Contains("RazorClassLibrary.dll", lazyVal.EnumerateObject().Select(jp => jp.Name));
}

private string CreateProjectWithNativeReference(string id)
{
CreateBlazorWasmTemplateProject(id);
Expand Down