* Port https://github.com/aspnet/AspNetCore/pull/12879 to 3.1 * PR feedback
This commit is contained in:
parent
fa93369beb
commit
8e6cd2c70d
|
|
@ -71,7 +71,7 @@
|
||||||
"polyfills": "src/polyfills.ts",
|
"polyfills": "src/polyfills.ts",
|
||||||
"tsConfig": "src/tsconfig.spec.json",
|
"tsConfig": "src/tsconfig.spec.json",
|
||||||
"karmaConfig": "src/karma.conf.js",
|
"karmaConfig": "src/karma.conf.js",
|
||||||
"styles": ["styles.css"],
|
"styles": ["src/styles.css"],
|
||||||
"scripts": [],
|
"scripts": [],
|
||||||
"assets": ["src/assets"]
|
"assets": ["src/assets"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,14 +104,14 @@ namespace Templates.Test.Helpers
|
||||||
return new ProcessEx(output, proc);
|
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)
|
||||||
{
|
{
|
||||||
var (shellExe, argsPrefix) = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
var (shellExe, argsPrefix) = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||||
? ("cmd", "/c")
|
? ("cmd", "/c")
|
||||||
: ("bash", "-c");
|
: ("bash", "-c");
|
||||||
|
|
||||||
var result = Run(output, workingDirectory, shellExe, $"{argsPrefix} \"{commandAndArgs}\"");
|
var result = Run(output, workingDirectory, shellExe, $"{argsPrefix} \"{commandAndArgs}\"");
|
||||||
await result.Exited;
|
result.WaitForExit(assertSuccess: false);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,9 +168,14 @@ namespace Templates.Test.Helpers
|
||||||
return $"Process exited with code {_process.ExitCode}\nStdErr: {Error}\nStdOut: {Output}";
|
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)
|
if (assertSuccess && _process.ExitCode != 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ namespace Templates.Test.Helpers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
output.WriteLine($"Restoring NPM packages in '{workingDirectory}' using npm...");
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
||||||
|
|
@ -63,14 +63,14 @@ namespace Templates.Test.SpaTemplateTest
|
||||||
using var npmRestoreResult = await Project.RestoreWithRetryAsync(Output, clientAppSubdirPath);
|
using var npmRestoreResult = await Project.RestoreWithRetryAsync(Output, clientAppSubdirPath);
|
||||||
Assert.True(0 == npmRestoreResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm restore", Project, npmRestoreResult));
|
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));
|
Assert.True(0 == lintResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run lint", Project, lintResult));
|
||||||
|
|
||||||
if (template == "react" || template == "reactredux")
|
// 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 = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npm run test");
|
|
||||||
Assert.True(0 == testResult.ExitCode, ErrorMessages.GetFailedProcessMessage("npm run test", Project, testResult));
|
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();
|
using var publishResult = await Project.RunDotNetPublishAsync();
|
||||||
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", Project, publishResult));
|
Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", Project, publishResult));
|
||||||
|
|
@ -159,7 +159,7 @@ namespace Templates.Test.SpaTemplateTest
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npx rimraf ./build");
|
testResult = ProcessEx.RunViaShell(Output, clientAppSubdirPath, "npx rimraf ./build");
|
||||||
testResultExitCode = testResult.ExitCode;
|
testResultExitCode = testResult.ExitCode;
|
||||||
if (testResultExitCode == 0)
|
if (testResultExitCode == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue