Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Expand Down
13 changes: 9 additions & 4 deletions src/ProjectTemplates/test/Helpers/ProcessEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ public static ProcessEx Run(ITestOutputHelper output, string workingDirectory, s
return new ProcessEx(output, proc);
}

public static async Task<ProcessEx> RunViaShellAsync(ITestOutputHelper output, string workingDirectory, string commandAndArgs)
public static ProcessEx RunViaShell(ITestOutputHelper output, string workingDirectory, string commandAndArgs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no longer async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await result.Exited was the last async thing in this function, without it we get that annoying warning/error about an async with nothing awaited. Unfortunately I wasn't able to find/manufacture an overload to wait for result to complete that was both async and did a timeout.

{
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;
}

Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ProjectTemplates/test/Helpers/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private async Task<ProcessEx> 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
Expand Down
14 changes: 7 additions & 7 deletions src/ProjectTemplates/test/SpaTemplateTest/SpaTemplateTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ 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));
}
// 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" : "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this conditional argument is needed. Can you add a comment?


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));
Expand Down Expand Up @@ -159,7 +159,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)
{
Expand Down