Skip to content

Fix single-file static web assets tests #34186

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

Merged
merged 4 commits into from
Jul 24, 2023
Merged
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
15 changes: 7 additions & 8 deletions src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -172,7 +172,7 @@ protected void AssertPublishAssets(
string wwwRootFolder = Path.Combine(publishFolder, "wwwroot");
var wwwRootFiles = Directory.Exists(wwwRootFolder) ?
Directory.GetFiles(wwwRootFolder, "*", fileEnumerationOptions)
.Select(f => _baselineFactory.TemplatizeFilePath(f, null, null, intermediateOutputPath, publishFolder)) :
.Select(f => _baselineFactory.TemplatizeFilePath(f, null, null, intermediateOutputPath, publishFolder, null)) :
Array.Empty<string>();

// Computed publish assets must exist on disk (we do this check to quickly identify when something is not being
Expand Down Expand Up @@ -234,6 +234,7 @@ internal void AssertManifest(
StaticWebAssetsManifest manifest,
StaticWebAssetsManifest expected,
string suffix = "",
string runtimeIdentifier = null,
[CallerMemberName] string name = "")
{
if (!_generateBaselines)
Expand All @@ -244,15 +245,13 @@ internal void AssertManifest(
manifest,
ProjectDirectory.Path,
TestContext.Current.NuGetCachePath,
RuntimeVersion,
DefaultTfm,
DefaultPackageVersion);
runtimeIdentifier);

_comparer.AssertManifest(expected, manifest);
}
else
{
var template = Templatize(manifest, ProjectDirectory.Path, TestContext.Current.NuGetCachePath);
var template = Templatize(manifest, ProjectDirectory.Path, TestContext.Current.NuGetCachePath, runtimeIdentifier);
if (!Directory.Exists(Path.Combine(BaselinesFolder)))
{
Directory.CreateDirectory(Path.Combine(BaselinesFolder));
Expand All @@ -275,9 +274,9 @@ private string GetExpectedFilesPath(string suffix, string name, string manifestT
private Stream GetExpectedFilesEmbeddedResource(string suffix, string name, string manifestType)
=> TestAssembly.GetManifestResourceStream(string.Join('.', EmbeddedResourcePrefix, $"{name}{(!string.IsNullOrEmpty(suffix) ? $"_{suffix}" : "")}.{manifestType}.files.json"));

private string Templatize(StaticWebAssetsManifest manifest, string projectRoot, string restorePath)
private string Templatize(StaticWebAssetsManifest manifest, string projectRoot, string restorePath, string runtimeIdentifier)
{
_baselineFactory.ToTemplate(manifest, projectRoot, restorePath, RuntimeVersion, DefaultTfm, DefaultPackageVersion);
_baselineFactory.ToTemplate(manifest, projectRoot, restorePath, runtimeIdentifier);
return JsonSerializer.Serialize(manifest, BaselineSerializationOptions);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ public class StaticWebAssetsBaselineComparer
{
private static readonly string BaselineGenerationInstructions =
@"If the difference in baselines is expected, please re-generate the baselines.
Note, baseline generation must be done on a Windows device.
Start by ensuring you're dogfooding the SDK from the current branch (dotnet --version should be '*.0.0-dev').
If you're not on the dogfood sdk, from the root of the repository run:
1. dotnet clean
2. .\restore.cmd
3. .\build.cmd
4. .\eng\dogfood.cmd
2. .\restore.cmd or ./restore.sh
3. .\build.cmd ./build.sh
4. .\eng\dogfood.cmd or . ./eng/dogfood.sh

Then, using the dogfood SDK run the .\src\RazorSdk\update-test-baselines.ps1 script.";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -37,15 +37,13 @@ public void ToTemplate(
StaticWebAssetsManifest manifest,
string projectRoot,
string restorePath,
string runtimeVersion,
string defaultTfm,
string defaultPackageVersion)
string runtimeIdentifier)
{
manifest.Hash = "__hash__";
var assetsByIdentity = manifest.Assets.ToDictionary(a => a.Identity);
foreach (var asset in manifest.Assets)
{
TemplatizeAsset(projectRoot, restorePath, asset);
TemplatizeAsset(projectRoot, restorePath, runtimeIdentifier, asset);
if (asset.AssetTraitName == "Content-Encoding")
{
var relativePath = asset.RelativePath.Replace('/', Path.DirectorySeparatorChar);
Expand Down Expand Up @@ -89,42 +87,47 @@ public void ToTemplate(
Array.Sort(manifest.ReferencedProjectsConfiguration, (l, r) => StringComparer.Ordinal.Compare(l.Identity, r.Identity));
}

private void TemplatizeAsset(string projectRoot, string restorePath, StaticWebAsset asset)
private void TemplatizeAsset(string projectRoot, string restorePath, string runtimeIdentifier, StaticWebAsset asset)
{
asset.Identity = TemplatizeFilePath(
asset.Identity,
restorePath,
projectRoot,
null,
null);
null,
runtimeIdentifier);

asset.RelativePath = TemplatizeFilePath(
asset.RelativePath,
null,
null,
null,
null,
null).Replace('\\', '/');

asset.ContentRoot = TemplatizeFilePath(
asset.ContentRoot,
restorePath,
projectRoot,
null,
null);
null,
runtimeIdentifier);

asset.RelatedAsset = TemplatizeFilePath(
asset.RelatedAsset,
restorePath,
projectRoot,
null,
null,
null);

asset.OriginalItemSpec = TemplatizeFilePath(
asset.OriginalItemSpec,
restorePath,
projectRoot,
null,
null);
null,
runtimeIdentifier);
}

internal IEnumerable<string> TemplatizeExpectedFiles(
Expand All @@ -141,7 +144,8 @@ internal IEnumerable<string> TemplatizeExpectedFiles(
restorePath,
projectPath,
intermediateOutputPath,
buildOrPublishFolder);
buildOrPublishFolder,
null);

yield return updated;
}
Expand All @@ -152,7 +156,8 @@ public string TemplatizeFilePath(
string restorePath,
string projectPath,
string intermediateOutputPath,
string buildOrPublishFolder)
string buildOrPublishFolder,
string runtimeIdentifier)
{
var updated = file switch
{
Expand All @@ -164,7 +169,7 @@ var processed when file.StartsWith("$") => processed,
var fromPackage when restorePath is not null && file.StartsWith(restorePath) =>
TemplatizeNugetPath(restorePath, fromPackage),
var fromProject when projectPath is not null && file.StartsWith(projectPath) =>
TemplatizeProjectPath(projectPath, fromProject),
TemplatizeProjectPath(projectPath, fromProject, runtimeIdentifier),
_ =>
ReplaceSegments(file, (i, segments) => i switch
{
Expand Down Expand Up @@ -206,7 +211,7 @@ private string TemplatizeIntermediatePath(string intermediatePath, string file)
return file;
}

private string TemplatizeProjectPath(string projectPath, string file)
private string TemplatizeProjectPath(string projectPath, string file, string runtimeIdentifier)
{
file = file.Replace(projectPath, "${ProjectPath}")
.Replace('\\', '/');
Expand All @@ -215,6 +220,8 @@ private string TemplatizeProjectPath(string projectPath, string file)
{
3 when segments[1] is "obj" or "bin" => "${Tfm}",
4 when segments[2] is "obj" or "bin" => "${Tfm}",
4 when segments[1] is "obj" or "bin" && segments[4] == runtimeIdentifier => "${Rid}",
5 when segments[2] is "obj" or "bin" && segments[5] == runtimeIdentifier => "${Rid}",
_ when i == segments.Length - 1 => RemovePossibleHash(segments[i]),
_ => segments[i]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
"OriginalItemSpec": "wwwroot\\js\\project-direct-dep.js"
},
{
"Identity": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css",
"Identity": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css",
"SourceId": "AppWithPackageAndP2PReference",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\",
"ContentRoot": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\",
"BasePath": "_content/AppWithPackageAndP2PReference",
"RelativePath": "AppWithPackageAndP2PReference.styles.css",
"AssetKind": "All",
Expand All @@ -101,7 +101,7 @@
"AssetTraitValue": "ApplicationBundle",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css"
"OriginalItemSpec": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css"
},
{
"Identity": "${ProjectPath}\\ClassLibrary\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\ClassLibrary.bundle.scp.css",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
[
"${OutputPath}\\wwwroot\\AppWithPackageAndP2PReference.styles.css",
"${OutputPath}\\wwwroot\\_content\\AnotherClassLib\\css\\site.css",
"${OutputPath}\\wwwroot\\_content\\AnotherClassLib\\js\\project-direct-dep.js",
"${OutputPath}\\wwwroot\\_content\\ClassLibrary\\ClassLibrary.bundle.scp.css",
"${OutputPath}\\wwwroot\\_content\\ClassLibrary\\js\\project-transitive-dep.js",
"${OutputPath}\\wwwroot\\_content\\ClassLibrary\\js\\project-transitive-dep.v4.js",
"${OutputPath}\\wwwroot\\_content\\PackageLibraryDirectDependency\\PackageLibraryDirectDependency.bundle.scp.css",
"${OutputPath}\\wwwroot\\_content\\PackageLibraryDirectDependency\\css\\site.css",
"${OutputPath}\\wwwroot\\_content\\PackageLibraryDirectDependency\\js\\pkg-direct-dep.js",
"${OutputPath}\\wwwroot\\_content\\PackageLibraryTransitiveDependency\\js\\pkg-transitive-dep.js",
"${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css",
"${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css",
"${OutputPath}\\wwwroot\\AppWithPackageAndP2PReference.styles.css",
"${OutputPath}\\wwwroot\\_content\\AnotherClassLib\\css\\site.css",
"${OutputPath}\\wwwroot\\_content\\AnotherClassLib\\js\\project-direct-dep.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
"OriginalItemSpec": "wwwroot\\js\\project-direct-dep.js"
},
{
"Identity": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css",
"Identity": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css",
"SourceId": "AppWithPackageAndP2PReference",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\",
"ContentRoot": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\",
"BasePath": "_content/AppWithPackageAndP2PReference",
"RelativePath": "AppWithPackageAndP2PReference.styles.css",
"AssetKind": "All",
Expand All @@ -101,7 +101,7 @@
"AssetTraitValue": "ApplicationBundle",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css"
"OriginalItemSpec": "${ProjectPath}\\AppWithPackageAndP2PReference\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\AppWithPackageAndP2PReference.styles.css"
},
{
"Identity": "${ProjectPath}\\ClassLibrary\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\ClassLibrary.bundle.scp.css",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"DiscoveryPatterns": [],
"Assets": [
{
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\ComponentApp.styles.css",
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\ComponentApp.styles.css",
"SourceId": "ComponentApp",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\",
"BasePath": "_content/ComponentApp",
"RelativePath": "ComponentApp.styles.css",
"AssetKind": "All",
Expand All @@ -25,13 +25,13 @@
"AssetTraitValue": "ApplicationBundle",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\ComponentApp.styles.css"
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\ComponentApp.styles.css"
},
{
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css",
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css",
"SourceId": "ComponentApp",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\projectbundle\\",
"BasePath": "_content/ComponentApp",
"RelativePath": "ComponentApp.bundle.scp.css",
"AssetKind": "All",
Expand All @@ -44,7 +44,7 @@
"AssetTraitValue": "ProjectBundle",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css"
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[
"${OutputPath}\\wwwroot\\ComponentApp.styles.css",
"${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\ComponentApp.styles.css",
"${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css",
"${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\ComponentApp.styles.css",
"${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css",
"${OutputPath}\\wwwroot\\ComponentApp.styles.css"
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"DiscoveryPatterns": [],
"Assets": [
{
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\ComponentApp.styles.css",
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\ComponentApp.styles.css",
"SourceId": "ComponentApp",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\",
"BasePath": "_content/ComponentApp",
"RelativePath": "ComponentApp.styles.css",
"AssetKind": "All",
Expand All @@ -25,13 +25,13 @@
"AssetTraitValue": "ApplicationBundle",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\bundle\\ComponentApp.styles.css"
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\bundle\\ComponentApp.styles.css"
},
{
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css",
"Identity": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css",
"SourceId": "ComponentApp",
"SourceType": "Computed",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\",
"ContentRoot": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\projectbundle\\",
"BasePath": "_content/ComponentApp",
"RelativePath": "ComponentApp.bundle.scp.css",
"AssetKind": "All",
Expand All @@ -44,7 +44,7 @@
"AssetTraitValue": "ProjectBundle",
"CopyToOutputDirectory": "Never",
"CopyToPublishDirectory": "PreserveNewest",
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css"
"OriginalItemSpec": "${ProjectPath}\\obj\\Debug\\${Tfm}\\${Rid}\\scopedcss\\projectbundle\\ComponentApp.bundle.scp.css"
}
]
}
Loading