Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<MicrosoftExtensionsLoggingVersion>3.1.7</MicrosoftExtensionsLoggingVersion>
<MicrosoftSymbolStoreVersion>1.0.406601</MicrosoftSymbolStoreVersion>
<!-- sdk version, for testing workloads -->
<SdkVersionForWorkloadTesting>$(MicrosoftDotNetApiCompatTaskVersion)</SdkVersionForWorkloadTesting>
<SdkVersionForWorkloadTesting>10.0.100-rtm.25508.107</SdkVersionForWorkloadTesting>
<EmsdkPackageVersion>10.0.0-preview.7.25359.101</EmsdkPackageVersion>
<NodePackageVersion>$(runtimewinx64MicrosoftNETCoreRuntimeWasmNodeTransportPackageVersion)</NodePackageVersion>
<!-- The package path for python in src/mono/mono.proj needs to be updated if this changes-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,13 @@ Copyright (c) .NET Foundation. All rights reserved.
</Target>

<Target Name="_AddWasmPreloadBuildProperties" DependsOnTargets="_WasmConfigurePreload;_AddWasmStaticWebAssets" BeforeTargets="GenerateStaticWebAssetsManifest" Condition="'$(_WasmPreloadAssets)' == 'true'">
<PropertyGroup>
<_WasmBootConfigFileNameWithoutExtension>$([System.IO.Path]::GetFileNameWithoutExtension('$(_WasmBootConfigFileName)'))</_WasmBootConfigFileNameWithoutExtension>
<_WasmBootConfigFileExtension>$([System.IO.Path]::GetExtension('$(_WasmBootConfigFileName)'))</_WasmBootConfigFileExtension>
</PropertyGroup>
<ItemGroup>
<_WasmPreloadBuildScriptAsset Include="@(StaticWebAsset)" Condition="'%(AssetKind)' != 'Publish' and '%(FileName)%(Extension)' == '$(_WasmBootConfigFileName)'" />
<_WasmPreloadBuildScriptAsset Include="@(StaticWebAsset)" Condition="'$(_WasmFingerprintAssets)' == 'true' and '$(_WasmFingerprintBootConfig)' == 'true' and '%(AssetKind)' != 'Publish' and '%(FileName)%(Extension)' == '$(_WasmBootConfigFileNameWithoutExtension).%(Fingerprint)$(_WasmBootConfigFileExtension)'" />
<_WasmPreloadBuildScriptAsset Include="@(StaticWebAsset)" Condition="('$(_WasmFingerprintAssets)' != 'true' or '$(_WasmFingerprintBootConfig)' != 'true') and '%(AssetKind)' != 'Publish' and '%(FileName)%(Extension)' == '$(_WasmBootConfigFileName)'" />
</ItemGroup>

<FilterStaticWebAssetEndpoints
Expand Down
54 changes: 40 additions & 14 deletions src/mono/wasm/Wasm.Build.Tests/PreloadingTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.IO;
using System.Linq;
using Xunit;
Expand All @@ -18,22 +19,26 @@ public PreloadingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture
}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void PreloadAssets(bool isPublish, bool fingerprintDotnetJs)
[InlineData(false, false, false)]
[InlineData(false, false, true)]
[InlineData(false, true, false)]
[InlineData(false, true, true)]
[InlineData(true, false, false)]
[InlineData(true, false, true)]
[InlineData(true, true, false)]
[InlineData(true, true, true)]
public void PreloadAssets(bool isPublish, bool fingerprintDotnetJs, bool preloadAssets)
{
Configuration config = Configuration.Debug;
ProjectInfo info = CopyTestAsset(config, aot: false, TestAsset.WasmBasicTestApp, "PreloadAssets");

string extraMSBuildArgs = $"-p:WasmFingerprintDotnetJs={fingerprintDotnetJs}";
string extraMSBuildArgs = $"-p:WasmFingerprintDotnetJs={fingerprintDotnetJs.ToString().ToLower()} -p:WasmPreloadAssets={preloadAssets.ToString().ToLower()}";
if (isPublish)
PublishProject(info, config, new PublishOptions(ExtraMSBuildArgs: extraMSBuildArgs), wasmFingerprintDotnetJs: fingerprintDotnetJs);
else
BuildProject(info, config, new BuildOptions(ExtraMSBuildArgs: extraMSBuildArgs), wasmFingerprintDotnetJs: fingerprintDotnetJs);

string? indexHtmlPath = null;
string? indexHtmlPath;
if (isPublish)
{
indexHtmlPath = Path.Combine(
Expand All @@ -51,16 +56,37 @@ public void PreloadAssets(bool isPublish, bool fingerprintDotnetJs)
Assert.True(File.Exists(indexHtmlPath));
string indexHtmlContent = File.ReadAllText(indexHtmlPath);

if (fingerprintDotnetJs)
Assert.Equal(preloadAssets ? 1 : 0, CountOccurrences(indexHtmlContent, "rel=\"preload\""));
if (preloadAssets)
{
// Expect to find fingerprinted preload
Assert.Contains("<link href=\"_framework/dotnet", indexHtmlContent);
Assert.DoesNotContain("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
if (fingerprintDotnetJs)
{
// Expect to find fingerprinted preload
Assert.Contains("<link href=\"_framework/dotnet", indexHtmlContent);
Assert.DoesNotContain("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
}
else
{
// Expect to find non-fingerprinted preload
Assert.Contains("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
}
}
else
}

public static int CountOccurrences(string source, string substring)
{
if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(substring))
return 0;

int count = 0;
int index = 0;

while ((index = source.IndexOf(substring, index, StringComparison.Ordinal)) != -1)
{
// Expect to find non-fingerprinted preload
Assert.Contains("<link href=\"_framework/dotnet.js\"", indexHtmlContent);
count++;
index += substring.Length;
}

return count;
}
}
Loading