Repository navigation
Enable Microsoft.Testing.Platform on browser-wasm (#2196) - #9857
Merged
Merged
Conversation
Follow-up to the wasi-wasm work: the platform runtime was already browser-aware
(single-threaded fallbacks, BrowserOutputDevice, OperatingSystem.IsBrowser guards);
what was missing was the JS host harness and tooling that wasi never needed.
- BrowserOutputDevice: fix JSConsoleWarn to resolve against globalThis (drop the stray
'main.js' module arg that was never registered and would throw at call time).
- samples/BrowserPlayground: browser-wasm MTP sample mirroring WasiPlayground, with a JS
boot module (wwwroot/main.js), index.html, a headless node runner (runtests.mjs), and a
README documenting the run flows and unsupported-feature matrix. Verified end-to-end
under node: MTP boots ([browser-wasm - net10.0]) and the test passes.
- BrowserWasmExecutionTests: gated acceptance test mirroring WasmExecutionTests (always-on
entry-point build assertion + node-hosted end-to-end run), Inconclusive when the
wasm-tools workload or node is unavailable.
- eng/restore-toolset.{ps1,sh}: document the wasm-tools workload requirement (kept opt-in).
- FileLoggerTests: mark [UnsupportedOSPlatform("browser")] to fix a pre-existing CA1416
break (test doubles forward to ITask.RunLongRunning, which is browser-unsupported).
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Contributor
There was a problem hiding this comment.
Pull request overview
Adds browser-wasm hosting and validation for Microsoft.Testing.Platform.
Changes:
- Fixes browser console warning interop.
- Adds a browser/Node WASM sample and tooling guidance.
- Adds gated browser-wasm acceptance coverage.
Show a summary per file
| File | Description |
|---|---|
BrowserOutputDevice.cs |
Fixes global console warning binding. |
BrowserWasmExecutionTests.cs |
Adds build and Node execution tests. |
FileLoggerTests.cs |
Marks tests unsupported on browsers. |
BrowserPlayground.csproj |
Configures browser-wasm publishing. |
Program.cs |
Hosts MTP with browser-safe extensions. |
README.md |
Documents setup, execution, and limitations. |
wwwroot/main.js |
Boots MTP in browsers. |
wwwroot/runtests.mjs |
Runs the bundle under Node. |
wwwroot/index.html |
Provides the browser host page. |
restore-toolset.sh |
Documents the optional workload. |
restore-toolset.ps1 |
Documents the optional workload. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 6
- Review effort level: Medium
- restore-toolset.{ps1,sh}: install the wasm-tools-net10 workload in CI so the
browser-wasm build/run is actually exercised instead of always Inconclusive.
- BrowserWasmExecutionTests: detect the wasm-tools workload up front (via
'dotnet workload list') and skip only when it is genuinely absent; once present,
build and publish must succeed (no longer swallow failures as "workload missing").
- Assert the exact ExitCode.AtLeastOneTestFailed (2) instead of a generic non-zero
check, so post-run crashes can't masquerade as the expected failing-test outcome.
- JS runners (sample runtests.mjs + the acceptance test's node runner): set
process.exitCode instead of calling process.exit(), so Node drains redirected
stdout/stderr before exiting and the asserted MTP summary isn't truncated.
- Docs updated to reflect that the bootstrap now installs the workload.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
…c-tribble # Conflicts: # eng/restore-toolset.ps1 # eng/restore-toolset.sh
…time reuse - Remove AddTrxReportProvider from BrowserPlayground (TRX's streaming writer uses ITask.RunLongRunning / BlockingCollection, unsupported on browser); list TRX as unavailable in the README matrix and drop the unused project reference. - Add BrowserWasmExecution_FrameworkWarningReachesNode: a custom-framework asset emits a WarningMessageOutputDeviceData + ErrorMessageOutputDeviceData that must reach Node output via the [JSImport] console bindings, directly guarding the BrowserOutputDevice.JSConsoleWarn fix. Validated end-to-end under node. - Reuse the shared WasmRuntime helper (extended with browser-wasm LocateNode/PublishForBrowserAsync/GetBrowserAppBundlePath/RunUnderNodeAsync) instead of bespoke detection, mirroring the wasi tests: skip only on the NETSDK1147 missing-'wasm-tools' signature, fail on any other build/publish error. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Amaury Levé (Evangelink)
marked this pull request as ready for review
July 11, 2026 20:32
Petr Pokorny (0101)
approved these changes
Jul 11, 2026
This comment has been minimized.
This comment has been minimized.
Petr Pokorny (0101)
approved these changes
Jul 11, 2026
This comment has been minimized.
This comment has been minimized.
- README: replace Windows-only commands/paths with cross-platform forms (repo-local dotnet path shown for both OSes, forward-slash paths), and replace the 'dotnet serve' browser step (not an SDK command / not provisioned by the repo) with 'npx http-server' or 'python3 -m http.server'. Verified the browser flow end-to-end in a headless Chromium: MTP boots [browser-wasm - net10.0], the test passes, exit 0. - csproj: use singular <TargetFramework> (single TFM) instead of <TargetFrameworks>, matching the other playground samples and avoiding the outer multi-TFM build loop. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
main removed samples/WasiPlayground (its wasi coverage is now the inline WasmExecutionTests acceptance asset). Repoint the BrowserPlayground README and the eng/restore-toolset.{ps1,sh} comments away from the deleted sample to the wasi acceptance assets (WasmExecutionTests.cs) so contributors can actually find the referenced code.
Also clarify the 'Not part of TestFx.slnx' note: the bootstrap installs wasm-tools, so the exclusion is to protect solution/IDE builds that bypass the bootstrap, not the default build.cmd.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Petr Pokorny (0101)
approved these changes
Jul 13, 2026
This comment has been minimized.
This comment has been minimized.
…rowser The Linux CI leg for BrowserWasmExecution_RunsTestsUnderNode failed because the standard MSTest runner flow crashes at startup on browser-wasm. Two auto-registered extensions throw PlatformNotSupportedException on browser: 1. Microsoft.Testing.Platform.MSBuild's TestingPlatformBuilderHook.AddExtensions (auto-registered because MSTest.TestAdapter references it) called AddMSBuild, which throws on browser. The MSBuild/dotnet-test integration relies on named-pipe IPC unavailable on browser, so skip it there instead of throwing. 2. MSTest's AddMSTest registered a TestHostControllers environment-variable provider (applies runsettings <EnvironmentVariables> by relaunching the host); test host controllers require process restart, which browser-wasm does not support. Guard the registration with !OperatingSystem.IsBrowser(). Both are real bugs for any browser-wasm MSTest user, not just the test. Validated end-to-end under node with locally-packed packages: MSTest boots ([browser-wasm - net10.0]) and reports succeeded: 2 / failed: 1, exit 2 (AtLeastOneTestFailed). Also adjust the acceptance test to assert the run summary against combined stdout+stderr: on browser-wasm the failed-run summary is routed through BrowserOutputDevice.ConsoleError -> console.error (stderr), unlike wasi where everything lands on stdout. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Petr Pokorny (0101)
approved these changes
Jul 13, 2026
This comment has been minimized.
This comment has been minimized.
…entVariables on browser Markdown lint (MD040/MD012): add the 'sh' language to the four fenced code blocks in samples/BrowserPlayground/README.md and drop the extra trailing blank line. Review feedback: skipping the MSTest env-var provider on browser silently dropped a requested runsettings <EnvironmentVariables> section, changing test semantics. Applying it in-process is not possible (it needs a test-host-controller process restart, unsupported on browser), so instead the shared '--settings' command-line validation (RunSettingsCommandLineOptionsProviderBase, used by both the MSTest adapter and the VSTest bridge) now fails with a clear unsupported-platform diagnostic when a browser run supplies runsettings that declare <EnvironmentVariables>. Guarded to NETCOREAPP (browser-wasm only runs there; OperatingSystem.IsBrowser is built-in since .NET 8, no polyfill needed). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Petr Pokorny (0101)
approved these changes
Jul 13, 2026
This comment has been minimized.
This comment has been minimized.
…lize diagnostic Two review points on the browser-wasm runsettings <EnvironmentVariables> handling: 1. The previous guard only rejected the section when supplied via --settings (ValidateOptionArgumentsAsync). MSTest/VSTest also accept runsettings from the TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS and TESTINGPLATFORM_VSTESTBRIDGE_RUNSETTINGS_FILE environment variables, which bypass that hook. Moved the browser check to ValidateCommandLineOptionsAsync (runs once, always) and resolve the runsettings via RunSettingsProviderHelper.TryLoadRunSettingsAsync, which covers all three sources. 2. The diagnostic was hard-coded in the resource-independent shared base. Made it an abstract EnvironmentVariablesNotSupportedOnBrowserError property that each concrete provider supplies from its own resources (ExtensionResources for the VSTest bridge, PlatformAdapterResources for the MSTest adapter), so it is localizable. Added the resource entries and regenerated the XLF for all languages; declared the new internal API members in InternalAPI.Unshipped.txt for both projects. Builds clean (0 warnings) across net9.0/net8.0/net462/netstandard2.0. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Petr Pokorny (0101)
approved these changes
Jul 13, 2026
This comment has been minimized.
This comment has been minimized.
…ariables rejection Adds BrowserWasmExecution_RunSettingsEnvironmentVariables_FailsWithClearDiagnostic: publishes a browser-wasm MSTest project, boots it under node with a runsettings <EnvironmentVariables> section supplied via the TESTINGPLATFORM_EXPERIMENTAL_VSTEST_RUNSETTINGS content environment variable (using the dotnet.js withEnvironmentVariable API), and asserts the run is rejected with the localized unsupported-platform diagnostic and exit code InvalidCommandLine (5). This exercises RunSettingsCommandLineOptionsProviderBase.ValidateCommandLineOptionsAsync -> TryLoadRunSettingsAsync end-to-end, i.e. the environment-variable runsettings resolution path (not just --settings). Validated locally: the run exits 5 and emits the exact diagnostic 'The runsettings EnvironmentVariables section is not supported on browser/WebAssembly platforms...'. (The --settings and file env-var sources fail earlier on the wasm virtual filesystem's file-path resolution, unrelated to this validation, so the content source is used for reliable coverage.) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 730677ed-c8a9-4a0e-aeb8-0c5793072ed7
Petr Pokorny (0101)
approved these changes
Jul 13, 2026
Contributor
🧪 Test quality grade — PR #9857
This advisory comment was generated automatically. Grades are heuristic Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Member
Author
|
/azp run microsoft.testfx |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the wasi-wasm work (#2196). The platform runtime was already browser-aware — the single-threaded fallbacks (
RuntimeFeatureHelper.IsMultiThreaded/RuntimeContext.IsMultiThreaded),BrowserOutputDevice, and theOperatingSystem.IsBrowser()guards throughout the platform and extensions were all shared with the wasi effort. What was missing was the JS host harness + tooling that wasi never needed (wasi runs headless underwasmtime; browser-wasm boots through a JS module that loadsdotnet.js).This PR adds that layer and validates it end-to-end.
Changes
BrowserOutputDevice—JSConsoleWarnused[JSImport("globalThis.console.warn", "main.js")], but nosetModuleImports('main.js', …)module is ever registered, so the binding would throw at call time. Dropped the stray module arg sowarnresolves againstglobalThislikeerror/log.samples/BrowserPlayground/(new) — a browser-wasm MTP sample mirroringWasiPlayground:Program.cs(DummyFramework, registers only the browser-safe telemetry provider), a JS boot module (wwwroot/main.js),index.html, a headless node runner (wwwroot/runtests.mjs), and a README documenting the browser + node run flows and the unsupported-feature matrix. Intentionally not added toTestFx.slnx(browser-wasm needs thewasm-toolsworkload even to build).BrowserWasmExecutionTests(new) — gated acceptance tests mirroringWasmExecutionTests, built on the sharedWasmRuntimehelper:AtLeastOneTestFailed),IOutputDevice, asserting both reach the node output via the[JSImport]console bindings — directly guarding theJSConsoleWarnfix.Each skips (Inconclusive) only on the specific NETSDK1147 missing-
wasm-toolssignature or whennodeis unavailable; any other build/publish failure fails the test.eng/restore-toolset.{ps1,sh}— the repo bootstrap now installs thewasm-tools-net10workload (main already added it for the wasi publish step; this PR documents the browser-wasm requirement alongside it), so CI and local bootstrap exercise the browser-wasm build and, wherenodeis present, the end-to-end run — the gated tests are no longer perpetually Inconclusive.FileLoggerTests— the pre-existing CA1416 break is fixed onmain(Fix CA1416 build failure in FileLoggerTests #9844, method-level[UnsupportedOSPlatform("browser")]); this branch defers to that fix.Verification
Installed the
wasm-tools-net10workload, publishedsamples/BrowserPlaygroundforbrowser-wasm, and ran the published AppBundle headlessly under node (node runtests.mjs):Separately validated the warning path end-to-end (a framework emitting
WarningMessageOutputDeviceData/ErrorMessageOutputDeviceData): both markers reach node stderr via theconsole.warn/console.error[JSImport]bindings with a clean exit — proving theJSConsoleWarnfix.Node works headlessly because Microsoft.Testing.Platform never touches the DOM, so the same bundle the browser loads also boots under the
dotnet.jsloader in node.Publish-config notes (captured in the sample csproj + README):
SelfContained=trueis required (otherwise the mono browser-wasm runtime pack isn't resolved when targetingnet10.0under an11.0SDK);InvariantGlobalizationis left unset (on browser-wasm it forcesWasmBuildNative=true/an emscripten relink);WasmExtraFilesToDeploylands the node runner /index.htmlin theAppBundle.Build status:
Microsoft.Testing.Platform(incl. browser TFM / CA1416), the acceptance project, and the full merged tree all build clean.Feature matrix
Several capabilities remain unavailable on browser-wasm (guarded by
OperatingSystem.IsBrowser()): TRX report (--report-trx; its streaming writer usesITask.RunLongRunning/BlockingCollection<T>), hang/crash dumps (System.Diagnostics.Process, #8557), Azure DevOps report (HttpClient.AutomaticDecompression), server mode /dotnet testpipe (TCP/named-pipe IPC),--exit-on-process-exitand wait-for-debugger, and synchronous file-logger flush. The sample therefore registers only the telemetry provider.