Skip to content

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

Merged
merged 11 commits into from
Apr 4, 2019
Merged

Conversation

ryanbrandenburg
Copy link
Contributor

Fixes #5433.

Also added some tests for some scenarios that were missing.

@ryanbrandenburg ryanbrandenburg changed the title Rybrande/templating links Test all links in templates Mar 18, 2019
@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 18, 2019
@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/TemplatingLinks branch from 86b9421 to bfd2d04 Compare March 21, 2019 21:47
@ryanbrandenburg
Copy link
Contributor Author

@javiercn ⌚️

@javiercn
Copy link
Member

javiercn commented Mar 25, 2019

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.

@ryanbrandenburg
Copy link
Contributor Author

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.

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/TemplatingLinks branch from bfd2d04 to c02083b Compare March 26, 2019 16:28
@pranavkm
Copy link
Contributor

<AddRazorSupportForMvc Condition="'$(SupportPagesAndViews)' == 'True'">>true</AddRazorSupportForMvc>

@@ -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>
Copy link
Contributor

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()
{
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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()
{
Copy link
Member

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

Copy link
Member

@javiercn javiercn left a 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. :shipit: 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.

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/TemplatingLinks branch from a7f1c32 to afb8c22 Compare April 1, 2019 18:15
@analogrelay analogrelay removed their request for review April 1, 2019 19:17
@ryanbrandenburg
Copy link
Contributor Author

🆙📅

@ryanbrandenburg ryanbrandenburg requested a review from javiercn April 2, 2019 18:13
using (var clientProcess = Project.StartBuiltClientAsync(serverProcess))
{
// Wait for the client to do its thing
System.Threading.Thread.Sleep(100);
Copy link
Member

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,
Copy link
Member

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";
Copy link
Member

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


Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@javiercn javiercn left a 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!

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/TemplatingLinks branch from afb8c22 to 7fcb33d Compare April 2, 2019 18:53
@ryanbrandenburg
Copy link
Contributor Author

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact ryanbrandenburg.

I've triaged the above build.

2 similar comments
@ryanbrandenburg
Copy link
Contributor Author

This comment was made automatically. If there is a problem contact ryanbrandenburg.

I've triaged the above build.

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact ryanbrandenburg.

I've triaged the above build.

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/TemplatingLinks branch from 726cd57 to a36cb35 Compare April 3, 2019 21:49

namespace Templates.Test
{
public class GrpcTemplateTest
Copy link
Contributor

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.

cc @JamesNK @shirhatti

@ryanbrandenburg ryanbrandenburg merged commit fefffd7 into master Apr 4, 2019
@ryanbrandenburg ryanbrandenburg deleted the rybrande/TemplatingLinks branch April 4, 2019 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants