[Templates][Fixes #13641] Run rimraf before running the app to give it a better chance of avoiding a failure

* Rimraf has reliability issues on windows.
* This change runs rimraf with a few retries before starting the app with `dotnet run` so that `npm run start` on the ReactDeveloperMiddleware has a better chance to succeed.
This commit is contained in:
Javier Calvarro Nelson 2019-09-04 20:12:51 +02:00 committed by GitHub
parent 6e88aa200c
commit ddf987eb4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 1 deletions

View File

@ -6,7 +6,6 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.E2ETesting;
@ -99,6 +98,11 @@ namespace Templates.Test.SpaTemplateTest
}
}
if (template == "react" || template == "reactredux")
{
await CleanupReactClientAppBuildFolder(clientAppSubdirPath);
}
using (var aspNetProcess = Project.StartBuiltProjectAsync())
{
Assert.False(
@ -147,6 +151,35 @@ namespace Templates.Test.SpaTemplateTest
}
}
private async Task CleanupReactClientAppBuildFolder(string clientAppSubdirPath)
{
ProcessEx testResult = null;
int? testResultExitCode = null;
for (int i = 0; i < 3; i++)
{
try
{
testResult = await ProcessEx.RunViaShellAsync(Output, clientAppSubdirPath, "npx rimraf ./build");
testResultExitCode = testResult.ExitCode;
if (testResultExitCode == 0)
{
return;
}
}
catch
{
}
finally
{
testResult.Dispose();
}
await Task.Delay(3000);
}
Assert.True(testResultExitCode == 0, ErrorMessages.GetFailedProcessMessage("npx rimraf ./build", Project, testResult));
}
private void ValidatePackageJson(string clientAppSubdirPath)
{
Assert.True(File.Exists(Path.Combine(clientAppSubdirPath, "package.json")), "Missing a package.json");