From 147ab6f27d2d743e30b8f0409331e54a39a1b12b Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Mon, 23 Sep 2019 14:57:23 -0700 Subject: [PATCH 1/2] Port https://github.com/aspnet/AspNetCore/pull/12879 to 3.1 --- .../content/Angular-CSharp/ClientApp/angular.json | 2 +- src/ProjectTemplates/test/Helpers/ProcessEx.cs | 13 +++++++++---- src/ProjectTemplates/test/Helpers/Project.cs | 2 +- .../test/SpaTemplateTest/SpaTemplateTestBase.cs | 12 +++++------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/ClientApp/angular.json b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/ClientApp/angular.json index 56f93675c610..ce5929d3f118 100644 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/ClientApp/angular.json +++ b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/ClientApp/angular.json @@ -71,7 +71,7 @@ "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.spec.json", "karmaConfig": "src/karma.conf.js", - "styles": ["styles.css"], + "styles": ["src/styles.css"], "scripts": [], "assets": ["src/assets"] } diff --git a/src/ProjectTemplates/test/Helpers/ProcessEx.cs b/src/ProjectTemplates/test/Helpers/ProcessEx.cs index af16ef384966..2f3cbbc36119 100644 --- a/src/ProjectTemplates/test/Helpers/ProcessEx.cs +++ b/src/ProjectTemplates/test/Helpers/ProcessEx.cs @@ -104,14 +104,14 @@ public static ProcessEx Run(ITestOutputHelper output, string workingDirectory, s return new ProcessEx(output, proc); } - public static async Task RunViaShellAsync(ITestOutputHelper output, string workingDirectory, string commandAndArgs) + public static ProcessEx RunViaShell(ITestOutputHelper output, string workingDirectory, string commandAndArgs) { var (shellExe, argsPrefix) = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ("cmd", "/c") : ("bash", "-c"); var result = Run(output, workingDirectory, shellExe, $"{argsPrefix} \"{commandAndArgs}\""); - await result.Exited; + result.WaitForExit(assertSuccess: false); return result; } @@ -168,9 +168,14 @@ internal string GetFormattedOutput() return $"Process exited with code {_process.ExitCode}\nStdErr: {Error}\nStdOut: {Output}"; } - public void WaitForExit(bool assertSuccess) + public void WaitForExit(bool assertSuccess, TimeSpan? timeSpan = null) { - Exited.Wait(); + if(!timeSpan.HasValue) + { + timeSpan = TimeSpan.FromSeconds(480); + } + + Exited.Wait(timeSpan.Value); if (assertSuccess && _process.ExitCode != 0) { diff --git a/src/ProjectTemplates/test/Helpers/Project.cs b/src/ProjectTemplates/test/Helpers/Project.cs index e768bc3b238c..fc6923ae5c59 100644 --- a/src/ProjectTemplates/test/Helpers/Project.cs +++ b/src/ProjectTemplates/test/Helpers/Project.cs @@ -287,7 +287,7 @@ private async Task RestoreAsync(ITestOutputHelper output, string work try { output.WriteLine($"Restoring NPM packages in '{workingDirectory}' using npm..."); - var result = await ProcessEx.RunViaShellAsync(output, workingDirectory, "npm install"); + var result = ProcessEx.RunViaShell(output, workingDirectory, "npm install"); return result; } finally diff --git a/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs b/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs index 1826b5a4eb0d..0f474bfc76ca 100644 --- a/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs +++ b/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs @@ -63,14 +63,12 @@ protected async Task SpaTemplateImplAsync( using var npmRestoreResult = await Project.RestoreWithRetryAsync(Output, clientAppSubdirPath); Assert.True(0 == npmRestoreResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm restore", Project, npmRestoreResult)); - using var lintResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run lint"); + using var lintResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, "npm run lint"); Assert.True(0 == lintResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run lint", Project, lintResult)); - if (template == "react" || template == "reactredux") - { - using var testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run test"); - Assert.True(0 == testResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run test", Project, testResult)); - } + var testcommand = "npm run test" + template == "angular" ? "-- --watch=false" : ""; + using var testResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, testcommand); + Assert.True(0 == testResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run test", Project, testResult)); using var publishResult = await Project.RunDotNetPublishAsync(); Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", Project, publishResult)); @@ -159,7 +157,7 @@ private async Task CleanupReactClientAppBuildFolder(string clientAppSubdirPath) { try { - testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npx rimraf ./build"); + testResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, "npx rimraf ./build"); testResultExitCode = testResult.ExitCode; if (testResultExitCode == 0) { From 7467059dd81a99414f765c0f7e21019ac15b12ab Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Tue, 1 Oct 2019 14:21:47 -0700 Subject: [PATCH 2/2] PR feedback --- .../test/SpaTemplateTest/SpaTemplateTestBase.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs b/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs index 0f474bfc76ca..fa2c3fb9fa3b 100644 --- a/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs +++ b/src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs @@ -66,7 +66,9 @@ protected async Task SpaTemplateImplAsync( using var lintResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, "npm run lint"); Assert.True(0 == lintResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run lint", Project, lintResult)); + // The default behavior of angular tests is watch mode, which leaves the test process open after it finishes, which leads to delays/hangs. var testcommand = "npm run test" + template == "angular" ? "-- --watch=false" : ""; + using var testResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, testcommand); Assert.True(0 == testResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run test", Project, testResult));