Fixed issue with SPA templates generating invalid NPM package names (#9725)
Added unit test to check NPM package names matches regex
This commit is contained in:
parent
53acfe63df
commit
d9ad99933c
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "Company.WebApplication1",
|
"name": "company.webapplication1",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "Company.WebApplication1",
|
"name": "company.webapplication1",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "Company.WebApplication1",
|
"name": "company.webapplication1",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.E2ETesting;
|
using Microsoft.AspNetCore.E2ETesting;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
@ -51,7 +52,7 @@ namespace Templates.Test.SpaTemplateTest
|
||||||
// multiple NPM installs run concurrently which otherwise causes errors when
|
// multiple NPM installs run concurrently which otherwise causes errors when
|
||||||
// tests run in parallel.
|
// tests run in parallel.
|
||||||
var clientAppSubdirPath = Path.Combine(Project.TemplateOutputDir, "ClientApp");
|
var clientAppSubdirPath = Path.Combine(Project.TemplateOutputDir, "ClientApp");
|
||||||
Assert.True(File.Exists(Path.Combine(clientAppSubdirPath, "package.json")), "Missing a package.json");
|
ValidatePackageJson(clientAppSubdirPath);
|
||||||
|
|
||||||
var projectFileContents = ReadFile(Project.TemplateOutputDir, $"{Project.ProjectName}.csproj");
|
var projectFileContents = ReadFile(Project.TemplateOutputDir, $"{Project.ProjectName}.csproj");
|
||||||
if (usesAuth && !useLocalDb)
|
if (usesAuth && !useLocalDb)
|
||||||
|
|
@ -137,6 +138,17 @@ namespace Templates.Test.SpaTemplateTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ValidatePackageJson(string clientAppSubdirPath)
|
||||||
|
{
|
||||||
|
Assert.True(File.Exists(Path.Combine(clientAppSubdirPath, "package.json")), "Missing a package.json");
|
||||||
|
var packageJson = JObject.Parse(ReadFile(clientAppSubdirPath, "package.json"));
|
||||||
|
|
||||||
|
// NPM package names must match ^(?:@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$
|
||||||
|
var packageName = (string)packageJson["name"];
|
||||||
|
Regex regex = new Regex("^(?:@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$");
|
||||||
|
Assert.True(regex.IsMatch(packageName), "package.json name is invalid format");
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task WarmUpServer(AspNetProcess aspNetProcess)
|
private static async Task WarmUpServer(AspNetProcess aspNetProcess)
|
||||||
{
|
{
|
||||||
var attempt = 0;
|
var attempt = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue