From ee2dbb87eb72367d8d180214c91324b2411b4169 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Fri, 9 Sep 2022 19:50:18 -0300 Subject: [PATCH 01/11] trying to fix 75356 --- src/mono/wasm/build/WasmApp.targets | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 1c5cb833874880..46fa0419017b9e 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -117,10 +117,7 @@ - <_AppBundleDirForRunCommand Condition="Exists('$(WasmAppDir)/$(AssemblyName).runtimeconfig.json')">$(WasmAppDir) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/browser-wasm/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">OutputPath=$(OutputPath), OutDir=$(OutDir) + <_AppBundleDirForRunCommand>$([MSBuild]::NormalizeDirectory($(OutputPath), 'AppBundle')) From 5388eba7fe94af0062fd31e9bcb6d38fdd6d4e06 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Fri, 9 Sep 2022 21:17:28 -0300 Subject: [PATCH 02/11] Trying to fix for running from VS and from command line --- src/mono/wasm/build/WasmApp.targets | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 46fa0419017b9e..9f0c807cd38ec9 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -117,7 +117,11 @@ - <_AppBundleDirForRunCommand>$([MSBuild]::NormalizeDirectory($(OutputPath), 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(MSBuildProjectDirectory)/$(OutputPath)/browser-wasm/AppBundle')">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath), 'browser-wasm', 'AppBundle')) + <_AppBundleDirForRunCommand Condition="Exists('$(WasmAppDir)/$(AssemblyName).runtimeconfig.json')">$(WasmAppDir) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/browser-wasm/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">OutputPath=$(OutputPath), OutDir=$(OutDir) From d461e7a2d60e10150f0c45646bf40685fbfc4b02 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Fri, 9 Sep 2022 21:17:57 -0300 Subject: [PATCH 03/11] Remove unused spaces --- src/mono/wasm/build/WasmApp.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 9f0c807cd38ec9..05f38f2776e8c6 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -121,7 +121,7 @@ <_AppBundleDirForRunCommand Condition="Exists('$(WasmAppDir)/$(AssemblyName).runtimeconfig.json')">$(WasmAppDir) <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'AppBundle')) <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/browser-wasm/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">OutputPath=$(OutputPath), OutDir=$(OutDir) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">OutputPath=$(OutputPath), OutDir=$(OutDir) From fa45fe50b40edc20f8118ed84024eb1e3c0ea6db Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Fri, 9 Sep 2022 21:36:37 -0300 Subject: [PATCH 04/11] Fix again --- src/mono/wasm/build/WasmApp.targets | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 05f38f2776e8c6..172bd5966f7d58 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -117,11 +117,7 @@ - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(MSBuildProjectDirectory)/$(OutputPath)/browser-wasm/AppBundle')">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath), 'browser-wasm', 'AppBundle')) - <_AppBundleDirForRunCommand Condition="Exists('$(WasmAppDir)/$(AssemblyName).runtimeconfig.json')">$(WasmAppDir) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists('$(OutputPath)/browser-wasm/AppBundle')">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">OutputPath=$(OutputPath), OutDir=$(OutDir) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath), 'browser-wasm', 'AppBundle')) From 43d69ffc3dff3df4492d588564d507a7eea36bef Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 12 Sep 2022 13:43:09 -0300 Subject: [PATCH 05/11] Addressing @radical comments --- src/mono/wasm/build/WasmApp.targets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 172bd5966f7d58..91e4c48547d6c0 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -117,7 +117,8 @@ - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath), 'browser-wasm', 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and !$([System.IO.Path]::IsPathRooted($(OutputPath)))">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath), 'browser-wasm', 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) From 4caaa3f889ad81f828351728064c2b0b3959567c Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 12 Sep 2022 21:20:24 +0000 Subject: [PATCH 06/11] OutputPath can be missing the rid during the evaluation --- src/mono/wasm/build/WasmApp.targets | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 91e4c48547d6c0..7c508526c58865 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -114,17 +114,29 @@ -1 + <_FullOutputPath Condition="!$([System.IO.Path]::IsPathRooted($(OutputPath)))">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath))) + <_FullOutputPath Condition=" $([System.IO.Path]::IsPathRooted($(OutputPath)))">$(OutputPath) + - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and !$([System.IO.Path]::IsPathRooted($(OutputPath)))">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath), 'browser-wasm', 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) + <_AppBundleDirForRunCommand Condition="Exists('$(WasmAppDir)/$(AssemblyName).runtimeconfig.json')">$(WasmAppDir) + + <_AppBundleCandidatePath>$([MSBuild]::NormalizeDirectory($(_FullOutputPath), 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists($(_AppBundleCandidatePath))">$(_AppBundleCandidatePath) + + <_AppBundleCandidatePath>$([MSBuild]::NormalizeDirectory($(_FullOutputPath), 'browser-wasm', 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists($(_AppBundleCandidatePath))">$(_AppBundleCandidatePath) + + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">Could not determine the AppBundle path. _FullOutputPath=$(_FullOutputPath), OutDir=$(OutDir) $(DOTNET_HOST_PATH) dotnet - exec "$([MSBuild]::NormalizePath($(WasmAppHostDir), 'WasmAppHost.dll'))" --runtime-config "$(_AppBundleDirForRunCommand)/$(AssemblyName).runtimeconfig.json" $(WasmHostArguments) + + <_RuntimeConfigJsonPath>$([MSBuild]::NormalizePath($(_AppBundleDirForRunCommand), '$(AssemblyName).runtimeconfig.json')) + exec "$([MSBuild]::NormalizePath($(WasmAppHostDir), 'WasmAppHost.dll'))" --runtime-config "$(_RuntimeConfigJsonPath)" $(WasmHostArguments) $(_AppBundleDirForRunCommand) From 215474e2f171325ae50aa1222bbaf1e87e0e2323 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 12 Sep 2022 22:01:54 +0000 Subject: [PATCH 07/11] more cleanup --- src/mono/wasm/build/WasmApp.targets | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 7c508526c58865..8bc60b93f6ee60 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -113,22 +113,26 @@ -1 + - <_FullOutputPath Condition="!$([System.IO.Path]::IsPathRooted($(OutputPath)))">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(OutputPath))) - <_FullOutputPath Condition=" $([System.IO.Path]::IsPathRooted($(OutputPath)))">$(OutputPath) - - - <_AppBundleDirForRunCommand Condition="Exists('$(WasmAppDir)/$(AssemblyName).runtimeconfig.json')">$(WasmAppDir) + + + <_AppBundleDirForRunCommand Condition="'$(WasmAppDir)' != ''">$(WasmAppDir) - <_AppBundleCandidatePath>$([MSBuild]::NormalizeDirectory($(_FullOutputPath), 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == '' and Exists($(_AppBundleCandidatePath))">$(_AppBundleCandidatePath) + + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">Could not determine the AppBundle path. _FullOutputPath=$(_FullOutputPath), OutDir=$(OutDir) + + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' != '' and !$([System.IO.Path]::IsPathRooted($(_AppBundleDirForRunCommand)))">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(_AppBundleDirForRunCommand))) From 75947b2ee6d145d8d0c9d71004bcc5434aee5d41 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 12 Sep 2022 19:40:43 -0300 Subject: [PATCH 08/11] Replacing NormalizeDirectory with [System.IO.Path]::Combine --- src/mono/wasm/build/WasmApp.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 8bc60b93f6ee60..3266e12f988d02 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -128,11 +128,11 @@ The path might not have been created yet, for example when creating a new project in VS, so don't use an Exists() check --> - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">$([MSBuild]::NormalizeDirectory($(OutputPath), 'browser-wasm', 'AppBundle')) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' == ''">$([System.IO.Path]::Combine($(OutputPath), 'browser-wasm', 'AppBundle')) - <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' != '' and !$([System.IO.Path]::IsPathRooted($(_AppBundleDirForRunCommand)))">$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(_AppBundleDirForRunCommand))) + <_AppBundleDirForRunCommand Condition="'$(_AppBundleDirForRunCommand)' != '' and !$([System.IO.Path]::IsPathRooted($(_AppBundleDirForRunCommand)))">$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(_AppBundleDirForRunCommand))) From 04a2bdc653dc83cdf0def408a4c4150782b762b9 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Mon, 12 Sep 2022 23:55:01 +0000 Subject: [PATCH 09/11] [wasm] Add tests for running templates outside project directory --- .../Wasm.Build.Tests/WasmTemplateTests.cs | 73 ++++++++++++++++++- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs index 08fc1180c849bd..c6a16115d03ae6 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs @@ -21,7 +21,7 @@ public WasmTemplateTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur { } - private void updateProgramCS() + private void UpdateProgramCS() { string programText = """ Console.WriteLine("Hello, Console!"); @@ -188,7 +188,7 @@ public void ConsoleBuildAndRun(string config, bool relinking) string projectFile = CreateWasmTemplateProject(id, "wasmconsole"); string projectName = Path.GetFileNameWithoutExtension(projectFile); - updateProgramCS(); + UpdateProgramCS(); UpdateConsoleMainJs(); if (relinking) AddItemsPropertiesToProject(projectFile, "true"); @@ -216,6 +216,73 @@ public void ConsoleBuildAndRun(string config, bool relinking) Assert.Contains("args[2] = z", output); } + [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] + //[InlineData("Debug")] + [InlineData("Release")] + public void ConsoleRunTwiceOutsideProjectDirectory(string config) + => ConsoleRunWithAndThenWithoutBuild(config, runOutsideProjectDirectory: true); + + [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] + [InlineData("Debug", false)] + [InlineData("Debug", true)] + public void ConsoleRunTwiceWithCustomOutputPath(string config, bool runOutsideProjectDirectory) + => ConsoleRunWithAndThenWithoutBuild(config, + $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}", + runOutsideProjectDirectory); + + [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] + //[InlineData("Debug")] + [InlineData("Release", false)] + [InlineData("Release", true)] + public void ConsoleRunTwiceWithCustomWasmAppDir(string config, bool runOutsideProjectDirectory) + => ConsoleRunWithAndThenWithoutBuild(config, + $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}", + runOutsideProjectDirectory); + + private void ConsoleRunWithAndThenWithoutBuild(string config, string extraProperties = "", bool runOutsideProjectDirectory = false) + { + string id = $"console_{config}_{Path.GetRandomFileName()}"; + string projectFile = CreateWasmTemplateProject(id, "wasmconsole"); + + UpdateProgramCS(); + UpdateConsoleMainJs(); + + if (!string.IsNullOrEmpty(extraProperties)) + AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); + + string workingDir = runOutsideProjectDirectory ? Path.GetTempPath() : _projectDir!; + + { + string runArgs = $"run -c {config} --project {projectFile}"; + runArgs += " x y z"; + var res = new RunCommand(s_buildEnv, _testOutput, label: id) + .WithWorkingDirectory(workingDir) + .WithEnvironmentVariables(s_buildEnv.EnvVars) + .ExecuteWithCapturedOutput(runArgs) + .EnsureExitCode(42); + + Assert.Contains("args[0] = x", res.Output); + Assert.Contains("args[1] = y", res.Output); + Assert.Contains("args[2] = z", res.Output); + } + + _testOutput.WriteLine($"{Environment.NewLine}[{id}] Running again with --no-build{Environment.NewLine}"); + + { + // Run with --no-build + string runArgs = $"run -c {config} --project {projectFile} --no-build"; + runArgs += " x y z"; + var res = new RunCommand(s_buildEnv, _testOutput, label: id) + .WithWorkingDirectory(workingDir) + .ExecuteWithCapturedOutput(runArgs) + .EnsureExitCode(42); + + Assert.Contains("args[0] = x", res.Output); + Assert.Contains("args[1] = y", res.Output); + Assert.Contains("args[2] = z", res.Output); + } + } + public static TheoryData TestDataForConsolePublishAndRun() { var data = new TheoryData(); @@ -242,7 +309,7 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) string projectFile = CreateWasmTemplateProject(id, "wasmconsole"); string projectName = Path.GetFileNameWithoutExtension(projectFile); - updateProgramCS(); + UpdateProgramCS(); UpdateConsoleMainJs(); if (aot) From 479e0091ddf60a70e0022f6064e6fd4f6f88e7ea Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 13 Sep 2022 00:38:30 +0000 Subject: [PATCH 10/11] Add tests for browser template --- .../Wasm.Build.Tests/WasmTemplateTests.cs | 95 +++++++++++++------ 1 file changed, 67 insertions(+), 28 deletions(-) diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs index c6a16115d03ae6..fe3d235710d270 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs @@ -216,30 +216,69 @@ public void ConsoleBuildAndRun(string config, bool relinking) Assert.Contains("args[2] = z", output); } - [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] - //[InlineData("Debug")] - [InlineData("Release")] - public void ConsoleRunTwiceOutsideProjectDirectory(string config) - => ConsoleRunWithAndThenWithoutBuild(config, runOutsideProjectDirectory: true); + public static TheoryData TestDataForAppBundleDir() + { + var data = new TheoryData(); + AddTestData(forConsole: true, runOutsideProjectDirectory: false); + AddTestData(forConsole: true, runOutsideProjectDirectory: true); - [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] - [InlineData("Debug", false)] - [InlineData("Debug", true)] - public void ConsoleRunTwiceWithCustomOutputPath(string config, bool runOutsideProjectDirectory) - => ConsoleRunWithAndThenWithoutBuild(config, - $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}", - runOutsideProjectDirectory); + AddTestData(forConsole: false, runOutsideProjectDirectory: false); + AddTestData(forConsole: false, runOutsideProjectDirectory: true); + + void AddTestData(bool forConsole, bool runOutsideProjectDirectory) + { + data.Add(runOutsideProjectDirectory, forConsole, string.Empty); + + data.Add(runOutsideProjectDirectory, forConsole, + $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}"); + data.Add(runOutsideProjectDirectory, forConsole, + $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}"); + } + + return data; + } [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] - //[InlineData("Debug")] - [InlineData("Release", false)] - [InlineData("Release", true)] - public void ConsoleRunTwiceWithCustomWasmAppDir(string config, bool runOutsideProjectDirectory) - => ConsoleRunWithAndThenWithoutBuild(config, - $"{Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())}", - runOutsideProjectDirectory); + [MemberData(nameof(TestDataForAppBundleDir))] + public async Task RunWithDifferentAppBundleLocations(bool forConsole, bool runOutsideProjectDirectory, string extraProperties) + => await (forConsole + ? ConsoleRunWithAndThenWithoutBuildAsync("Release", extraProperties, runOutsideProjectDirectory) + : BrowserRunTwiceWithAndThenWithoutBuildAsync("Release", extraProperties, runOutsideProjectDirectory)); - private void ConsoleRunWithAndThenWithoutBuild(string config, string extraProperties = "", bool runOutsideProjectDirectory = false) + private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, string extraProperties = "", bool runOutsideProjectDirectory = false) + { + string id = $"browser_{config}_{Path.GetRandomFileName()}"; + string projectFile = CreateWasmTemplateProject(id, "wasmbrowser"); + + UpdateBrowserMainJs(DefaultTargetFramework); + + if (!string.IsNullOrEmpty(extraProperties)) + AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); + + string workingDir = runOutsideProjectDirectory ? Path.GetTempPath() : _projectDir!; + + { + using var runCommand = new RunCommand(s_buildEnv, _testOutput) + .WithWorkingDirectory(workingDir); + + await using var runner = new BrowserRunner(); + var page = await runner.RunAsync(runCommand, $"run -c {config} --project {projectFile} --forward-console"); + await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2)); + Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines)); + } + + { + using var runCommand = new RunCommand(s_buildEnv, _testOutput) + .WithWorkingDirectory(workingDir); + + await using var runner = new BrowserRunner(); + var page = await runner.RunAsync(runCommand, $"run -c {config} --no-build --project {projectFile} --forward-console"); + await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2)); + Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines)); + } + } + + private Task ConsoleRunWithAndThenWithoutBuildAsync(string config, string extraProperties = "", bool runOutsideProjectDirectory = false) { string id = $"console_{config}_{Path.GetRandomFileName()}"; string projectFile = CreateWasmTemplateProject(id, "wasmconsole"); @@ -255,11 +294,10 @@ private void ConsoleRunWithAndThenWithoutBuild(string config, string extraProper { string runArgs = $"run -c {config} --project {projectFile}"; runArgs += " x y z"; - var res = new RunCommand(s_buildEnv, _testOutput, label: id) + using var cmd = new RunCommand(s_buildEnv, _testOutput, label: id) .WithWorkingDirectory(workingDir) - .WithEnvironmentVariables(s_buildEnv.EnvVars) - .ExecuteWithCapturedOutput(runArgs) - .EnsureExitCode(42); + .WithEnvironmentVariables(s_buildEnv.EnvVars); + var res = cmd.ExecuteWithCapturedOutput(runArgs).EnsureExitCode(42); Assert.Contains("args[0] = x", res.Output); Assert.Contains("args[1] = y", res.Output); @@ -272,15 +310,16 @@ private void ConsoleRunWithAndThenWithoutBuild(string config, string extraProper // Run with --no-build string runArgs = $"run -c {config} --project {projectFile} --no-build"; runArgs += " x y z"; - var res = new RunCommand(s_buildEnv, _testOutput, label: id) - .WithWorkingDirectory(workingDir) - .ExecuteWithCapturedOutput(runArgs) - .EnsureExitCode(42); + using var cmd = new RunCommand(s_buildEnv, _testOutput, label: id) + .WithWorkingDirectory(workingDir); + var res = cmd.ExecuteWithCapturedOutput(runArgs).EnsureExitCode(42); Assert.Contains("args[0] = x", res.Output); Assert.Contains("args[1] = y", res.Output); Assert.Contains("args[2] = z", res.Output); } + + return Task.CompletedTask; } public static TheoryData TestDataForConsolePublishAndRun() From 5ad3d55a79f528df02c0d5fb555d5b4645454a7d Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 13 Sep 2022 05:52:01 +0000 Subject: [PATCH 11/11] fix --- src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs index fe3d235710d270..285e1b665752c0 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs @@ -250,7 +250,7 @@ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, st string id = $"browser_{config}_{Path.GetRandomFileName()}"; string projectFile = CreateWasmTemplateProject(id, "wasmbrowser"); - UpdateBrowserMainJs(DefaultTargetFramework); + UpdateBrowserMainJs(); if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties);