Mcqdb.NScript.SunlightTestAdapter
1.1.13
dotnet add package Mcqdb.NScript.SunlightTestAdapter --version 1.1.13
NuGet\Install-Package Mcqdb.NScript.SunlightTestAdapter -Version 1.1.13
<PackageReference Include="Mcqdb.NScript.SunlightTestAdapter" Version="1.1.13"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Mcqdb.NScript.SunlightTestAdapter" Version="1.1.13" />
<PackageReference Include="Mcqdb.NScript.SunlightTestAdapter"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Mcqdb.NScript.SunlightTestAdapter --version 1.1.13
#r "nuget: Mcqdb.NScript.SunlightTestAdapter, 1.1.13"
#:package Mcqdb.NScript.SunlightTestAdapter@1.1.13
#addin nuget:?package=Mcqdb.NScript.SunlightTestAdapter&version=1.1.13
#tool nuget:?package=Mcqdb.NScript.SunlightTestAdapter&version=1.1.13
Mcqdb.NScript.SunlightTestAdapter
A VSTest adapter for NScript / SunlightUnit. Lets dotnet test discover and
run NScript-compiled QUnit browser tests — no separate Node runner, no manual
QUnit page wiring.
What it does
- Discovery — Reads
[TestFixture]/[Test]attribute metadata from a NScript-compiled test DLL usingMetadataLoadContext, so the NScriptmscorlibfacade does not need to resolve at runtime. - Execution — Launches headless Chromium via
Microsoft.Playwright, serves the NScript-emitted JavaScript bundle from a synthetic URL, loads QUnit 2.x, and readstestEnd/runEndevents back to VSTest.
Install
In a vanilla .NET 8 wrapper project alongside your NScript test project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<RunSettingsFilePath>$(MSBuildThisFileDirectory)sunlight.runsettings</RunSettingsFilePath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Mcqdb.NScript.SunlightTestAdapter" Version="1.1.0" />
</ItemGroup>
</Project>
The NScript-compiled test DLL itself targets netstandard2.1 with a custom
mscorlib facade and cannot reference Microsoft.NET.Test.Sdk directly —
hence the thin wrapper above. The wrapper should copy your NScript-compiled
test DLL (and its SunlightUnit / framework siblings) into its own bin/ so
the adapter can resolve attribute metadata.
Configure
Point the adapter at your test assembly and the NScript-emitted JS bundle via
a .runsettings file:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<TargetFrameworkVersion>net8.0</TargetFrameworkVersion>
</RunConfiguration>
<NSTest>
<TestSourceAssembly>YourSuite.Test.dll</TestSourceAssembly>
<JsFilePath>../../../../path/to/GeneratedScripts/YourSuite.Test.js</JsFilePath>
<LogEndpoint>./logs/browser-tests.jsonl</LogEndpoint>
</NSTest>
</RunSettings>
| Setting | Required | Purpose |
|---|---|---|
TestSourceAssembly |
yes | Filename of the NScript-compiled test DLL, resolved relative to the wrapper's bin/. |
JsFilePath |
yes | Path to the NScript-emitted JS bundle (relative to the test DLL dir, then CWD). |
LogEndpoint |
no | When set, the adapter writes structured client + adapter logs to this JSONL file. When unset, behavior is byte-identical to today. |
Structured log capture
By default the adapter serves the test bundle via Playwright route
interception and forwards browser console output to VSTest's logger as
[browser:log] <text> — handy for live triage, but not persisted in a
machine-readable shape.
Set <LogEndpoint> to capture structured logs instead. When it is present,
the executor boots a single in-process Kestrel host on a loopback port that
serves the test-bundle static assets and hosts the
Sunlight.Logging.Server ingestion endpoints (/_log, /_log/ws) at the
same origin. Browser-side Sunlight.Framework.Logger events
(Sunlight.Browser.*) and adapter lifecycle events (SunlightTestAdapter.*)
both flow through one Serilog CompactJsonFormatter file sink, so they land
in the configured file — one JSON object per line — ready for jq, DuckDB,
or a log shipper.
The browser bundle opts in by clearing the default sink and wiring the factory at startup:
Logger.ClearSinks();
Logger.AddSink(LogSinkFactory.CreateFromBootstrap(new WindowTimer()));
CreateFromBootstrap reads the window.__nscriptLogEndpoint /
window.__nscriptLogWsEndpoint globals the host page injects and returns the
matching sink (WebSocket-primary with HTTP failover when both are present).
When LogEndpoint is unset, none of this is wired and the legacy
[browser:log] forwarding stays in effect.
See docs/framework-logging.md for the
full event schema, sink reference, and server-side ingestion API.
Run
dotnet test path/to/YourSuite.Test.Runner.csproj -c Debug
The first build of any consumer project invokes playwright install chromium
once via this package's .targets; subsequent builds short-circuit on a
sentinel file in bin/. Opt out by setting NSTestSkipPlaywrightInstall=true
in CI environments that provision Chromium externally.
Caveats
- One bundle per wrapper. Each NScript suite must run in its own wrapper
project / runsettings combo. Two NScript bundles co-loaded in the same page
collide on shared
Function.prototyperuntime slots after minification. - SunlightUnit is not transitive. You write
[TestFixture]/[Test]attributes in your own test project — installMcqdb.NScript.SunlightUnitthere directly.
Source
Sources/Compiler/SunlightTestAdapter/ in the NScript repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Mcqdb.NScript.Sunlight.Logging.Server (>= 1.1.13)
- Microsoft.Playwright (>= 1.49.0)
- System.Reflection.MetadataLoadContext (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.