docs/workflow/testing/libraries/testing-wasm.md
In order to be able to run tests, the following JavaScript engines should be installed:
They can be installed as a part of jsvu.
Please make sure that a JavaScript engine binary is available via command line, e.g. for V8:
$ v8
V8 version 8.5.62
If you use jsvu, first add its location to PATH variable
e.g. for V8
PATH=/Users/<your_user>/.jsvu/:$PATH V8
It's possible to run tests in a browser instance:
/Users/<your_user>/.chromedriverPATH=/Users/<your_user>/.chromedriver:$PATH
/Users/<your_user>/.geckodriverPATH=/Users/<your_user>/.geckodriver:$PATH
Now we're ready to build everything for WebAssembly (for more details, please read this document):
./build.sh -os browser -c Release
and even run tests one by one for each library:
./build.sh libs.tests -test -os browser -c Release
The following shows how to run tests for a specific library
./dotnet.sh build /t:Test src/libraries/System.AppContext/tests /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Release
To run all tests, including "outer loop" tests (which are typically slower and in some test suites less reliable, but which are more comprehensive):
./dotnet.sh build /t:Test src/libraries/System.AppContext/tests /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Release /p:Outerloop=true
It's possible to set a JavaScript engine explicitly by adding /p:JSEngine property:
./dotnet.sh build /t:Test src/libraries/System.AppContext/tests /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Release /p:JSEngine=SpiderMonkey
At the moment supported values are:
V8JavaScriptCoreSpiderMonkeyBy default, V8 engine is used.
The following shows how to run tests for a specific library
XHARNESS_COMMAND=test-browser ./dotnet.sh build /t:Test src/libraries/System.AppContext/tests /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Release
run-browser-tests-<test>
make -C src/mono/wasm/ run-browser-tests-System.AppContext
$(WasmXHarnessArgsCli) - xharness command arguments
Example: WasmXHarnessArgsCli="--set-web-server-http-env=DOTNET_TEST_WEBSOCKETHOST" -> becomes dotnet xharness wasm test --set-web-server-http-env=DOTNET_TEST_WEBSOCKETHOST
$(WasmXHarnessMonoArgs) - arguments and variables for mono
Example: WasmXHarnessMonoArgs="--runtime-arg=--trace=E --setenv=MONO_LOG_LEVEL=debug"
$(WasmTestAppArgs) - arguments for the test app itself
To run all tests, including "outer loop" tests (which are typically slower and in some test suites less reliable, but which are more comprehensive):
CLI
XHARNESS_COMMAND=test-browser ./dotnet.sh build /t:Test src/libraries/System.AppContext/tests /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Release /p:Outerloop=true
Makefile target run-browser-tests-<test>
MSBUILD_ARGS=/p:OuterLoop=true make -C src/mono/wasm/ run-browser-tests-System.AppContext
It's possible to set a Browser explicitly by adding --browser= command line argument to XHARNESS_COMMAND:
CLI
XHARNESS_COMMAND="test-browser --browser=safari" ./dotnet.sh build /t:Test src/libraries/System.AppContext/tests /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Release
Makefile target run-browser-tests-<test>
XHARNESS_BROWSER=firefox make -C src/mono/wasm/ run-browser-tests-System.AppContext
At the moment supported values are:
chromesafarifirefoxBy default, chrome browser is used.
Building library tests with AOT, and (even) with EnableAggressiveTrimming takes 3-9mins on CI, and that adds up for all the assemblies, causing
a large build time. To circumvent that on CI, we build the test assemblies on the build machine, but skip the WasmApp build part of it, since
that includes the expensive AOT step.
Instead, we take the built test assembly+dependencies, and enough related bits to be able to run the WasmBuildApp target, with the original
inputs.
To recreate a similar build+test run locally, add /p:BuildAOTTestsOnHelix=true to the usual command line.
For example, with ./dotnet.sh build /t:Test src/libraries/System.AppContext/tests /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Release
/p:EnableAggressiveTrimming=true /p:RunAOTCompilation=true /p:BuildAOTTestsOnHelix=true/p:EnableAggressiveTrimming=true /p:BuildAOTTestsOnHelix=true/p:DebuggerSupport=true to the command line, for Release builds. It's enabled by default for Debug builds.Add the following to the comment of a PR.
/azp run runtime-libraries-mono outerloop
TBD
TBD
TBD