Skip to content

Conversation

@ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Feb 12, 2026

Follow up for #65037.

Summary

Adds end-to-end browser tests for the webworker template introduced in #65037. Tests verify that the template produces a functional web worker that can be invoked from a Blazor WASM application.

Changes

  • Test fixture (IAsyncLifetime): Creates the Blazor WASM host app once per test class
  • Per-test setup: Each test creates a fresh webworker library via dotnet new webworker, adds reference via dotnet add reference, runs browser tests, then cleans up (removes reference and deletes directory)
  • Browser automation: Uses Playwright to verify worker initialization, method invocation, error handling, and disposal
  • Test assets: Reusable Razor component and worker methods with namespace placeholder

Test Coverage

Test Validates
WebWorkerTemplate_CanInvokeMethods Worker initialization, primitive/string/JSON method calls
WebWorkerTemplate_HandlesErrors Exception propagation from worker to main thread
WebWorkerTemplate_CanDisposeWorker Worker disposal via DisposeAsync

@ilonatommy ilonatommy added this to the 11.0-preview2 milestone Feb 12, 2026
@ilonatommy ilonatommy requested a review from javiercn February 12, 2026 14:28
@ilonatommy ilonatommy self-assigned this Feb 12, 2026
Copilot AI review requested due to automatic review settings February 12, 2026 14:28
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Feb 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive end-to-end browser tests for the webworker template introduced in PR #65037. The tests validate the webworker template by creating a Blazor WASM host application, adding a webworker library, and using Playwright to exercise worker functionality through the browser UI.

Changes:

  • Added new E2E test class with three test methods validating worker initialization, method invocation, error handling, and disposal
  • Created test assets including a Razor test page and JSExport worker methods for exercising worker functionality
  • Updated project file to include test assets with proper copy and compilation exclusions

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
WebWorkerTemplateE2ETest.cs New test class implementing IAsyncLifetime to create host project once, then run three tests validating worker operations via Playwright
TestAssets/WebWorker/WebWorkerTest.razor Blazor test page with UI buttons to initialize worker and test Add, Echo, JSON, error handling, and disposal operations
TestAssets/WebWorker/TestWorkerMethods.cs JSExport methods (Add, Echo, GetPersonJson, ThrowError, plus unused IsEven, Divide, Concat) for worker testing
Templates.Blazor.Tests.csproj Added ItemGroup to copy test assets to output and exclude them from compilation
Comments suppressed due to low confidence (1)

src/ProjectTemplates/test/Templates.Blazor.Tests/WebWorkerTemplateE2ETest.cs:283

  • The string interpolation in WaitForFunctionAsync creates a potential security vulnerability if selector or expectedText contain single quotes. The JavaScript code is constructed using string interpolation which could break if the values contain special characters. Consider using Playwright's more robust waitForSelector with text matching, or properly escape the values before interpolation.

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@ilonatommy ilonatommy enabled auto-merge (squash) February 12, 2026 14:44
@ilonatommy ilonatommy disabled auto-merge February 12, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants