Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bff1785
Enable Microsoft.Testing.Platform on browser-wasm (#2196)
Evangelink Jul 11, 2026
e91368b
Address PR review: harden browser-wasm acceptance tests and CI coverage
Evangelink Jul 11, 2026
f8a438d
Merge remote-tracking branch 'origin/main' into dev/amauryleve/psychi…
Evangelink Jul 11, 2026
b740fcf
Address PR review: browser-wasm TRX matrix, warning coverage, WasmRun…
Evangelink Jul 11, 2026
d8f721e
Merge branch 'main' into dev/amauryleve/psychic-tribble
Evangelink Jul 11, 2026
b7f592b
Address PR review: cross-platform BrowserPlayground docs, singular TFM
Evangelink Jul 11, 2026
6e8b701
Address PR review: fix references to removed WasiPlayground sample
Evangelink Jul 11, 2026
33059f3
Address PR review: correct 'MTP-generated Program.Main' wording in sa…
Evangelink Jul 11, 2026
95d742e
Merge branch 'main' into dev/amauryleve/psychic-tribble
Evangelink Jul 13, 2026
2b5e8b2
Address PR review: drop server/container ProjectCapability from brows…
Evangelink Jul 13, 2026
ccb3cf5
Address PR review: fix cross-platform path note in BrowserPlayground …
Evangelink Jul 13, 2026
694eaab
Merge branch 'main' into dev/amauryleve/psychic-tribble
Evangelink Jul 13, 2026
461cd75
Address PR review: normalize LocateNode path + refresh WasmRuntime su…
Evangelink Jul 13, 2026
5304cf1
Merge branch 'main' into dev/amauryleve/psychic-tribble
Evangelink Jul 13, 2026
a8fda39
Fix browser-wasm test execution: skip process-restart extensions on b…
Evangelink Jul 13, 2026
85548b6
Fix markdown lint + surface clear diagnostic for runsettings Environm…
Evangelink Jul 13, 2026
d33364c
Address PR review: validate all runsettings sources on browser + loca…
Evangelink Jul 13, 2026
4173533
Add browser-wasm acceptance coverage for the runsettings EnvironmentV…
Evangelink Jul 13, 2026
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
19 changes: 12 additions & 7 deletions eng/restore-toolset.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
# AFTER InitializeDotNetCli has bootstrapped the repo-local .dotnet/ SDK, so
# $RepoRoot and the helpers from eng/common/tools.ps1 are in scope.
#
# Required by the wasi-wasm acceptance tests:
# Required by the wasm acceptance tests (and the browser-wasm sample):
# - test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/WasmExecutionTests.cs
# - test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WasmExecutionTests.cs
# Their generated assets set <UsingWasiRuntimeWorkload>true</UsingWasiRuntimeWorkload>; the
# `wasi-experimental-net10` workload is needed by the always-on `dotnet build -r wasi-wasm` assertions
# (otherwise NETSDK1147 in CI), and `wasm-tools-net10` is needed by the gated `dotnet publish -r
# wasi-wasm` step the execution tests perform (otherwise the publish fails and they self-skip).
# Running the execution tests to completion additionally needs `wasmtime` on PATH; when it is absent
# the tests mark themselves inconclusive.
# - test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/BrowserWasmExecutionTests.cs
# - samples/BrowserPlayground
# `wasi-experimental-net10` is needed by the always-on `dotnet build -r wasi-wasm` assertions, whose
# generated asset sets <UsingWasiRuntimeWorkload>true</UsingWasiRuntimeWorkload> (see WasmExecutionTests.cs);
# otherwise NETSDK1147 in CI. `wasm-tools-net10` is needed by the gated `dotnet publish -r wasi-wasm` step the
# wasi execution tests perform AND by the browser-wasm build/publish path (BrowserWasmExecutionTests /
# BrowserPlayground) — for browser-wasm it is required even by `dotnet build`. Installing it here means CI
# actually exercises the browser-wasm build (and, where 'node' is present, the end-to-end run) instead of the
# acceptance test silently going Inconclusive on every leg. Running the wasi execution tests to completion
# additionally needs `wasmtime` on PATH; when it (or `node`, for browser-wasm) is absent the tests mark
# themselves inconclusive.

$RequiredWorkloads = @('wasi-experimental-net10', 'wasm-tools-net10')

Expand Down
19 changes: 12 additions & 7 deletions eng/restore-toolset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
# AFTER InitializeDotNetCli has bootstrapped the repo-local .dotnet/ SDK, so
# $repo_root and the helpers from eng/common/tools.sh are in scope.
#
# Required by the wasi-wasm acceptance tests:
# Required by the wasm acceptance tests (and the browser-wasm sample):
# - test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/WasmExecutionTests.cs
# - test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WasmExecutionTests.cs
# Their generated assets set <UsingWasiRuntimeWorkload>true</UsingWasiRuntimeWorkload>; the
# `wasi-experimental-net10` workload is needed by the always-on `dotnet build -r wasi-wasm` assertions
# (otherwise NETSDK1147 in CI), and `wasm-tools-net10` is needed by the gated `dotnet publish -r
# wasi-wasm` step the execution tests perform (otherwise the publish fails and they self-skip).
# Running the execution tests to completion additionally needs `wasmtime` on PATH; when it is absent
# the tests mark themselves inconclusive.
# - test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/BrowserWasmExecutionTests.cs
# - samples/BrowserPlayground
# `wasi-experimental-net10` is needed by the always-on `dotnet build -r wasi-wasm` assertions, whose
# generated asset sets <UsingWasiRuntimeWorkload>true</UsingWasiRuntimeWorkload> (see WasmExecutionTests.cs);
# otherwise NETSDK1147 in CI. `wasm-tools-net10` is needed by the gated `dotnet publish -r wasi-wasm` step the
# wasi execution tests perform AND by the browser-wasm build/publish path (BrowserWasmExecutionTests /
# BrowserPlayground) — for browser-wasm it is required even by `dotnet build`. Installing it here means CI
# actually exercises the browser-wasm build (and, where 'node' is present, the end-to-end run) instead of the
# acceptance test silently going Inconclusive on every leg. Running the wasi execution tests to completion
# additionally needs `wasmtime` on PATH; when it (or `node`, for browser-wasm) is absent the tests mark
# themselves inconclusive.

required_workloads=('wasi-experimental-net10' 'wasm-tools-net10')
Comment thread
Evangelink marked this conversation as resolved.
Resolved

Expand Down
63 changes: 63 additions & 0 deletions samples/BrowserPlayground/BrowserPlayground.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<!--
Publishing browser-wasm must be self-contained so the mono browser-wasm runtime
pack is resolved; targeting net10.0 under an 11.0 SDK does not infer this on its own.
-->
<SelfContained>true</SelfContained>

<!--
The JS boot module that the WebAssembly runtime loads first. It creates the
.NET runtime via dotnet.js and invokes the sample's Program.Main (defined by the
top-level statements in Program.cs). See wwwroot/main.js.
-->
<WasmMainJSPath>wwwroot\main.js</WasmMainJSPath>

<!-- Use the pre-built dotnet.native.wasm (no emscripten / wasm-sdk relink required). -->
<WasmBuildNative>false</WasmBuildNative>
<PublishTrimmed>false</PublishTrimmed>

<Nullable>enable</Nullable>
<!--
Marks this as a Microsoft.Testing.Platform application. It is intentionally NOT set
when running under 'dotnet test' (CI's Debug Test step on TestFx.slnx passes
-p:UsingDotNetTest=true): the browser-wasm output can only be launched through a JS
host (a browser or node importing dotnet.js), which is not wired into 'dotnet test'.
The entry point is this sample's own Program.cs (top-level statements), not an
MTP-generated one.
-->
<IsTestingPlatformApplication Condition=" '$(UsingDotNetTest)' != 'true' ">true</IsTestingPlatformApplication>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.Telemetry\Microsoft.Testing.Extensions.Telemetry.csproj" />
</ItemGroup>

<ItemGroup>
<!--
Only the diagnostic capability is advertised. TestingPlatformServer / TestContainer are
intentionally omitted: browser-wasm cannot use server mode or the 'dotnet test' pipe (both
need TCP/named-pipe IPC — see the IsTestingPlatformApplication comment above and the README
feature matrix), and advertising them would let Test Explorer pick an unsupported launch path
when the project is opened directly.
-->
<ProjectCapability Include="DiagnoseCapabilities" />
</ItemGroup>

<!--
Ship the node headless runner and the browser page inside the published AppBundle.
The wasm SDK copies the WasmMainJSPath module (wwwroot/main.js) into the AppBundle;
WasmExtraFilesToDeploy places additional files (the node runner and index.html) next
to it so 'node runtests.mjs' / a browser can boot the app from the bundle (see README).
-->
<ItemGroup>
<WasmExtraFilesToDeploy Include="wwwroot\runtests.mjs" />
<WasmExtraFilesToDeploy Include="wwwroot\index.html" />
</ItemGroup>

</Project>
62 changes: 62 additions & 0 deletions samples/BrowserPlayground/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Extensions;
using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.TestFramework;

ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);

testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, _) => new DummyFramework());

testApplicationBuilder.AddAppInsightsTelemetryProvider();

// The following extensions are intentionally NOT registered on browser-wasm:
// - AddTrxReportProvider: with --report-trx enabled, TrxDataConsumer creates a
// TrxResultStreamingStore whose background writer calls ITask.RunLongRunning (and uses
// BlockingCollection<T>), both unsupported on browser; the TRX lifecycle handlers are
// themselves gated by OperatingSystem.IsBrowser() (see TrxReportExtensions). Registering it
// would let a user pass --report-trx and hit PlatformNotSupportedException.
// - AddHangDumpProvider / AddCrashDumpProvider: dumps rely on System.Diagnostics.Process,
// which is unsupported in the browser sandbox (see #8557).
// - AddAzureDevOpsProvider: its HttpClient sets AutomaticDecompression, which the browser
// HttpClientHandler does not support.
// Threading is not an issue for the registered providers: the platform detects the
// single-threaded wasm runtime (RuntimeFeatureHelper.IsMultiThreaded == false) and runs the
// pipeline inline, exactly as it does on wasi-wasm.
using ITestApplication testApplication = await testApplicationBuilder.BuildAsync();
return await testApplication.RunAsync();

internal sealed class DummyFramework : ITestFramework, IDataProducer
{
public string Uid => nameof(DummyFramework);

public string Version => "1.0.0";

public string DisplayName => "DummyFramework";

public string Description => DisplayName;
Comment thread
Evangelink marked this conversation as resolved.
Resolved

public Type[] DataTypesProduced => [typeof(TestNodeUpdateMessage)];

public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context)
=> Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });

public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context)
=> Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });

public async Task ExecuteRequestAsync(ExecuteRequestContext context)
{
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
{
DisplayName = "Test display name",
Uid = "Uid1",
Properties = new PropertyBag(PassedTestNodeStateProperty.CachedInstance),
}));
context.Complete();
}

public Task<bool> IsEnabledAsync() => Task.FromResult(true);
}
153 changes: 153 additions & 0 deletions samples/BrowserPlayground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# BrowserPlayground

Demonstrates hosting [Microsoft.Testing.Platform](https://aka.ms/testingplatform/) on
`browser-wasm` — the WebAssembly runtime that runs inside a browser (and, headlessly,
under [Node.js](https://nodejs.org/) via the same `dotnet.js` loader).

This is the browser counterpart to the `wasi-wasm` acceptance coverage in
[`WasmExecutionTests.cs`](../../test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/WasmExecutionTests.cs)
(and its MSTest sibling under `MSTest.Acceptance.IntegrationTests`). Both `wasi-wasm` and
`browser-wasm` run on a single-threaded WebAssembly runtime; the platform work that makes
that possible is shared (see [#2196](https://github.com/microsoft/testfx/issues/2196)). The
only real difference is the **host**: `wasi-wasm` runs headless under `wasmtime`, whereas
`browser-wasm` boots through a small JavaScript module (`wwwroot/main.js`) that loads
`dotnet.js` and invokes the sample's `Program.Main` (defined by the top-level statements
in `Program.cs`).

## Build & run

> **Not part of `TestFx.slnx`.** `browser-wasm` needs the `wasm-tools` workload even to
> *build*. The repo bootstrap (`.\build.cmd` / `./build.sh`) installs that workload via
> `eng/restore-toolset`, so a bootstrapped build already has it. It is kept out of the
> solution to protect **builds that bypass the bootstrap** — most notably opening
> `TestFx.slnx` in an IDE on a fresh clone, or any environment where the workload has not
> been installed — from failing the whole solution build. So `BrowserPlayground` is built
> on demand with the explicit `dotnet publish` below rather than as part of the solution.

Prerequisites:

- The repo-local .NET SDK (`.dotnet\dotnet.exe` on Windows, `.dotnet/dotnet` on
Linux/macOS). Bootstrap it once by running `.\build.cmd` (Windows) or `./build.sh`
(Linux/macOS) from the repo root. The bootstrap also installs the `wasm-tools-net10`
workload this sample needs (see
[`eng/restore-toolset.ps1`](../../eng/restore-toolset.ps1) /
[`eng/restore-toolset.sh`](../../eng/restore-toolset.sh)). If you use a machine-installed
SDK instead, install the workload manually:

```

Check failure on line 37 in samples/BrowserPlayground/README.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should have a language specified

samples/BrowserPlayground/README.md:37 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md040.md
dotnet workload install wasm-tools-net10
```

- For the headless run: [Node.js](https://nodejs.org/) on `PATH`.
For the browser run: any static web server (see step 2b).

> The commands below use the repo-local SDK so the `.dotnet/packs` lookup resolves — that
> is `.\.dotnet\dotnet.exe` on Windows and `./.dotnet/dotnet` on Linux/macOS (shown as
> `dotnet` below for brevity). Swap in a machine-installed `dotnet` if you prefer. The paths
> below use forward slashes, which work on all platforms; on Windows you can also use `\`.

### 1. Publish

```

Check failure on line 51 in samples/BrowserPlayground/README.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should have a language specified

samples/BrowserPlayground/README.md:51 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md040.md
dotnet publish samples/BrowserPlayground/BrowserPlayground.csproj -c Debug -f net10.0
```

The published app bundle lands under
`artifacts/bin/BrowserPlayground/Debug/net10.0/browser-wasm/AppBundle` and contains
`_framework/dotnet.js`, the managed assemblies, `index.html`, `main.js`, and
`runtests.mjs`.

### 2a. Run headlessly under Node

From the bundle directory:

```

Check failure on line 64 in samples/BrowserPlayground/README.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should have a language specified

samples/BrowserPlayground/README.md:64 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md040.md
cd artifacts/bin/BrowserPlayground/Debug/net10.0/browser-wasm/AppBundle
node runtests.mjs
```

`runtests.mjs` boots the same bundle under Node (no DOM required — Microsoft.Testing.Platform
never touches the DOM), forwards stdout/stderr, and maps the .NET exit code onto the Node
process exit code. This is the mode the `BrowserWasmExecutionTests` acceptance test uses.

### 2b. Run in a browser

Serve the bundle over HTTP (WebAssembly cannot be loaded from `file://`) and open it. Any
static file server works; two options that need no extra provisioning:

```

Check failure on line 78 in samples/BrowserPlayground/README.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should have a language specified

samples/BrowserPlayground/README.md:78 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.36.1/doc/md040.md
cd artifacts/bin/BrowserPlayground/Debug/net10.0/browser-wasm/AppBundle

# Using Node (installed for step 2a):
npx --yes http-server -o

# ...or using Python 3:
python3 -m http.server 8080
```

Then browse to the served URL (`http-server` opens it automatically; for the Python server
open <http://localhost:8080/>). The test run output appears in the browser's developer-tools
**Console**. Pass Microsoft.Testing.Platform options through the page query string, e.g.
`index.html?arg=--minimum-expected-tests&arg=1`.

## Status

Microsoft.Testing.Platform boots on `browser-wasm` (the banner reads
`[browser-wasm - net10.0]`) and tests run to completion, exactly as on `wasi-wasm`.
Running this sample — which hosts a `DummyFramework` with a single passing test —
produces:

```console
Test run summary: Passed!
total: 1
failed: 0
succeeded: 1
skipped: 0
```

MSTest itself (not just the raw platform) also runs end-to-end on `browser-wasm`; that
is covered by the gated `BrowserWasmExecutionTests.BrowserWasmExecution_RunsTestsUnderNode`
acceptance test (see
[`test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/BrowserWasmExecutionTests.cs`](../../test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/BrowserWasmExecutionTests.cs)),
which publishes a real MSTest project and runs it under Node.

### Why it works

The single-threaded WebAssembly constraint is the same as `wasi-wasm`: there is no
thread pool, so `Task.Run` continuations never execute and blocking waits throw
`PlatformNotSupportedException`. The platform and the MSTest adapter detect this
(`RuntimeFeatureHelper.IsMultiThreaded` / `RuntimeContext.IsMultiThreaded`, derived from
`OperatingSystem.IsBrowser()`) and fall back to inline/synchronous execution on the run
path — the message-bus consumers, the shutdown watchdog, the telemetry ingest loop, the
countdown-event wait, and the adapter's per-test task factory.

Console output is routed through `BrowserOutputDevice`, which forwards to the browser's
`globalThis.console.*` APIs via `[JSImport]`.

### Feature matrix (what is *not* available on browser-wasm)

Several extensions/capabilities are intentionally unavailable in the browser sandbox and
are guarded off by `OperatingSystem.IsBrowser()` in the platform:

| Feature | Reason |
| --- | --- |
| TRX report (`--report-trx`) | `TrxDataConsumer` creates a `TrxResultStreamingStore` whose background writer uses `BlockingCollection<T>` and `ITask.RunLongRunning`, both unsupported on browser; the TRX lifecycle handlers are gated by `OperatingSystem.IsBrowser()`. |
| Hang dump / crash dump | Rely on `System.Diagnostics.Process`, unsupported in the browser (see [#8557](https://github.com/microsoft/testfx/issues/8557)). |
| Azure DevOps report | Its `HttpClient` sets `AutomaticDecompression`, unsupported by the browser `HttpClientHandler`. |
| Server mode / `dotnet test` pipe | Depends on TCP/named-pipe IPC, unavailable in the browser. |
| `--exit-on-process-exit`, wait-for-debugger | No host process model in the browser. |
| Synchronous file-logger flush | Not supported in the browser (throws `PlatformNotSupportedException`). |

That is why `Program.cs` registers only the telemetry provider (`AddAppInsightsTelemetryProvider`).

## Build configuration notes

`BrowserPlayground.csproj` ships with a few non-obvious switches:

| Property | Reason |
| --- | --- |
| `SelfContained=true` | Publishing browser-wasm must be self-contained so the `Microsoft.NETCore.App.Runtime.Mono.browser-wasm` runtime pack is resolved. Targeting `net10.0` under an `11.0` SDK does not infer this on its own, so publish fails with an empty `MicrosoftNetCoreAppRuntimePackDir` without it. |
| `WasmBuildNative=false` | Use the pre-built `dotnet.native.wasm`. A native relink needs the emscripten toolchain (pulled in by the `wasm-tools` workload) and is slower; the pre-built runtime is enough to boot MTP. |
| (no `InvariantGlobalization`) | On browser-wasm, `InvariantGlobalization=true` forces `WasmBuildNative=true` (an emscripten relink), so it is intentionally left unset — the browser bundle ships ICU (`icudt*.dat`) by default. This differs from the `wasi-wasm` acceptance asset (`WasmExecutionTests.cs`), which keeps `InvariantGlobalization=true` and stages `icudt.dat` manually via `WasmRuntime.StageIcuData`. |
| `WasmExtraFilesToDeploy` | Copies the node runner (`runtests.mjs`) and `index.html` into the published `AppBundle` next to `main.js` (the `WasmMainJSPath` module). Plain `CopyToOutputDirectory` would only reach the build output folder, not the `AppBundle`. |

18 changes: 18 additions & 0 deletions samples/BrowserPlayground/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BrowserPlayground</title>
</head>

<body>
<p>Running Microsoft.Testing.Platform on browser-wasm. Open the developer-tools console to see the test run output.</p>
<!-- Boots the .NET WebAssembly runtime and Microsoft.Testing.Platform (see wwwroot/main.js). -->
<script type="module" src="./main.js"></script>
</body>

</html>
Loading
Loading