-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wasm] Wasm.Build.Tests - some refactoring, and rationalizing (#88357)
- Loading branch information
Showing
19 changed files
with
661 additions
and
322 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/mono/wasm/Wasm.Build.Tests/AssertTestMainJsAppBundleOptions.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,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public record AssertTestMainJsAppBundleOptions | ||
( | ||
string BundleDir, | ||
string ProjectName, | ||
string Config, | ||
string MainJS, | ||
bool HasV8Script, | ||
GlobalizationMode? GlobalizationMode, | ||
string PredefinedIcudt = "", | ||
bool UseWebcil = true, | ||
bool IsBrowserProject = true, | ||
bool IsPublish = false | ||
); |
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
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
88 changes: 88 additions & 0 deletions
88
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,88 @@ | ||
// 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; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public class BlazorWasmProjectProvider(string projectDir, ITestOutputHelper testOutput) | ||
: WasmSdkBasedProjectProvider(projectDir, testOutput) | ||
{ | ||
public void AssertBlazorBootJson( | ||
string binFrameworkDir, | ||
bool expectFingerprintOnDotnetJs = false, | ||
bool isPublish = false, | ||
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded) | ||
{ | ||
string bootJsonPath = Path.Combine(binFrameworkDir, "blazor.boot.json"); | ||
Assert.True(File.Exists(bootJsonPath), $"Expected to find {bootJsonPath}"); | ||
|
||
BootJsonData bootJson = ParseBootData(bootJsonPath); | ||
var bootJsonEntries = bootJson.resources.runtime.Keys.Where(k => k.StartsWith("dotnet.", StringComparison.Ordinal)).ToArray(); | ||
|
||
var expectedEntries = new SortedDictionary<string, Action<string>>(); | ||
IReadOnlySet<string> expected = GetDotNetFilesExpectedSet(runtimeType, isPublish); | ||
|
||
var knownSet = GetAllKnownDotnetFilesToFingerprintMap(runtimeType); | ||
foreach (string expectedFilename in expected) | ||
{ | ||
if (Path.GetExtension(expectedFilename) == ".map") | ||
continue; | ||
|
||
bool expectFingerprint = knownSet[expectedFilename]; | ||
expectedEntries[expectedFilename] = item => | ||
{ | ||
string prefix = Path.GetFileNameWithoutExtension(expectedFilename); | ||
string extension = Path.GetExtension(expectedFilename).Substring(1); | ||
|
||
if (ShouldCheckFingerprint(expectedFilename: expectedFilename, | ||
expectFingerprintOnDotnetJs: expectFingerprintOnDotnetJs, | ||
expectFingerprintForThisFile: expectFingerprint)) | ||
{ | ||
Assert.Matches($"{prefix}{s_dotnetVersionHashRegex}{extension}", item); | ||
} | ||
else | ||
{ | ||
Assert.Equal(expectedFilename, item); | ||
} | ||
|
||
string absolutePath = Path.Combine(binFrameworkDir, item); | ||
Assert.True(File.Exists(absolutePath), $"Expected to find '{absolutePath}'"); | ||
}; | ||
} | ||
// FIXME: maybe use custom code so the details can show up in the log | ||
Assert.Collection(bootJsonEntries.Order(), expectedEntries.Values.ToArray()); | ||
} | ||
|
||
public static BootJsonData ParseBootData(string bootJsonPath) | ||
{ | ||
using FileStream stream = File.OpenRead(bootJsonPath); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public record BuildProjectOptions | ||
( | ||
Action? InitProject = null, | ||
bool? DotnetWasmFromRuntimePack = null, | ||
GlobalizationMode? GlobalizationMode = null, | ||
string? PredefinedIcudt = null, | ||
bool UseCache = true, | ||
bool ExpectSuccess = true, | ||
bool AssertAppBundle = true, | ||
bool CreateProject = true, | ||
bool Publish = true, | ||
bool BuildOnlyAfterPublish = true, | ||
bool HasV8Script = true, | ||
string? Verbosity = null, | ||
string? Label = null, | ||
string? TargetFramework = null, | ||
string? MainJS = null, | ||
bool IsBrowserProject = true, | ||
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null | ||
); |
Oops, something went wrong.