Skip to content

Commit 1480b99

Browse files
authored
Enforce E2E test prerequisites when building individual solutions only (#11642)
* Fixes multiple issues that happened due to the E2E tests not running on the CI * Enforces prerequisites for E2E tests on the CI and when building projects with E2E tests. * Re-enables the E2E tests for templates.
1 parent f7de3da commit 1480b99

File tree

34 files changed

+210
-124
lines changed

34 files changed

+210
-124
lines changed

src/Components/Blazor/Build/src/ReferenceFromSource.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<PropertyGroup>
2929
<RunCommand>dotnet</RunCommand>
3030
<_BlazorCliLocation>$(MSBuildThisFileDirectory)../../DevServer/src/bin/$(Configuration)/netcoreapp3.0/blazor-devserver.dll</_BlazorCliLocation>
31-
<RunArguments>exec &quot;$(_BlazorCliLocation)&quot; serve &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot; $(AdditionalRunArguments)</RunArguments>
31+
<RunArguments>exec &quot;$(_BlazorCliLocation)&quot; serve --applicationpath &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot; $(AdditionalRunArguments)</RunArguments>
3232
</PropertyGroup>
3333

3434
<ItemGroup>

src/Components/Blazor/DevServer/src/Commands/ServeCommand.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
5-
using System.IO;
6-
using System.Runtime.Versioning;
74
using Microsoft.AspNetCore.Hosting;
85
using Microsoft.Extensions.CommandLineUtils;
6+
using Microsoft.Extensions.Hosting;
97

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

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

26-
ApplicationPath = new CommandArgument()
27-
{
28-
Description = "Path to the client application dll",
29-
MultipleValues = false,
30-
Name = "<PATH>",
31-
ShowInHelpText = true
32-
};
33-
Arguments.Add(ApplicationPath);
34-
3524
OnExecute(Execute);
3625
}
3726

38-
public CommandArgument ApplicationPath { get; private set; }
39-
4027
private int Execute()
4128
{
42-
if (string.IsNullOrWhiteSpace(ApplicationPath.Value))
43-
{
44-
throw new InvalidOperationException($"Invalid value for parameter '{nameof(ApplicationPath)}'. Value supplied: '{ApplicationPath.Value}'");
45-
}
46-
47-
Server.Startup.ApplicationAssembly = ApplicationPath.Value;
4829
Server.Program.BuildWebHost(RemainingArguments.ToArray()).Run();
4930
return 0;
5031
}

src/Components/Blazor/DevServer/src/Microsoft.AspNetCore.Blazor.DevServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<Reference Include="Microsoft.AspNetCore.ResponseCompression" />
2020
<Reference Include="Microsoft.AspNetCore" />
2121
<Reference Include="Microsoft.Extensions.CommandLineUtils.Sources" />
22+
<Reference Include="Microsoft.Extensions.Hosting" />
2223
</ItemGroup>
2324

2425
<!-- Pack settings -->
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Threading;
410
using Microsoft.AspNetCore.Hosting;
511
using Microsoft.Extensions.Configuration;
12+
using Microsoft.Extensions.Hosting;
613

714
namespace Microsoft.AspNetCore.Blazor.DevServer.Server
815
{
@@ -18,12 +25,24 @@ public class Program
1825
/// <summary>
1926
/// Intended for framework test use only.
2027
/// </summary>
21-
public static IWebHost BuildWebHost(string[] args) =>
22-
WebHost.CreateDefaultBuilder(args)
23-
.UseConfiguration(new ConfigurationBuilder()
24-
.AddCommandLine(args)
25-
.Build())
26-
.UseStartup<Startup>()
27-
.Build();
28+
public static IHost BuildWebHost(string[] args) =>
29+
Host.CreateDefaultBuilder(args)
30+
.ConfigureHostConfiguration(cb => {
31+
var applicationPath = args.SkipWhile(a => a != "--applicationpath").Skip(1).FirstOrDefault();
32+
var name = Path.ChangeExtension(applicationPath,".StaticWebAssets.xml");
33+
34+
if (name != null)
35+
{
36+
cb.AddInMemoryCollection(new Dictionary<string, string>
37+
{
38+
[WebHostDefaults.StaticWebAssetsKey] = name
39+
});
40+
}
41+
})
42+
.ConfigureWebHostDefaults(webBuilder =>
43+
{
44+
webBuilder.UseStaticWebAssets();
45+
webBuilder.UseStartup<Startup>();
46+
}).Build();
2847
}
2948
}

src/Components/Blazor/DevServer/src/Server/Startup.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ namespace Microsoft.AspNetCore.Blazor.DevServer.Server
1717
{
1818
internal class Startup
1919
{
20-
public static string ApplicationAssembly { get; set; }
20+
public Startup(IConfiguration configuration)
21+
{
22+
Configuration = configuration;
23+
}
24+
25+
public IConfiguration Configuration { get; }
2126

2227
public void ConfigureServices(IServiceCollection services)
2328
{
@@ -35,7 +40,7 @@ public void ConfigureServices(IServiceCollection services)
3540

3641
public void Configure(IApplicationBuilder app, IWebHostEnvironment environment, IConfiguration configuration)
3742
{
38-
var applicationAssemblyFullPath = ResolveApplicationAssemblyFullPath(environment);
43+
var applicationAssemblyFullPath = ResolveApplicationAssemblyFullPath();
3944

4045
app.UseDeveloperExceptionPage();
4146
app.UseResponseCompression();
@@ -54,15 +59,22 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment environment,
5459
});
5560
}
5661

57-
private static string ResolveApplicationAssemblyFullPath(IWebHostEnvironment environment)
62+
private string ResolveApplicationAssemblyFullPath()
5863
{
59-
var applicationAssemblyFullPath = Path.Combine(environment.ContentRootPath, ApplicationAssembly);
60-
if (!File.Exists(applicationAssemblyFullPath))
64+
const string applicationPathKey = "applicationpath";
65+
var configuredApplicationPath = Configuration.GetValue<string>(applicationPathKey);
66+
if (string.IsNullOrEmpty(configuredApplicationPath))
67+
{
68+
throw new InvalidOperationException($"No value was supplied for the required option '{applicationPathKey}'.");
69+
}
70+
71+
var resolvedApplicationPath = Path.GetFullPath(configuredApplicationPath);
72+
if (!File.Exists(resolvedApplicationPath))
6173
{
62-
throw new InvalidOperationException($"Application assembly not found at {applicationAssemblyFullPath}.");
74+
throw new InvalidOperationException($"Application assembly not found at {resolvedApplicationPath}.");
6375
}
6476

65-
return applicationAssemblyFullPath;
77+
return resolvedApplicationPath;
6678
}
6779

6880
private static void EnableConfiguredPathbase(IApplicationBuilder app, IConfiguration configuration)

src/Components/Blazor/DevServer/src/build/Microsoft.AspNetCore.Blazor.DevServer.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<PropertyGroup>
33
<_BlazorDevServerDll>$(MSBuildThisFileDirectory)../tools/blazor-devserver.dll</_BlazorDevServerDll>
44
<RunCommand>dotnet</RunCommand>
5-
<RunArguments>&quot;$(_BlazorDevServerDll)&quot; serve &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot;</RunArguments>
5+
<RunArguments>&quot;$(_BlazorDevServerDll)&quot; serve --applicationpath &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot;</RunArguments>
66
</PropertyGroup>
77
</Project>

src/Components/build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@ECHO OFF
22
SET RepoRoot=%~dp0..\..
3-
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*
3+
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj "/p:EnforceE2ETestPrerequisites=true" %*

src/Components/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -euo pipefail
44

55
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66
repo_root="$DIR/../.."
7-
"$repo_root/build.sh" --projects "$DIR/**/*.*proj" "$@"
7+
"$repo_root/build.sh" --projects "$DIR/**/*.*proj" "/p:EnforceE2ETestPrerequisites=true" "$@"

src/Components/test/E2ETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Hosting.Server;
6+
using Microsoft.AspNetCore.Http.Features;
7+
using Microsoft.Extensions.Hosting;
8+
using System;
59
using System.Collections.Generic;
10+
using System.Threading;
11+
using System.Threading.Tasks;
612
using DevHostServerProgram = Microsoft.AspNetCore.Blazor.DevServer.Server.Program;
713

814
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
@@ -22,7 +28,8 @@ protected override IWebHost CreateWebHost()
2228
{
2329
"--urls", "http://127.0.0.1:0",
2430
"--contentroot", ContentRoot,
25-
"--pathbase", PathBase
31+
"--pathbase", PathBase,
32+
"--applicationpath", typeof(TProgram).Assembly.Location,
2633
};
2734

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

34-
return DevHostServerProgram.BuildWebHost(args.ToArray());
41+
return new FakeWebHost(DevHostServerProgram.BuildWebHost(args.ToArray()));
42+
}
43+
44+
private class FakeWebHost : IWebHost
45+
{
46+
private readonly IHost _realHost;
47+
48+
public FakeWebHost(IHost realHost)
49+
{
50+
_realHost = realHost;
51+
}
52+
53+
public IFeatureCollection ServerFeatures => ((IServer)_realHost.Services.GetService(typeof(IServer))).Features;
54+
55+
public IServiceProvider Services => _realHost.Services;
56+
57+
public void Dispose() => _realHost.Dispose();
58+
59+
public void Start() => _realHost.Start();
60+
61+
public Task StartAsync(CancellationToken cancellationToken = default) => _realHost.StartAsync();
62+
63+
public Task StopAsync(CancellationToken cancellationToken = default) => _realHost.StopAsync();
3564
}
3665
}
3766
}

src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
<TargetFramework>netcoreapp3.0</TargetFramework>
88
<TestGroupName>Components.E2ETests</TestGroupName>
99

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

src/Components/test/testassets/BasicTestApp/wwwroot/index.html

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,39 @@
55
<title>Basic test app</title>
66
<base href="/subdir/" />
77
<link href="style.css" rel="stylesheet" />
8+
9+
<!-- Used by ExternalContentPackage -->
10+
<link href="_content/TestContentPackage/styles.css" rel="stylesheet" />
811
</head>
912
<body>
10-
<root>Loading...</root>
13+
<root>Loading...</root>
14+
15+
<!-- Used for testing interop scenarios between JS and .NET -->
16+
<script src="js/jsinteroptests.js"></script>
1117

12-
<!-- Used for testing interop scenarios between JS and .NET -->
13-
<script src="js/jsinteroptests.js"></script>
18+
<script>
19+
// Used by ElementRefComponent
20+
function setElementValue(element, newValue) {
21+
element.value = newValue;
22+
return element.value;
23+
}
1424

15-
<script>
16-
// Used by ElementRefComponent
17-
function setElementValue(element, newValue) {
18-
element.value = newValue;
19-
return element.value;
20-
}
25+
function uriHelperNavigate() {
26+
Blazor.navigateTo('/subdir/some-path');
27+
}
2128

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

26-
(function () {
27-
// Load either blazor.webassembly.js or blazor.server.js depending
28-
// on the hash part of the URL. This is just to give a way for the
29-
// test runner to make the selection.
30-
var src = location.hash === '#server'
31-
? 'blazor.server.js'
32-
: 'blazor.webassembly.js';
33-
document.write('<script src="_framework/' + src + '"><' + '/script>');
34-
})();
35-
</script>
40+
<!-- Used by ExternalContentPackage -->
41+
<script src="_content/TestContentPackage/prompt.js"></script>
3642
</body>
3743
</html>

src/Components/test/testassets/TestContentPackage/TestContentPackage.csproj

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<OutputType>library</OutputType>
66
<RazorLangVersion>3.0</RazorLangVersion>
7+
<StaticWebAssetBasePath>_content/TestContentPackage</StaticWebAssetBasePath>
78
</PropertyGroup>
89

9-
<ItemGroup>
10-
<!-- .js files will be referenced via <script> tags -->
11-
<EmbeddedResource Include="content\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
12-
13-
<!-- .css files will be referenced via <link rel='Stylesheet'> tags -->
14-
<EmbeddedResource Include="content\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
15-
16-
<!-- Any other files will be included in the 'dist' output but without any tags referencing them -->
17-
<EmbeddedResource Include="content\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
18-
</ItemGroup>
19-
2010
<ItemGroup>
2111
<Reference Include="Microsoft.AspNetCore.Components" />
2212
</ItemGroup>

src/Components/test/testassets/TestServer/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static IWebHost BuildWebHost<TStartup>(string[] args) where TStartup : cl
1919
.AddCommandLine(args)
2020
.Build())
2121
.UseStartup<TStartup>()
22+
.UseStaticWebAssets()
2223
.Build();
2324
}
2425
}

src/Components/test/testassets/TestServer/Startup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using BasicTestApp;
22
using Microsoft.AspNetCore.Authentication.Cookies;
33
using Microsoft.AspNetCore.Builder;
4-
using Microsoft.AspNetCore.Components.Server;
54
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.AspNetCore.Http;
7-
using Microsoft.AspNetCore.Http.Features;
85
using Microsoft.Extensions.Configuration;
96
using Microsoft.Extensions.DependencyInjection;
107
using Microsoft.Extensions.Hosting;
@@ -63,6 +60,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6360
// Mount the server-side Blazor app on /subdir
6461
app.Map("/subdir", subdirApp =>
6562
{
63+
subdirApp.UseStaticFiles();
6664
subdirApp.UseClientSideBlazorFiles<BasicTestApp.Startup>();
6765

6866
subdirApp.UseRouting();

src/DefaultBuilder/src/WebHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ internal static void ConfigureWebDefaults(IWebHostBuilder builder)
211211
{
212212
if (ctx.HostingEnvironment.IsDevelopment())
213213
{
214-
StaticWebAssetsLoader.UseStaticWebAssets(ctx.HostingEnvironment);
214+
StaticWebAssetsLoader.UseStaticWebAssets(ctx.HostingEnvironment, ctx.Configuration);
215215
}
216216
});
217217
builder.UseKestrel((builderContext, options) =>

src/Hosting/Abstractions/ref/Microsoft.AspNetCore.Hosting.Abstractions.netcoreapp3.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public static partial class WebHostDefaults
121121
public static readonly string ServerUrlsKey;
122122
public static readonly string ShutdownTimeoutKey;
123123
public static readonly string StartupAssemblyKey;
124+
public static readonly string StaticWebAssetsKey;
124125
public static readonly string SuppressStatusMessagesKey;
125126
public static readonly string WebRootKey;
126127
}

src/Hosting/Abstractions/src/WebHostDefaults.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ public static class WebHostDefaults
2121
public static readonly string SuppressStatusMessagesKey = "suppressStatusMessages";
2222

2323
public static readonly string ShutdownTimeoutKey = "shutdownTimeoutSeconds";
24+
public static readonly string StaticWebAssetsKey = "staticWebAssets";
2425
}
2526
}

src/Hosting/Hosting/ref/Microsoft.AspNetCore.Hosting.netcoreapp3.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
8282
public partial class StaticWebAssetsLoader
8383
{
8484
public StaticWebAssetsLoader() { }
85-
public static void UseStaticWebAssets(Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment) { }
85+
public static void UseStaticWebAssets(Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment, Microsoft.Extensions.Configuration.IConfiguration configuration) { }
8686
}
8787
}
8888
namespace Microsoft.Extensions.Hosting

0 commit comments

Comments
 (0)