Serve static content from wwwroot

This commit is contained in:
Steve Sanderson 2018-02-16 15:56:22 +00:00
parent 69498f68f9
commit f6d6714251
7 changed files with 52 additions and 3 deletions

View File

@ -0,0 +1,3 @@
// This is only used for E2E tests to verify that we're correctly serving static content.
// Later this will be replaced with something more useful.
window.customJsWasLoaded = true;

View File

@ -5,7 +5,8 @@
<title>Sample Blazor app</title>
</head>
<body>
<app>Loading...</app>
<script type="blazor-boot"></script>
<app>Loading...</app>
<script src="customJsFileForTests.js"></script>
<script type="blazor-boot"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -6,6 +6,8 @@
</head>
<body>
<app>Loading...</app>
<script src="/css/bootstrap/bootstrap-native.min.js"></script>
<script type="blazor-boot"></script>
</body>
</html>

View File

@ -42,6 +42,18 @@ namespace Microsoft.AspNetCore.Builder
FileProvider = distFileProvider,
ContentTypeProvider = CreateContentTypeProvider(),
});
if (!string.IsNullOrEmpty(config.WebRootPath))
{
// In development, we serve the wwwroot files directly from source
// (and don't require them to be copied into dist).
// TODO: When publishing is implemented, have config.WebRootPath set
// to null so that it only serves files that were copied to dist
applicationBuilder.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(config.WebRootPath)
});
}
}
private static IContentTypeProvider CreateContentTypeProvider()

View File

@ -3,6 +3,9 @@
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure.ServerFixtures;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using Xunit;
namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
@ -14,13 +17,29 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
{
serverFixture.BuildWebHostMethod = HostedInAspNet.Server.Program.BuildWebHost;
serverFixture.Environment = AspNetEnvironment.Development;
Navigate("/", noReload: true);
WaitUntilLoaded();
}
[Fact]
public void HasTitle()
{
Navigate("/", noReload: true);
Assert.Equal("Sample Blazor app", Browser.Title);
}
[Fact]
public void ServesStaticAssetsFromClientAppWebRoot()
{
var javascriptExecutor = (IJavaScriptExecutor)Browser;
var bootstrapTooltipType = javascriptExecutor
.ExecuteScript("return window.customJsWasLoaded;");
Assert.True((bool)bootstrapTooltipType);
}
private void WaitUntilLoaded()
{
new WebDriverWait(Browser, TimeSpan.FromSeconds(30)).Until(
driver => driver.FindElement(By.TagName("app")).Text != "Loading...");
}
}
}

View File

@ -31,6 +31,16 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
{
Assert.Equal("Hello, world!", Browser.FindElement(By.TagName("h1")).Text);
}
[Fact]
public void ServesStaticAssetsFromClientAppWebRoot()
{
// Verify that bootstrap.js was loaded
var javascriptExecutor = (IJavaScriptExecutor)Browser;
var bootstrapTooltipType = javascriptExecutor
.ExecuteScript("return typeof (window.Tooltip);");
Assert.Equal("function", bootstrapTooltipType);
}
private void WaitUntilLoaded()
{