diff options
Diffstat (limited to 'src/Components/WebAssembly/Build/test/BuildIntegrationTests/BuildCompressionTests.cs')
-rw-r--r-- | src/Components/WebAssembly/Build/test/BuildIntegrationTests/BuildCompressionTests.cs | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/Components/WebAssembly/Build/test/BuildIntegrationTests/BuildCompressionTests.cs b/src/Components/WebAssembly/Build/test/BuildIntegrationTests/BuildCompressionTests.cs index 5c2e8e9c8e..f1e6ea85e7 100644 --- a/src/Components/WebAssembly/Build/test/BuildIntegrationTests/BuildCompressionTests.cs +++ b/src/Components/WebAssembly/Build/test/BuildIntegrationTests/BuildCompressionTests.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -41,6 +42,45 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build } [Fact] + public async Task Build_WithLinkerAndCompression_UpdatesFilesWhenSourcesChange() + { + // Arrange + using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" }); + var result = await MSBuildProcessManager.DotnetMSBuild(project); + + Assert.BuildPassed(result); + + var mainAppDll = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll"); + var mainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + var mainAppCompressedDll = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll.gz"); + var mainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + + var blazorBootJson = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json"); + var blazorBootJsonThumbPrint = FileThumbPrint.Create(blazorBootJson); + var blazorBootJsonCompressed = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "blazor.boot.json.gz"); + var blazorBootJsonCompressedThumbPrint = FileThumbPrint.Create(blazorBootJsonCompressed); + + // Act + var programFile = Path.Combine(project.DirectoryPath, "Program.cs"); + var programFileContents = File.ReadAllText(programFile); + File.WriteAllText(programFile, programFileContents.Replace("args", "arguments")); + result = await MSBuildProcessManager.DotnetMSBuild(project); + + // Assert + Assert.BuildPassed(result); + var newMainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + var newMainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + var newBlazorBootJsonThumbPrint = FileThumbPrint.Create(blazorBootJson); + var newBlazorBootJsonCompressedThumbPrint = FileThumbPrint.Create(blazorBootJsonCompressed); + + Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); + Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); + + Assert.NotEqual(blazorBootJsonThumbPrint, newBlazorBootJsonThumbPrint); + Assert.NotEqual(blazorBootJsonCompressedThumbPrint, newBlazorBootJsonCompressedThumbPrint); + } + + [Fact] public async Task Build_WithoutLinkerAndCompression_IsIncremental() { // Arrange @@ -71,6 +111,34 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build } [Fact] + public async Task Build_WithoutLinkerAndCompression_UpdatesFilesWhenSourcesChange() + { + // Arrange + using var project = ProjectDirectory.Create("standalone", additionalProjects: new[] { "razorclasslibrary" }); + var result = await MSBuildProcessManager.DotnetMSBuild(project, args: "/p:BlazorWebAssemblyEnableLinking=false"); + + // Act + var mainAppDll = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll"); + var mainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + + var mainAppCompressedDll = Path.Combine(project.DirectoryPath, project.BuildOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll.gz"); + var mainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + + var programFile = Path.Combine(project.DirectoryPath, "Program.cs"); + var programFileContents = File.ReadAllText(programFile); + File.WriteAllText(programFile, programFileContents.Replace("args", "arguments")); + + // Assert + result = await MSBuildProcessManager.DotnetMSBuild(project, args: "/p:BlazorWebAssemblyEnableLinking=false"); + Assert.BuildPassed(result); + var newMainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + var newMainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + + Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); + Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); + } + + [Fact] public async Task Build_CompressesAllFrameworkFiles() { // Arrange @@ -148,6 +216,77 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build } [Fact] + public async Task Publish_WithLinkerAndCompression_UpdatesFilesWhenSourcesChange() + { + // Arrange + using var project = ProjectDirectory.Create("blazorhosted", additionalProjects: new[] { "standalone", "razorclasslibrary" }); + project.TargetFramework = "netcoreapp3.1"; + var result = await MSBuildProcessManager.DotnetMSBuild(project, target: "publish"); + + Assert.BuildPassed(result); + + // Act + var mainAppDll = Path.Combine(project.DirectoryPath, project.PublishOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll"); + var mainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + var mainAppCompressedDll = Path.Combine(project.DirectoryPath, project.PublishOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll.br"); + var mainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + + var blazorBootJson = Path.Combine(project.DirectoryPath, project.PublishOutputDirectory, "wwwroot", "_framework", "blazor.boot.json"); + var blazorBootJsonThumbPrint = FileThumbPrint.Create(blazorBootJson); + var blazorBootJsonCompressed = Path.Combine(project.DirectoryPath, project.PublishOutputDirectory, "wwwroot", "_framework", "blazor.boot.json.br"); + var blazorBootJsonCompressedThumbPrint = FileThumbPrint.Create(blazorBootJsonCompressed); + + var programFile = Path.Combine(project.DirectoryPath, "..", "standalone", "Program.cs"); + var programFileContents = File.ReadAllText(programFile); + File.WriteAllText(programFile, programFileContents.Replace("args", "arguments")); + + // Assert + result = await MSBuildProcessManager.DotnetMSBuild(project, target: "publish"); + Assert.BuildPassed(result); + var newMainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + var newMainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + var newBlazorBootJsonThumbPrint = FileThumbPrint.Create(blazorBootJson); + var newBlazorBootJsonCompressedThumbPrint = FileThumbPrint.Create(blazorBootJsonCompressed); + + Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); + Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); + + Assert.NotEqual(blazorBootJsonThumbPrint, newBlazorBootJsonThumbPrint); + Assert.NotEqual(blazorBootJsonCompressedThumbPrint, newBlazorBootJsonCompressedThumbPrint); + } + + [Fact] + public async Task Publish_WithoutLinkerAndCompression_UpdatesFilesWhenSourcesChange() + { + // Arrange + using var project = ProjectDirectory.Create("blazorhosted", additionalProjects: new[] { "standalone", "razorclasslibrary" }); + project.TargetFramework = "netcoreapp3.1"; + var result = await MSBuildProcessManager.DotnetMSBuild(project, target: "publish", args: "/p:BlazorWebAssemblyEnableLinking=false"); + + Assert.BuildPassed(result); + + // Act + var mainAppDll = Path.Combine(project.DirectoryPath, project.PublishOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll"); + var mainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + + var mainAppCompressedDll = Path.Combine(project.DirectoryPath, project.PublishOutputDirectory, "wwwroot", "_framework", "_bin", "standalone.dll.br"); + var mainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + + var programFile = Path.Combine(project.DirectoryPath, "..", "standalone", "Program.cs"); + var programFileContents = File.ReadAllText(programFile); + File.WriteAllText(programFile, programFileContents.Replace("args", "arguments")); + + // Assert + result = await MSBuildProcessManager.DotnetMSBuild(project, target: "publish", args: "/p:BlazorWebAssemblyEnableLinking=false"); + Assert.BuildPassed(result); + var newMainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); + var newMainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); + + Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); + Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); + } + + [Fact] public async Task Publish_WithLinkerAndCompression_IsIncremental() { // Arrange |