Skip to content

Commit

Permalink
Merge pull request #3 from KristofferStrube/feature/playwright-tests
Browse files Browse the repository at this point in the history
Started on adding Playwright test setup.
  • Loading branch information
KristofferStrube authored Apr 15, 2024
2 parents 54e95b8 + e3386bf commit 165ad13
Show file tree
Hide file tree
Showing 23 changed files with 517 additions and 7 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checkout the code
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# Install .NET 7.0 SDK
- name: Setup .NET 7 preview
uses: actions/setup-dotnet@v1
# Install .NET 8.0 SDK
- name: Setup .NET 8 preview
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'
include-prerelease: true

# Build
- name: Build
run: dotnet build

# Install PlayWright
- name: Install PlayWright
run: pwsh tests/IntegrationTests/bin/Debug/net8.0/playwright.ps1 install --with-deps

# Run tests
- name: Test
run: dotnet test

# Generate the website
- name: Publish
run: dotnet publish samples/KristofferStrube.Blazor.MediaCaptureStreams.WasmExample/KristofferStrube.Blazor.MediaCaptureStreams.WasmExample.csproj --configuration Release --output build
Expand Down
18 changes: 18 additions & 0 deletions Blazor.MediaCaptureStreams.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KristofferStrube.Blazor.Med
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KristofferStrube.Blazor.MediaCaptureStreams.WasmExample", "samples\KristofferStrube.Blazor.MediaCaptureStreams.WasmExample\KristofferStrube.Blazor.MediaCaptureStreams.WasmExample.csproj", "{78DF92DF-FAA4-44A5-8357-D931F0E56AAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTests", "tests\IntegrationTests\IntegrationTests.csproj", "{C2D2DA0F-81A0-4AC0-86BD-4F9806EEBB5E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{33733603-EC0E-45DC-852E-23502F1BB155}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorServer", "tests\BlazorServer\BlazorServer.csproj", "{691244C2-4262-44AC-BB45-7C076BF06FD9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,10 +27,22 @@ Global
{78DF92DF-FAA4-44A5-8357-D931F0E56AAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78DF92DF-FAA4-44A5-8357-D931F0E56AAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78DF92DF-FAA4-44A5-8357-D931F0E56AAF}.Release|Any CPU.Build.0 = Release|Any CPU
{C2D2DA0F-81A0-4AC0-86BD-4F9806EEBB5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2D2DA0F-81A0-4AC0-86BD-4F9806EEBB5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2D2DA0F-81A0-4AC0-86BD-4F9806EEBB5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2D2DA0F-81A0-4AC0-86BD-4F9806EEBB5E}.Release|Any CPU.Build.0 = Release|Any CPU
{691244C2-4262-44AC-BB45-7C076BF06FD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{691244C2-4262-44AC-BB45-7C076BF06FD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{691244C2-4262-44AC-BB45-7C076BF06FD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{691244C2-4262-44AC-BB45-7C076BF06FD9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C2D2DA0F-81A0-4AC0-86BD-4F9806EEBB5E} = {33733603-EC0E-45DC-852E-23502F1BB155}
{691244C2-4262-44AC-BB45-7C076BF06FD9} = {33733603-EC0E-45DC-852E-23502F1BB155}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ED852F74-EBA5-48B9-AEB3-EC4C1AC847F7}
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal BaseJSWrapper(IJSRuntime jSRuntime, IJSObjectReference jSReference)
}

/// <summary>
/// Disposes the
/// Disposes the underlying js object reference.
/// </summary>
/// <returns></returns>
public async ValueTask DisposeAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MediaDevices : EventTarget
protected MediaDevices(IJSRuntime jSRuntime, IJSObjectReference jSReference) : base(jSRuntime, jSReference)
{
mediaCaptureStreamsHelperTask = new(jSRuntime.GetHelperAsync);
if (ErrorHandlingJSInterop.ErrorHandlingJSInteropHasBeenSetup)
if (jSRuntime is not IJSInProcessRuntime || ErrorHandlingJSInterop.ErrorHandlingJSInteropHasBeenSetup)
{
errorHandlingJSReference = new ErrorHandlingJSObjectReference(jSRuntime, jSReference)
{
Expand Down
12 changes: 12 additions & 0 deletions tests/BlazorServer/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
13 changes: 13 additions & 0 deletions tests/BlazorServer/BlazorServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\KristofferStrube.Blazor.MediaCaptureStreams\KristofferStrube.Blazor.MediaCaptureStreams.csproj" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions tests/BlazorServer/EvaluationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BlazorServer;

public class EvaluationContext
{
public object? Result { get; set; }

public Exception? Exception { get; set; }

public Func<Task<object?>>? AfterRenderAsync { get; set; }
}
3 changes: 3 additions & 0 deletions tests/BlazorServer/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@inherits LayoutComponentBase

<main> @Body </main>
28 changes: 28 additions & 0 deletions tests/BlazorServer/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@page "/"

<span data-testid="result">@result</span>

@code {
string? result;

[Inject]
public required EvaluationContext EvaluationContext { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
try
{
if (EvaluationContext.AfterRenderAsync is not null)
{
EvaluationContext.Result = await EvaluationContext.AfterRenderAsync.Invoke();
}
}
catch (Exception e)
{
EvaluationContext.Exception = e;
}
result = "done";
StateHasChanged();
}
}
30 changes: 30 additions & 0 deletions tests/BlazorServer/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@page "/"
@using Microsoft.AspNetCore.Components.Web
@namespace BlazorServer.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="~/" />
<link href="css/site.css" rel="stylesheet" />
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />

<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

<script src="_framework/blazor.server.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions tests/BlazorServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using KristofferStrube.Blazor.MediaCaptureStreams;
using Microsoft.Extensions.Hosting;

namespace BlazorServer;

public class Program
{
private static async Task Main(string[] args)
{
var host = BuildWebHost(args, _ => { });
await host.RunAsync();
}

public static IHost BuildWebHost(string[] args, Action<IServiceCollection> configureServices)
=> Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(builder =>
{
builder.UseStaticWebAssets();
builder.UseStartup<Startup>();
builder.ConfigureServices(configureServices);
})
.Build();
}
35 changes: 35 additions & 0 deletions tests/BlazorServer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"iisSettings": {
"iisExpress": {
"applicationUrl": "http://localhost:1729",
"sslPort": 44325
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5151",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7131;http://localhost:5151",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
35 changes: 35 additions & 0 deletions tests/BlazorServer/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using KristofferStrube.Blazor.MediaCaptureStreams;

namespace BlazorServer;

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddMediaDevicesService();
}

public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
4 changes: 4 additions & 0 deletions tests/BlazorServer/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using BlazorServer
9 changes: 9 additions & 0 deletions tests/BlazorServer/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions tests/BlazorServer/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
28 changes: 28 additions & 0 deletions tests/BlazorServer/wwwroot/css/site.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}

#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 3.5rem;
top: 0.5rem;
}

.blazor-error-boundary {
background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iN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aTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
padding: 1rem 1rem 1rem 3.7rem;
color: white;
}

.blazor-error-boundary::after {
content: "An error has occurred."
}
Loading

0 comments on commit 165ad13

Please sign in to comment.