Skip to content

Commit 8e6cd2c

Browse files
ryanbrandenburgmkArtakMSFT
authored andcommitted
Port #12879 to 3.1 (#14638)
* Port #12879 to 3.1 * PR feedback
1 parent fa93369 commit 8e6cd2c

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/ClientApp/angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"polyfills": "src/polyfills.ts",
7272
"tsConfig": "src/tsconfig.spec.json",
7373
"karmaConfig": "src/karma.conf.js",
74-
"styles": ["styles.css"],
74+
"styles": ["src/styles.css"],
7575
"scripts": [],
7676
"assets": ["src/assets"]
7777
}

src/ProjectTemplates/test/Helpers/ProcessEx.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ public static ProcessEx Run(ITestOutputHelper output, string workingDirectory, s
104104
return new ProcessEx(output, proc);
105105
}
106106

107-
public static async Task<ProcessEx> RunViaShellAsync(ITestOutputHelper output, string workingDirectory, string commandAndArgs)
107+
public static ProcessEx RunViaShell(ITestOutputHelper output, string workingDirectory, string commandAndArgs)
108108
{
109109
var (shellExe, argsPrefix) = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
110110
? ("cmd", "/c")
111111
: ("bash", "-c");
112112

113113
var result = Run(output, workingDirectory, shellExe, $"{argsPrefix} \"{commandAndArgs}\"");
114-
await result.Exited;
114+
result.WaitForExit(assertSuccess: false);
115115
return result;
116116
}
117117

@@ -168,9 +168,14 @@ internal string GetFormattedOutput()
168168
return $"Process exited with code {_process.ExitCode}\nStdErr: {Error}\nStdOut: {Output}";
169169
}
170170

171-
public void WaitForExit(bool assertSuccess)
171+
public void WaitForExit(bool assertSuccess, TimeSpan? timeSpan = null)
172172
{
173-
Exited.Wait();
173+
if(!timeSpan.HasValue)
174+
{
175+
timeSpan = TimeSpan.FromSeconds(480);
176+
}
177+
178+
Exited.Wait(timeSpan.Value);
174179

175180
if (assertSuccess && _process.ExitCode != 0)
176181
{

src/ProjectTemplates/test/Helpers/Project.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ private async Task<ProcessEx> RestoreAsync(ITestOutputHelper output, string work
287287
try
288288
{
289289
output.WriteLine($"Restoring NPM packages in '{workingDirectory}' using npm...");
290-
var result = await ProcessEx.RunViaShellAsync(output, workingDirectory, "npm install");
290+
var result = ProcessEx.RunViaShell(output, workingDirectory, "npm install");
291291
return result;
292292
}
293293
finally

src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ protected async Task SpaTemplateImplAsync(
6363
using var npmRestoreResult = await Project.RestoreWithRetryAsync(Output, clientAppSubdirPath);
6464
Assert.True(0 == npmRestoreResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm restore", Project, npmRestoreResult));
6565

66-
using var lintResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run lint");
66+
using var lintResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, "npm run lint");
6767
Assert.True(0 == lintResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run lint", Project, lintResult));
6868

69-
if (template == "react" || template == "reactredux")
70-
{
71-
using var testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run test");
72-
Assert.True(0 == testResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run test", Project, testResult));
73-
}
69+
// The default behavior of angular tests is watch mode, which leaves the test process open after it finishes, which leads to delays/hangs.
70+
var testcommand = "npm run test" + template == "angular" ? "-- --watch=false" : "";
71+
72+
using var testResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, testcommand);
73+
Assert.True(0 == testResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run test", Project, testResult));
7474

7575
using var publishResult = await Project.RunDotNetPublishAsync();
7676
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", Project, publishResult));
@@ -159,7 +159,7 @@ private async Task CleanupReactClientAppBuildFolder(string clientAppSubdirPath)
159159
{
160160
try
161161
{
162-
testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npx rimraf ./build");
162+
testResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, "npx rimraf ./build");
163163
testResultExitCode = testResult.ExitCode;
164164
if (testResultExitCode == 0)
165165
{

0 commit comments

Comments
 (0)