[wasm][libs] Fix `WasmAppHost`, and `AppBundle` for library tests (#77719)
authorIlona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>
Tue, 31 Jan 2023 13:53:15 +0000 (14:53 +0100)
committerGitHub <noreply@github.com>
Tue, 31 Jan 2023 13:53:15 +0000 (14:53 +0100)
* Removed fixed path separator + duplicated `browser-wasm`.

* Working fix.

* Fix for different `OutputPath` conventions.

* Fixing the url printed on the console.

* `ProcessQueryArguments` in test-main.js forces debug to be the 1st arg.

* Removing special case for WBT.

* We cannot skip checking for missing browser-wasm.

* Both runArgs and queryArgs are important when running tests.

* Revert changes in the shipped targets and move them to tests targets.

* Update src/mono/wasm/host/BrowserArguments.cs

Co-authored-by: Ankit Jain <radical@gmail.com>
* Fetch does not work for node<18 => get rid of json.

* Separated runtime args from app args for both hosts.

* Revert 7.0 file.

* Focusing on enabling libs debugging for browser.

* Should have been reverted with dae5d7460c3a23b108e1d141e72c3b0bcdc9d730.

* Fix CI lib tests: avoid referencing undefined properties.

* In all the cases runArgs should be first populated by defaults that can be later overwritten.

* Update src/mono/wasm/test-main.js

Co-authored-by: Ankit Jain <radical@gmail.com>
---------

Co-authored-by: Ankit Jain <radical@gmail.com>
eng/testing/tests.wasm.targets
src/mono/wasm/test-main.js

index 486be5f..149d211 100644 (file)
@@ -36,6 +36,7 @@
                                         ('$(ContinuousIntegrationBuild)' != 'true' or Exists('/.dockerenv')) and
                                         '$(Scenario)' == 'WasmTestOnBrowser'">true</InstallChromeForTests>
     <_XHarnessTestsTimeout>00:30:00</_XHarnessTestsTimeout>
+    <RunWorkingDirectory>$(BundleDir)</RunWorkingDirectory>
   </PropertyGroup>
 
   <!-- On CI this is installed as part of pretest, but it should still be installed
     <BundleTestWasmAppDependsOn Condition="'$(IsBrowserWasmProject)' == 'true' and '$(BuildAOTTestsOn)' == 'local'">WasmTriggerPublishApp</BundleTestWasmAppDependsOn>
     <BundleTestWasmAppDependsOn Condition="'$(IsBrowserWasmProject)' == 'true' and '$(BuildAOTTestsOnHelix)' == 'true'">$(BundleTestWasmAppDependsOn);_BundleAOTTestWasmAppForHelix</BundleTestWasmAppDependsOn>
 
-    <RunCommand>$(WasmAppHostDir)/WasmAppHost</RunCommand>
     <!-- Use BundleDir here, since WasmAppDir is set in a target, and `dotnet run` reads
          $(Run*) without running any targets -->
-    <RunArguments>--runtime-config $(BundleDir)/WasmTestRunner.runtimeconfig.json $(WasmHostArguments) $(StartArguments) $(WasmXHarnessMonoArgs) $(_AppArgs)</RunArguments>
+    <_RuntimeConfigJsonPath>$([MSBuild]::NormalizePath($(BundleDir), 'WasmTestRunner.runtimeconfig.json'))</_RuntimeConfigJsonPath>
+    <RunArguments>exec &quot;$([MSBuild]::NormalizePath($(WasmAppHostDir), 'WasmAppHost.dll'))&quot; --runtime-config &quot;$(_RuntimeConfigJsonPath)&quot; $(WasmHostArguments) $(StartArguments) $(WasmXHarnessMonoArgs) $(_AppArgs)</RunArguments>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(BuildAOTTestsOnHelix)' == 'true'">
index 8f37acc..979c8a2 100644 (file)
@@ -10,7 +10,7 @@
 /*****************************************************************************
  * Please don't use this as template for startup code.
  * There are simpler and better samples like src\mono\sample\wasm\browser\main.js
- * This one is not ES6 nor CJS, doesn't use top level await and has edge case polyfills. 
+ * This one is not ES6 nor CJS, doesn't use top level await and has edge case polyfills.
  * It handles strange things which happen with XHarness.
  ****************************************************************************/
 
@@ -63,19 +63,21 @@ async function getArgs() {
         queryArguments = Array.from(WScript.Arguments);
     }
 
-    let runArgs;
-    if (queryArguments.length > 0) {
-        runArgs = processArguments(queryArguments);
-    } else {
-        const response = fetch('/runArgs.json')
-        if (!response.ok) {
-            console.debug(`could not load /args.json: ${response.status}. Ignoring`);
+    let runArgsJson;
+    // ToDo: runArgs should be read for all kinds of hosts, but
+    // fetch is added to node>=18 and current Windows's emcc node<18
+    if (is_browser)
+    {
+        const response = await globalThis.fetch('./runArgs.json');
+        if (response.ok) {
+            runArgsJson = initRunArgs(await response.json());
+        } else {
+            console.debug(`could not load /runArgs.json: ${response.status}. Ignoring`);
         }
-        runArgs = await response.json();
     }
-    runArgs = initRunArgs(runArgs);
-
-    return runArgs;
+    if (!runArgsJson)
+        runArgsJson = initRunArgs({});
+    return processArguments(queryArguments, runArgsJson);
 }
 
 function initRunArgs(runArgs) {
@@ -95,9 +97,7 @@ function initRunArgs(runArgs) {
     return runArgs;
 }
 
-function processArguments(incomingArguments) {
-    const runArgs = initRunArgs({});
-
+function processArguments(incomingArguments, runArgs) {
     console.log("Incoming arguments: " + incomingArguments.join(' '));
     while (incomingArguments && incomingArguments.length > 0) {
         const currentArg = incomingArguments[0];
@@ -343,4 +343,4 @@ async function run() {
     }
 }
 
-run();
\ No newline at end of file
+run();