Skip to content

Commit

Permalink
Fix tests, use property for extensibility
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercn committed Aug 7, 2021
1 parent a8661b5 commit 720d8d2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<ResolvePublishStaticWebAssetsDependsOn>
$(ResolvePublishStaticWebAssetsDependsOn);
ProcessPublishFilesForBlazor;
ComputeBlazorExtensionAssets;
ComputeBlazorExtensions;
_AddPublishBlazorBootJsonToStaticWebAssets;
</ResolvePublishStaticWebAssetsDependsOn>

Expand Down Expand Up @@ -465,10 +465,12 @@ Copyright (c) .NET Foundation. All rights reserved.
(('%(StaticWebAsset.AssetTraitName)' == 'BlazorWebAssemblyResource' and '%(StaticWebAsset.AssetTraitValue)' != 'manifest' and '%(StaticWebAsset.AssetTraitValue)' != 'boot') or
'%(StaticWebAsset.AssetTraitName)' == 'Culture')" />
</ItemGroup>

</Target>

<Target Name="ComputeBlazorExtensionAssets">
<Target
Name="ComputeBlazorExtensions"
AfterTargets="ProcessPublishFilesForBlazor"
DependsOnTargets="$(ComputeBlazorExtensionsDependsOn)" >
<ItemGroup>
<_BlazorExtensionsCandidate Include="@(BlazorPublishExtension->'%(FullPath)')">
<SourceId>$(PackageId)</SourceId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Build_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonM
var outputPath = build.GetOutputDirectory(DefaultTfm).ToString();
var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
new FileInfo(path).Should().Exist();
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
AssertManifest(manifest, LoadBuildManifest());
Expand Down Expand Up @@ -68,7 +68,7 @@ public void JSModules_ManifestIncludesModuleTargetPaths()
var outputPath = build.GetOutputDirectory(DefaultTfm).ToString();
var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
new FileInfo(path).Should().Exist();
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
AssertManifest(manifest, LoadBuildManifest());
Expand Down Expand Up @@ -103,7 +103,7 @@ public void Publish_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJso
var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString();
var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
new FileInfo(path).Should().Exist();
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
AssertManifest(manifest, LoadPublishManifest());
Expand Down Expand Up @@ -155,7 +155,7 @@ public void JsModules_CanHaveDifferentBuildAndPublishModules()
var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString();
var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
new FileInfo(path).Should().Exist();
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
AssertManifest(manifest, LoadPublishManifest());
Expand Down Expand Up @@ -199,20 +199,25 @@ public void JsModules_CanCustomizeBlazorInitialization()

ProjectDirectory.WithProjectChanges(document =>
{
document.Root.Add(XElement.Parse(@"
<Target Name=""_CustomizeBlazorBootProcess"" AfterTargets=""ProcessPublishFilesForBlazor"" BeforeTargets=""ComputeBlazorExtensionAssets"">
document.Root.Add(
XElement.Parse(@"
<PropertyGroup>
<ComputeBlazorExtensionsDependsOn>$(ComputeBlazorExtensionsDependsOn);_CustomizeBlazorBootProcess</ComputeBlazorExtensionsDependsOn>
</PropertyGroup>"),
XElement.Parse(@"
<Target Name=""_CustomizeBlazorBootProcess"">
<ItemGroup>
<BlazorPublishExtension Include=""$(IntermediateOutputPath)publish.extension.txt"">
<ExtensionName>my-custom-extension</ExtensionName>
<RelativePath>_bin/publish.extension.txt</RelativePath>
</BlazorPublishExtension>
<FileWrites Include=""$(IntermediateOutputPath)publish.extension.txt"" />
<BlazorPublishExtension Include=""$(IntermediateOutputPath)publish.extension.txt"">
<ExtensionName>my-custom-extension</ExtensionName>
<RelativePath>_bin/publish.extension.txt</RelativePath>
</BlazorPublishExtension>
<FileWrites Include=""$(IntermediateOutputPath)publish.extension.txt"" />
</ItemGroup>
<WriteLinesToFile
Lines=""@(_BlazorBootFilesToUpdate->'%(FullPath)')""
File=""$(IntermediateOutputPath)publish.extension.txt""
WriteOnlyWhenDifferent=""true"" />
Lines=""@(_BlazorBootFilesToUpdate->'%(FullPath)')""
File=""$(IntermediateOutputPath)publish.extension.txt""
WriteOnlyWhenDifferent=""true"" />
</Target>"));
});

Expand All @@ -224,7 +229,7 @@ public void JsModules_CanCustomizeBlazorInitialization()
var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString();
var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
new FileInfo(path).Should().Exist();
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
AssertManifest(manifest, LoadPublishManifest());
Expand Down Expand Up @@ -271,22 +276,27 @@ public void JsModules_Hosted_CanCustomizeBlazorInitialization()
{
if (Path.GetFileNameWithoutExtension(path) == "blazorwasm")
{
document.Root.Add(XElement.Parse(@"
<Target Name=""_CustomizeBlazorBootProcess"" AfterTargets=""ProcessPublishFilesForBlazor"" BeforeTargets=""ComputeBlazorExtensionAssets"">
document.Root.Add(
XElement.Parse(@"
<PropertyGroup>
<ComputeBlazorExtensionsDependsOn>$(ComputeBlazorExtensionsDependsOn);_CustomizeBlazorBootProcess</ComputeBlazorExtensionsDependsOn>
</PropertyGroup>"),
XElement.Parse(@"
<Target Name=""_CustomizeBlazorBootProcess"">
<ItemGroup>
<BlazorPublishExtension Include=""$(IntermediateOutputPath)publish.extension.txt"">
<ExtensionName>my-custom-extension</ExtensionName>
<RelativePath>_bin/publish.extension.txt</RelativePath>
</BlazorPublishExtension>
<FileWrites Include=""$(IntermediateOutputPath)publish.extension.txt"" />
<BlazorPublishExtension Include=""$(IntermediateOutputPath)publish.extension.txt"">
<ExtensionName>my-custom-extension</ExtensionName>
<RelativePath>_bin/publish.extension.txt</RelativePath>
</BlazorPublishExtension>
<FileWrites Include=""$(IntermediateOutputPath)publish.extension.txt"" />
</ItemGroup>
<WriteLinesToFile
Lines=""@(_BlazorBootFilesToUpdate->'%(FullPath)')""
File=""$(IntermediateOutputPath)publish.extension.txt""
WriteOnlyWhenDifferent=""true"" />
Lines=""@(_BlazorBootFilesToUpdate->'%(FullPath)')""
File=""$(IntermediateOutputPath)publish.extension.txt""
WriteOnlyWhenDifferent=""true"" />
</Target>"));
}
}
});

var publish = new PublishCommand(ProjectDirectory, "blazorhosted");
Expand All @@ -297,7 +307,7 @@ public void JsModules_Hosted_CanCustomizeBlazorInitialization()
var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString();
var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
new FileInfo(path).Should().Exist();
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
AssertManifest(manifest, LoadPublishManifest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void Publish_PublishesBundleToTheRightLocation()
var outputPath = publish.GetOutputDirectory(DefaultTfm).ToString();
var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
new FileInfo(path).Should().Exist();
var manifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));
AssertManifest(manifest, LoadPublishManifest());
Expand Down Expand Up @@ -281,12 +281,12 @@ public void PublishProjectWithReferences_IncorporatesInitializersFromClassLibrar
var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
var outputPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json");
var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json");
AssertManifest(
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path)),
LoadBuildManifest());

var finalPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json");
var finalPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
AssertManifest(
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)),
LoadPublishManifest());
Expand Down Expand Up @@ -331,7 +331,7 @@ public void PublishProjectWithReferences_DifferentBuildAndPublish_LibraryInitial
var intermediateOutputPath = publish.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
var outputPath = publish.GetOutputDirectory(DefaultTfm, "Debug").ToString();

var path = Path.Combine(intermediateOutputPath, "StaticWebAssets.build.json"); ;
var path = Path.Combine(intermediateOutputPath, "staticwebassets.build.json"); ;
var buildManifest = StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(path));

var initializers = buildManifest.Assets.Where(a => a.RelativePath == "AnotherClassLib.lib.module.js");
Expand All @@ -342,7 +342,7 @@ public void PublishProjectWithReferences_DifferentBuildAndPublish_LibraryInitial
buildManifest,
LoadBuildManifest());

var finalPath = Path.Combine(intermediateOutputPath, "StaticWebAssets.publish.json");
var finalPath = Path.Combine(intermediateOutputPath, "staticwebassets.publish.json");
AssertManifest(
StaticWebAssetsManifest.FromJsonBytes(File.ReadAllBytes(finalPath)),
LoadPublishManifest());
Expand Down

0 comments on commit 720d8d2

Please sign in to comment.