-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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] Wasm.Build.Tests - some refactoring, and rationalizing #88357
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
57a47bb
WBT: Add new TestOutputWrapper for ITestOutputHelper
radical 74ea3c1
WBT: Fix local runs for no-workload case
radical 0354e61
Add AssertTestMainJsAppBundleOptions
radical 7e39d6e
WasmTemplateTests - use BuildTemplateProject
radical 487bcad
Add BlazorWasmProjectProvider
radical f5b5a1d
cleanup
radical 0224289
Improve checks for `dotnet*` files in output bundles
radical 9abdcab
Merge remote-tracking branch 'origin/main' into wbt-cleanup
radical 09c1e42
fix build
radical ae5cf3d
cleanup
radical b2897a1
Merge remote-tracking branch 'origin/main' into wbt-cleanup
radical 60b7bdc
[wasm] Remove net5.0 projects. Future PRs will add net6/7 projects
radical File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/mono/wasm/Wasm.Build.Tests/BlazorWasmProjectProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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.Data; | ||
using System.IO; | ||
using System.Linq; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using System.Runtime.Serialization.Json; | ||
using Microsoft.NET.Sdk.WebAssembly; | ||
using System.Text.Json.Nodes; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public class BlazorWasmProjectProvider(string projectDir, ITestOutputHelper _testOutput) | ||
: ProjectProviderBase(projectDir, _testOutput) | ||
{ | ||
public void AssertBlazorBootJson(string config, bool isPublish, bool isNet7AndBelow, string targetFramework, string? binFrameworkDir) | ||
{ | ||
binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework); | ||
|
||
string bootJsonPath = Path.Combine(binFrameworkDir, "blazor.boot.json"); | ||
Assert.True(File.Exists(bootJsonPath), $"Expected to find {bootJsonPath}"); | ||
|
||
string bootJson = File.ReadAllText(bootJsonPath); | ||
var bootJsonNode = JsonNode.Parse(bootJson); | ||
var runtimeObj = bootJsonNode?["resources"]?["runtime"]?.AsObject(); | ||
Assert.NotNull(runtimeObj); | ||
|
||
string msgPrefix = $"[{(isPublish ? "publish" : "build")}]"; | ||
Assert.True(runtimeObj!.Where(kvp => kvp.Key == (isNet7AndBelow ? "dotnet.wasm" : "dotnet.native.wasm")).Any(), $"{msgPrefix} Could not find dotnet.native.wasm entry in blazor.boot.json"); | ||
Assert.True(runtimeObj!.Where(kvp => kvp.Key.StartsWith("dotnet.", StringComparison.OrdinalIgnoreCase) && | ||
kvp.Key.EndsWith(".js", StringComparison.OrdinalIgnoreCase)).Any(), | ||
$"{msgPrefix} Could not find dotnet.*js in {bootJson}"); | ||
} | ||
|
||
public static BootJsonData ParseBootData(Stream stream) | ||
{ | ||
stream.Position = 0; | ||
var serializer = new DataContractJsonSerializer( | ||
typeof(BootJsonData), | ||
new DataContractJsonSerializerSettings { UseSimpleDictionaryFormat = true }); | ||
|
||
var config = (BootJsonData?)serializer.ReadObject(stream); | ||
Assert.NotNull(config); | ||
return config; | ||
} | ||
|
||
public string FindBlazorBinFrameworkDir(string config, bool forPublish, string framework) | ||
{ | ||
string basePath = Path.Combine(ProjectDir, "bin", config, framework); | ||
if (forPublish) | ||
basePath = FindSubDirIgnoringCase(basePath, "publish"); | ||
|
||
return Path.Combine(basePath, "wwwroot", "_framework"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public abstract class ProjectProviderBase(string projectDir, ITestOutputHelper output) | ||
{ | ||
protected const string s_dotnetVersionHashRegex = @"\.(?<version>.+)\.(?<hash>[a-zA-Z0-9]+)\."; | ||
|
||
public ITestOutputHelper TestOutput { get; init; } = output; | ||
public string ProjectDir { get; init; } = projectDir; | ||
|
||
public static string FindSubDirIgnoringCase(string parentDir, string dirName) | ||
{ | ||
IEnumerable<string> matchingDirs = Directory.EnumerateDirectories(parentDir, | ||
dirName, | ||
new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive }); | ||
|
||
string? first = matchingDirs.FirstOrDefault(); | ||
if (matchingDirs.Count() > 1) | ||
throw new Exception($"Found multiple directories with names that differ only in case. {string.Join(", ", matchingDirs.ToArray())}"); | ||
|
||
return first ?? Path.Combine(parentDir, dirName); | ||
} | ||
|
||
public static bool ShouldCheckFingerprint(string expectedFilename, bool expectFingerprintOnDotnetJs, bool expectFingerprintForThisFile) => | ||
(expectedFilename == "dotnet.js" && expectFingerprintOnDotnetJs) || expectFingerprintForThisFile; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blazor boot json schema is now shared with WasmAppBuilder. We should do the same check for every app bundle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that will in the follow up PRs. I'm trying to keep the changes to a minimum, like here the essential change is the check for dotnet files. The next one will add some new test classes and mostly move code around. And the one after that can then cleanly move the templates to wasm-sdk. Followed up multithreaded tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the same thing is needed for checking icu files.