-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Test all links in templates #8628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
86b9421
to
bfd2d04
Compare
@javiercn ⌚️ |
I don't think that this PR addresses aspnet/Templating#692 correctly. The reason is because when a link doesn't exist on routing we will generate an empty link, which will return a 200 status code when visited as its pointing to the same page you are on. I think the only correct way to do this is to collect all the links on a given page and assert they are present. And then after that, if you want to, you visit them. For example: aspNetProcess.ContainsLinks("/", expectedLinks)
aspNetProcess.AssertOk("/Privacy") To be clear, this test will pass in many broken scenarios, so we should be more specific on what we are testing. Specially given the fact that our templates only contain a small set of urls. |
Fair duce. We do also want to confirm that external links don't 404 (it's happened before) but you're right that given that Routing behavior this PR isn't covering the most likely break-case. |
bfd2d04
to
c02083b
Compare
|
@@ -5,6 +5,7 @@ | |||
<TargetFramework Condition="'$(SupportPagesAndViews)' != 'True'">netstandard2.0</TargetFramework> | |||
<RazorLangVersion Condition="'$(SupportPagesAndViews)' != 'True'">3.0</RazorLangVersion> | |||
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.RazorClassLibrary1</RootNamespace> | |||
<AddRazorSupportForMvc Condition="'$(SupportPagesAndViews)' == 'True'">true</AddRazorSupportForMvc> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
[Fact] | ||
public async Task GrpcTemplate() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a class-library or an executable, if it's the former. Should we test it runs?
/cc: @glennc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add that because I don't know what the expected behavior is. Would certainly be reasonable to at least check it doesn't crash instantly and file an issue for someone involved with Grpc to test expectations.
} | ||
} | ||
|
||
public async Task ContainsLinks(string requestUrl, IEnumerable<string> expectedLinks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is covering things like <link rel="stylesheet" type="text/css" href="theme.css">
and similar. Or <script src="app.js" />
or for that matter. Are we not planning to cover those?
Also, shouldn't we fail if we encounter more links than expected? That would mean that we added something we are not testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely not covering thinks like missing style-sheets/scripts. My thought was to cover that using the Browser console checks we have to add anyway for the LibMan switch, but that would mean testing non-SPA templates with Selenium. May as well start doing it here since we're already parsing.
|
||
[Fact(Skip = "Microsoft.NET.Sdk.Worker isn't available yet")] | ||
public async Task WorkerTemplateAsync() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for the grpc template. Shouldn't we run this if it's an executable template?
/cc: @glennc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only have a comment about the links regarded to link and script elements and the fact that we don't fail if there are additional links than the ones we expect. Other than that and a potentially missing couple of test actions looks good. once we have a resolution for those three items.
- urls in link and script tags.
- fail when we find additional links.
- running the grpc and worker templates.
a7f1c32
to
afb8c22
Compare
🆙📅 |
using (var clientProcess = Project.StartBuiltClientAsync(serverProcess)) | ||
{ | ||
// Wait for the client to do its thing | ||
System.Threading.Thread.Sleep(100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await Task.Delay(100)
internal ProcessEx Process { get; } | ||
|
||
public AspNetProcess( | ||
ITestOutputHelper output, | ||
string workingDirectory, | ||
string dllPath, | ||
IDictionary<string, string> environmentVariables) | ||
IDictionary<string, string> environmentVariables, | ||
bool useExec = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you rename useExec to published? that's essentially what it is.
return new AspNetProcess(Output, TemplateClientReleaseDir, projectDll, environment); | ||
} | ||
|
||
private const string _urls = "http://127.0.0.1:0;https://127.0.0.1:0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should go at the top of the file.
@@ -23,6 +24,7 @@ public RazorPagesTemplateTest(ProjectFactoryFixture projectFactory, ITestOutputH | |||
|
|||
public ITestOutputHelper Output { get; } | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unnecessary extra line
@@ -31,8 +33,6 @@ public async Task RazorPagesTemplate_NoAuthImplAsync() | |||
var createResult = await Project.RunDotNetNewAsync("razor"); | |||
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("razor", Project, createResult)); | |||
|
|||
AssertFileExists(Project.TemplateOutputDir, "Pages/Shared/_LoginPartial.cshtml", false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we remove this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File existence is covered more thoroughly here so I figured it was best to only test it in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some cleanups left, but otherwise looks good!
afb8c22
to
7fcb33d
Compare
This comment was made automatically. If there is a problem contact ryanbrandenburg. I've triaged the above build. |
2 similar comments
This comment was made automatically. If there is a problem contact ryanbrandenburg. I've triaged the above build. |
This comment was made automatically. If there is a problem contact ryanbrandenburg. I've triaged the above build. |
726cd57
to
a36cb35
Compare
|
||
namespace Templates.Test | ||
{ | ||
public class GrpcTemplateTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanbrandenburg we are going to be changing the template for gRPC pretty significantly since we'll be removing the client. We're going to need to update the test since our PRs will collide.
Fixes #5433.
Also added some tests for some scenarios that were missing.