-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Add E2E tests for webworker template #65405
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
src/ProjectTemplates/test/Templates.Blazor.Tests/TestAssets/WebWorker/TestWorkerMethods.cs
Outdated
Show resolved
Hide resolved
src/ProjectTemplates/test/Templates.Blazor.Tests/WebWorkerTemplateE2ETest.cs
Outdated
Show resolved
Hide resolved
src/ProjectTemplates/test/Templates.Blazor.Tests/WebWorkerTemplateE2ETest.cs
Outdated
Show resolved
Hide resolved
src/ProjectTemplates/test/Templates.Blazor.Tests/WebWorkerTemplateE2ETest.cs
Outdated
Show resolved
Hide resolved
src/ProjectTemplates/test/Templates.Blazor.Tests/WebWorkerTemplateE2ETest.cs
Outdated
Show resolved
Hide resolved
src/ProjectTemplates/test/Templates.Blazor.Tests/WebWorkerTemplateE2ETest.cs
Show resolved
Hide resolved
javiercn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
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 Coverage
WebWorkerTemplate_CanInvokeMethodsWebWorkerTemplate_HandlesErrorsWebWorkerTemplate_CanDisposeWorkerDisposeAsync