Skip to content

Enforce E2E test prerequisites when building individual solutions only #11642

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 15 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Components/Blazor/Build/src/ReferenceFromSource.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PropertyGroup>
<RunCommand>dotnet</RunCommand>
<_BlazorCliLocation>$(MSBuildThisFileDirectory)../../DevServer/src/bin/$(Configuration)/netcoreapp3.0/blazor-devserver.dll</_BlazorCliLocation>
<RunArguments>exec &quot;$(_BlazorCliLocation)&quot; serve &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot; $(AdditionalRunArguments)</RunArguments>
<RunArguments>exec &quot;$(_BlazorCliLocation)&quot; serve --applicationpath &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot; $(AdditionalRunArguments)</RunArguments>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 1 addition & 20 deletions src/Components/Blazor/DevServer/src/Commands/ServeCommand.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;
using System.Runtime.Versioning;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.CommandLineUtils;
using Microsoft.Extensions.Hosting;

namespace Microsoft.AspNetCore.Blazor.DevServer.Commands
{
Expand All @@ -23,28 +21,11 @@ public ServeCommand(CommandLineApplication parent)

HelpOption("-?|-h|--help");

ApplicationPath = new CommandArgument()
{
Description = "Path to the client application dll",
MultipleValues = false,
Name = "<PATH>",
ShowInHelpText = true
};
Arguments.Add(ApplicationPath);

OnExecute(Execute);
}

public CommandArgument ApplicationPath { get; private set; }

private int Execute()
{
if (string.IsNullOrWhiteSpace(ApplicationPath.Value))
{
throw new InvalidOperationException($"Invalid value for parameter '{nameof(ApplicationPath)}'. Value supplied: '{ApplicationPath.Value}'");
}

Server.Startup.ApplicationAssembly = ApplicationPath.Value;
Server.Program.BuildWebHost(RemainingArguments.ToArray()).Run();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Reference Include="Microsoft.AspNetCore.ResponseCompression" />
<Reference Include="Microsoft.AspNetCore" />
<Reference Include="Microsoft.Extensions.CommandLineUtils.Sources" />
<Reference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>

<!-- Pack settings -->
Expand Down
35 changes: 27 additions & 8 deletions src/Components/Blazor/DevServer/src/Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Microsoft.AspNetCore.Blazor.DevServer.Server
{
Expand All @@ -18,12 +25,24 @@ public class Program
/// <summary>
/// Intended for framework test use only.
/// </summary>
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(new ConfigurationBuilder()
.AddCommandLine(args)
.Build())
.UseStartup<Startup>()
.Build();
public static IHost BuildWebHost(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureHostConfiguration(cb => {
var applicationPath = args.SkipWhile(a => a != "--applicationpath").Skip(1).FirstOrDefault();
var name = Path.ChangeExtension(applicationPath,".StaticWebAssets.xml");

if (name != null)
{
cb.AddInMemoryCollection(new Dictionary<string, string>
{
[WebHostDefaults.StaticWebAssetsKey] = name
});
}
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStaticWebAssets();
webBuilder.UseStartup<Startup>();
}).Build();
}
}
26 changes: 19 additions & 7 deletions src/Components/Blazor/DevServer/src/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ namespace Microsoft.AspNetCore.Blazor.DevServer.Server
{
internal class Startup
{
public static string ApplicationAssembly { get; set; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
Expand All @@ -35,7 +40,7 @@ public void ConfigureServices(IServiceCollection services)

public void Configure(IApplicationBuilder app, IWebHostEnvironment environment, IConfiguration configuration)
{
var applicationAssemblyFullPath = ResolveApplicationAssemblyFullPath(environment);
var applicationAssemblyFullPath = ResolveApplicationAssemblyFullPath();

app.UseDeveloperExceptionPage();
app.UseResponseCompression();
Expand All @@ -54,15 +59,22 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment environment,
});
}

private static string ResolveApplicationAssemblyFullPath(IWebHostEnvironment environment)
private string ResolveApplicationAssemblyFullPath()
{
var applicationAssemblyFullPath = Path.Combine(environment.ContentRootPath, ApplicationAssembly);
if (!File.Exists(applicationAssemblyFullPath))
const string applicationPathKey = "applicationpath";
var configuredApplicationPath = Configuration.GetValue<string>(applicationPathKey);
if (string.IsNullOrEmpty(configuredApplicationPath))
{
throw new InvalidOperationException($"No value was supplied for the required option '{applicationPathKey}'.");
}

var resolvedApplicationPath = Path.GetFullPath(configuredApplicationPath);
if (!File.Exists(resolvedApplicationPath))
{
throw new InvalidOperationException($"Application assembly not found at {applicationAssemblyFullPath}.");
throw new InvalidOperationException($"Application assembly not found at {resolvedApplicationPath}.");
}

return applicationAssemblyFullPath;
return resolvedApplicationPath;
}

private static void EnableConfiguredPathbase(IApplicationBuilder app, IConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<PropertyGroup>
<_BlazorDevServerDll>$(MSBuildThisFileDirectory)../tools/blazor-devserver.dll</_BlazorDevServerDll>
<RunCommand>dotnet</RunCommand>
<RunArguments>&quot;$(_BlazorDevServerDll)&quot; serve &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot;</RunArguments>
<RunArguments>&quot;$(_BlazorDevServerDll)&quot; serve --applicationpath &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot;</RunArguments>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Components/build.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@ECHO OFF
SET RepoRoot=%~dp0..\..
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj "/p:EnforceE2ETestPrerequisites=true" %*
2 changes: 1 addition & 1 deletion src/Components/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -euo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
repo_root="$DIR/../.."
"$repo_root/build.sh" --projects "$DIR/**/*.*proj" "$@"
"$repo_root/build.sh" --projects "$DIR/**/*.*proj" "/p:EnforceE2ETestPrerequisites=true" "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DevHostServerProgram = Microsoft.AspNetCore.Blazor.DevServer.Server.Program;

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
Expand All @@ -22,7 +28,8 @@ protected override IWebHost CreateWebHost()
{
"--urls", "http://127.0.0.1:0",
"--contentroot", ContentRoot,
"--pathbase", PathBase
"--pathbase", PathBase,
"--applicationpath", typeof(TProgram).Assembly.Location,
};

if (!string.IsNullOrEmpty(Environment))
Expand All @@ -31,7 +38,29 @@ protected override IWebHost CreateWebHost()
args.Add(Environment);
}

return DevHostServerProgram.BuildWebHost(args.ToArray());
return new FakeWebHost(DevHostServerProgram.BuildWebHost(args.ToArray()));
}

private class FakeWebHost : IWebHost
{
private readonly IHost _realHost;

public FakeWebHost(IHost realHost)
{
_realHost = realHost;
}

public IFeatureCollection ServerFeatures => ((IServer)_realHost.Services.GetService(typeof(IServer))).Features;

public IServiceProvider Services => _realHost.Services;

public void Dispose() => _realHost.Dispose();

public void Start() => _realHost.Start();

public Task StartAsync(CancellationToken cancellationToken = default) => _realHost.StartAsync();

public Task StopAsync(CancellationToken cancellationToken = default) => _realHost.StopAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
<TestGroupName>Components.E2ETests</TestGroupName>

<!--
Temporarily disabled until this runs on macOS
-->
<SkipTests Condition="'$(SeleniumE2ETestsSupported)' != 'true'">true</SkipTests>
<SkipTests>true</SkipTests>
<!-- https://github.com/aspnet/AspNetCore/issues/6857 -->
<BuildHelixPayload>false</BuildHelixPayload>

Expand Down
50 changes: 28 additions & 22 deletions src/Components/test/testassets/BasicTestApp/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@
<title>Basic test app</title>
<base href="/subdir/" />
<link href="style.css" rel="stylesheet" />

<!-- Used by ExternalContentPackage -->
<link href="_content/TestContentPackage/styles.css" rel="stylesheet" />
</head>
<body>
<root>Loading...</root>
<root>Loading...</root>

<!-- Used for testing interop scenarios between JS and .NET -->
<script src="js/jsinteroptests.js"></script>

<!-- Used for testing interop scenarios between JS and .NET -->
<script src="js/jsinteroptests.js"></script>
<script>
// Used by ElementRefComponent
function setElementValue(element, newValue) {
element.value = newValue;
return element.value;
}

<script>
// Used by ElementRefComponent
function setElementValue(element, newValue) {
element.value = newValue;
return element.value;
}
function uriHelperNavigate() {
Blazor.navigateTo('/subdir/some-path');
}

function uriHelperNavigate() {
Blazor.navigateTo('/subdir/some-path');
}
(function () {
// Load either blazor.webassembly.js or blazor.server.js depending
// on the hash part of the URL. This is just to give a way for the
// test runner to make the selection.
var src = location.hash === '#server'
? 'blazor.server.js'
: 'blazor.webassembly.js';
document.write('<script src="_framework/' + src + '"><' + '/script>');
})();
</script>

(function () {
// Load either blazor.webassembly.js or blazor.server.js depending
// on the hash part of the URL. This is just to give a way for the
// test runner to make the selection.
var src = location.hash === '#server'
? 'blazor.server.js'
: 'blazor.webassembly.js';
document.write('<script src="_framework/' + src + '"><' + '/script>');
})();
</script>
<!-- Used by ExternalContentPackage -->
<script src="_content/TestContentPackage/prompt.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>library</OutputType>
<RazorLangVersion>3.0</RazorLangVersion>
<StaticWebAssetBasePath>_content/TestContentPackage</StaticWebAssetBasePath>
</PropertyGroup>

<ItemGroup>
<!-- .js files will be referenced via <script> tags -->
<EmbeddedResource Include="content\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />

<!-- .css files will be referenced via <link rel='Stylesheet'> tags -->
<EmbeddedResource Include="content\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />

<!-- Any other files will be included in the 'dist' output but without any tags referencing them -->
<EmbeddedResource Include="content\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Components" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Components/test/testassets/TestServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static IWebHost BuildWebHost<TStartup>(string[] args) where TStartup : cl
.AddCommandLine(args)
.Build())
.UseStartup<TStartup>()
.UseStaticWebAssets()
.Build();
}
}
4 changes: 1 addition & 3 deletions src/Components/test/testassets/TestServer/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using BasicTestApp;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Server;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -63,6 +60,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
// Mount the server-side Blazor app on /subdir
app.Map("/subdir", subdirApp =>
{
subdirApp.UseStaticFiles();
subdirApp.UseClientSideBlazorFiles<BasicTestApp.Startup>();

subdirApp.UseRouting();
Expand Down
2 changes: 1 addition & 1 deletion src/DefaultBuilder/src/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ internal static void ConfigureWebDefaults(IWebHostBuilder builder)
{
if (ctx.HostingEnvironment.IsDevelopment())
{
StaticWebAssetsLoader.UseStaticWebAssets(ctx.HostingEnvironment);
StaticWebAssetsLoader.UseStaticWebAssets(ctx.HostingEnvironment, ctx.Configuration);
}
});
builder.UseKestrel((builderContext, options) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static partial class WebHostDefaults
public static readonly string ServerUrlsKey;
public static readonly string ShutdownTimeoutKey;
public static readonly string StartupAssemblyKey;
public static readonly string StaticWebAssetsKey;
public static readonly string SuppressStatusMessagesKey;
public static readonly string WebRootKey;
}
Expand Down
1 change: 1 addition & 0 deletions src/Hosting/Abstractions/src/WebHostDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public static class WebHostDefaults
public static readonly string SuppressStatusMessagesKey = "suppressStatusMessages";

public static readonly string ShutdownTimeoutKey = "shutdownTimeoutSeconds";
public static readonly string StaticWebAssetsKey = "staticWebAssets";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
public partial class StaticWebAssetsLoader
{
public StaticWebAssetsLoader() { }
public static void UseStaticWebAssets(Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment) { }
public static void UseStaticWebAssets(Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment, Microsoft.Extensions.Configuration.IConfiguration configuration) { }
}
}
namespace Microsoft.Extensions.Hosting
Expand Down
Loading