Serve static content from wwwroot
This commit is contained in:
parent
69498f68f9
commit
f6d6714251
|
|
@ -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;
|
||||||
|
|
@ -5,7 +5,8 @@
|
||||||
<title>Sample Blazor app</title>
|
<title>Sample Blazor app</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<app>Loading...</app>
|
<app>Loading...</app>
|
||||||
<script type="blazor-boot"></script>
|
<script src="customJsFileForTests.js"></script>
|
||||||
|
<script type="blazor-boot"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -6,6 +6,8 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<app>Loading...</app>
|
<app>Loading...</app>
|
||||||
|
|
||||||
|
<script src="/css/bootstrap/bootstrap-native.min.js"></script>
|
||||||
<script type="blazor-boot"></script>
|
<script type="blazor-boot"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,18 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
FileProvider = distFileProvider,
|
FileProvider = distFileProvider,
|
||||||
ContentTypeProvider = CreateContentTypeProvider(),
|
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()
|
private static IContentTypeProvider CreateContentTypeProvider()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure;
|
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure.ServerFixtures;
|
using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure.ServerFixtures;
|
||||||
|
using OpenQA.Selenium;
|
||||||
|
using OpenQA.Selenium.Support.UI;
|
||||||
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
|
|
@ -14,13 +17,29 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
{
|
{
|
||||||
serverFixture.BuildWebHostMethod = HostedInAspNet.Server.Program.BuildWebHost;
|
serverFixture.BuildWebHostMethod = HostedInAspNet.Server.Program.BuildWebHost;
|
||||||
serverFixture.Environment = AspNetEnvironment.Development;
|
serverFixture.Environment = AspNetEnvironment.Development;
|
||||||
|
Navigate("/", noReload: true);
|
||||||
|
WaitUntilLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void HasTitle()
|
public void HasTitle()
|
||||||
{
|
{
|
||||||
Navigate("/", noReload: true);
|
|
||||||
Assert.Equal("Sample Blazor app", Browser.Title);
|
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...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,16 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
||||||
{
|
{
|
||||||
Assert.Equal("Hello, world!", Browser.FindElement(By.TagName("h1")).Text);
|
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()
|
private void WaitUntilLoaded()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue