Skip to content

New E2E Migration (PW) test project #31990

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 17 commits into from
May 1, 2021
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
1 change: 1 addition & 0 deletions eng/targets/Helix.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<PropertyGroup Condition="'$(TestDependsOnPlaywright)' == 'true'">
<SkipHelixQueues>Windows.7.Amd64.Open;Windows.81.Amd64.Open;Redhat.7.Amd64.Open;Redhat.7.Amd64;Debian.9.Amd64.Open;Debian.9.Amd64.Open;Ubuntu.2004.Amd64.Open;Ubuntu.2004.Amd64;Ubuntu.1604.Amd64.Open;Ubuntu.1604.Amd64;Alpine.312.Amd64.Open;(Alpine.312.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:alpine-3.12-helix-20200908125345-56c6673;(Fedora.33.Amd64.Open)[email protected]/dotnet-buildtools/prereqs:fedora-33-helix-20210120000908-a9df267</SkipHelixQueues>
<SkipHelixArm>true</SkipHelixArm>
</PropertyGroup>

<ItemGroup Condition="'$(TestDependsOnPlaywright)' == 'true' AND '$(IsWindowsHelixQueue)' == 'true'">
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Components.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
"src\\Components\\WebAssembly\\testassets\\HostedInAspNet.Server\\HostedInAspNet.Server.csproj",
"src\\Components\\WebAssembly\\testassets\\StandaloneApp\\StandaloneApp.csproj",
"src\\Components\\WebAssembly\\testassets\\Wasm.Authentication.Client\\Wasm.Authentication.Client.csproj",
"src\\Components\\WebAssembly\\testassets\\Wasm.Authentication.Shared\\Wasm.Authentication.Shared.csproj",
"src\\Components\\WebAssembly\\testassets\\Wasm.Authentication.Server\\Wasm.Authentication.Server.csproj",
"src\\Components\\WebAssembly\\testassets\\Wasm.Authentication.Shared\\Wasm.Authentication.Shared.csproj",
"src\\Components\\WebAssembly\\testassets\\WasmLinkerTest\\WasmLinkerTest.csproj",
"src\\Components\\Web\\src\\Microsoft.AspNetCore.Components.Web.csproj",
"src\\Components\\Web\\test\\Microsoft.AspNetCore.Components.Web.Tests.csproj",
"src\\Components\\benchmarkapps\\Wasm.Performance\\Driver\\Wasm.Performance.Driver.csproj",
"src\\Components\\benchmarkapps\\Wasm.Performance\\TestApp\\Wasm.Performance.TestApp.csproj",
"src\\Components\\test\\E2ETestMigration\\Microsoft.AspNetCore.Components.Migration.E2ETests.csproj",
"src\\Components\\test\\E2ETest\\Microsoft.AspNetCore.Components.E2ETests.csproj",
"src\\Components\\test\\testassets\\BasicTestApp\\BasicTestApp.csproj",
"src\\Components\\test\\testassets\\ComponentsApp.Server\\ComponentsApp.Server.csproj",
Expand Down Expand Up @@ -74,7 +75,6 @@
"src\\Middleware\\Localization\\src\\Microsoft.AspNetCore.Localization.csproj",
"src\\Middleware\\ResponseCaching.Abstractions\\src\\Microsoft.AspNetCore.ResponseCaching.Abstractions.csproj",
"src\\Middleware\\ResponseCompression\\src\\Microsoft.AspNetCore.ResponseCompression.csproj",
"src\\Middleware\\SpaServices.Extensions\\src\\Microsoft.AspNetCore.SpaServices.Extensions.csproj",
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj",
"src\\Middleware\\WebSockets\\src\\Microsoft.AspNetCore.WebSockets.csproj",
"src\\Mvc\\Mvc.Abstractions\\src\\Microsoft.AspNetCore.Mvc.Abstractions.csproj",
Expand Down Expand Up @@ -114,4 +114,4 @@
"src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj"
]
}
}
}
1 change: 1 addition & 0 deletions src/Components/ComponentsNoDeps.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"src\\Components\\benchmarkapps\\Wasm.Performance\\Driver\\Wasm.Performance.Driver.csproj",
"src\\Components\\benchmarkapps\\Wasm.Performance\\TestApp\\Wasm.Performance.TestApp.csproj",
"src\\Components\\test\\E2ETest\\Microsoft.AspNetCore.Components.E2ETests.csproj",
"src\\Components\\test\\E2ETestMigration\\Microsoft.AspNetCore.Components.Migration.E2ETests.csproj",
"src\\Components\\test\\testassets\\BasicTestApp\\BasicTestApp.csproj",
"src\\Components\\test\\testassets\\ComponentsApp.Server\\ComponentsApp.Server.csproj",
"src\\Components\\test\\testassets\\GlobalizationWasmApp\\GlobalizationWasmApp.csproj",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.BrowserTesting;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure
{
public class PlaywrightTestBase : LoggedTest, IAsyncLifetime
{
private static readonly bool _isCIEnvironment =
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("ContinuousIntegrationBuild"));

public PlaywrightTestBase(ITestOutputHelper output) : base(output) { }

protected async override Task InitializeCoreAsync(TestContext context)
{
BrowserManager = await BrowserManager.CreateAsync(CreateConfiguration(), LoggerFactory);
BrowserContextInfo = new ContextInformation(LoggerFactory);
_output = new TestOutputLogger(Logger);
}

public Task InitializeAsync() => Task.CompletedTask;

private static IConfiguration CreateConfiguration()
{
var basePath = Path.GetDirectoryName(typeof(PlaywrightTestBase).Assembly.Location);
var os = Environment.OSVersion.Platform switch
{
PlatformID.Win32NT => "win",
PlatformID.Unix => "linux",
PlatformID.MacOSX => "osx",
_ => null
};

var builder = new ConfigurationBuilder()
.AddJsonFile(Path.Combine(basePath, "playwrightSettings.json"))
.AddJsonFile(Path.Combine(basePath, $"playwrightSettings.{os}.json"), optional: true);

if (_isCIEnvironment)
{
builder.AddJsonFile(Path.Combine(basePath, "playwrightSettings.ci.json"), optional: true)
.AddJsonFile(Path.Combine(basePath, $"playwrightSettings.ci.{os}.json"), optional: true);
}

if (Debugger.IsAttached)
{
builder.AddJsonFile(Path.Combine(basePath, "playwrightSettings.debug.json"), optional: true);
}

return builder.Build();
}

public Task DisposeAsync() => BrowserManager.DisposeAsync();

private ITestOutputHelper _output;
public ITestOutputHelper Output
{
get
{
if (_output == null)
{
_output = new TestOutputLogger(Logger);
}
return _output;
}
}

public ContextInformation BrowserContextInfo { get; protected set; }
public BrowserManager BrowserManager { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
{
public enum AspNetEnvironment
{
Development,
Production
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.IO;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
{
public class AspNetSiteServerFixture : WebHostServerFixture
{
public delegate IHost BuildWebHost(string[] args);

public Assembly ApplicationAssembly { get; set; }

public BuildWebHost BuildWebHostMethod { get; set; }

public AspNetEnvironment Environment { get; set; } = AspNetEnvironment.Production;

public List<string> AdditionalArguments { get; set; } = new List<string> { "--test-execution-mode", "server" };

protected override IHost CreateWebHost()
{
if (BuildWebHostMethod == null)
{
throw new InvalidOperationException(
$"No value was provided for {nameof(BuildWebHostMethod)}");
}

var assembly = ApplicationAssembly ?? BuildWebHostMethod.Method.DeclaringType.Assembly;
var sampleSitePath = FindSampleOrTestSitePath(assembly.FullName);

var host = "127.0.0.1";

return BuildWebHostMethod(new[]
{
"--urls", $"http://{host}:0",
"--contentroot", sampleSitePath,
"--environment", Environment.ToString(),
}.Concat(AdditionalArguments).ToArray());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
{
public class BasicTestAppServerSiteFixture<TStartup> : AspNetSiteServerFixture where TStartup : class
{
public BasicTestAppServerSiteFixture()
{
BuildWebHostMethod = TestServer.Program.BuildWebHost<TStartup>;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 Microsoft.Extensions.Hosting;
using System.Collections.Generic;
using DevHostServerProgram = Microsoft.AspNetCore.Components.WebAssembly.DevServer.Server.Program;

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
{
public class DevHostServerFixture<TProgram> : WebHostServerFixture
{
public string Environment { get; set; }
public string PathBase { get; set; }
public string ContentRoot { get; private set; }

protected override IHost CreateWebHost()
{
ContentRoot = FindSampleOrTestSitePath(
typeof(TProgram).Assembly.FullName);

var host = "127.0.0.1";

var args = new List<string>
{
"--urls", $"http://{host}:0",
"--contentroot", ContentRoot,
"--pathbase", PathBase,
"--applicationpath", typeof(TProgram).Assembly.Location,
};

if (!string.IsNullOrEmpty(Environment))
{
args.Add("--environment");
args.Add(Environment);
}

return DevHostServerProgram.BuildWebHost(args.ToArray());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// 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.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading;

namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures
{
public abstract class ServerFixture : IDisposable
{
private static readonly Lazy<Dictionary<string, string>> _projects = new Lazy<Dictionary<string, string>>(FindProjects);

public Uri RootUri => _rootUriInitializer.Value;

private readonly Lazy<Uri> _rootUriInitializer;

public ServerFixture()
{
_rootUriInitializer = new Lazy<Uri>(() =>
{
var uri = new Uri(StartAndGetRootUri());

return uri;
});
}

public abstract void Dispose();

protected abstract string StartAndGetRootUri();

private static Dictionary<string, string> FindProjects()
{
return typeof(ServerFixture).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.Where(m => m.Key.StartsWith("TestAssemblyApplication[", StringComparison.Ordinal))
.ToDictionary(m =>
m.Key.Replace("TestAssemblyApplication", "").TrimStart('[').TrimEnd(']'),
m => m.Value);
}

public static string FindSampleOrTestSitePath(string projectName)
{
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix")))
{
var comma = projectName.IndexOf(",", StringComparison.Ordinal);
if (comma != -1)
{
projectName = projectName.Substring(0, comma);
}
if (string.Equals(projectName, "Components.TestServer", StringComparison.Ordinal))
{
projectName = "TestServer"; // This testasset doesn't match the folder name for some reason
}
var path = Path.Combine(AppContext.BaseDirectory, "testassets", projectName);
if (!Directory.Exists(path))
{
throw new ArgumentException($"Cannot find a sample or test site directory: '{path}'.");
}
return path;
}

var projects = _projects.Value;
if (projects.TryGetValue(projectName, out var dir))
{
return dir;
}

throw new ArgumentException($"Cannot find a sample or test site with name '{projectName}'.");
}

protected static void RunInBackgroundThread(Action action)
{
var isDone = new ManualResetEvent(false);

ExceptionDispatchInfo edi = null;
new Thread(() =>
{
try
{
action();
}
catch (Exception ex)
{
edi = ExceptionDispatchInfo.Capture(ex);
}

isDone.Set();
}).Start();

if (!isDone.WaitOne(TimeSpan.FromSeconds(10)))
{
throw new TimeoutException("Timed out waiting for: " + action);
}

if (edi != null)
{
throw edi.SourceException;
}
}
}
}
Loading