Skip to content

Commit 3361b2f

Browse files
marafpavelsavara
andauthored
[wasm] WebSocket tests on NodeJS (#63441)
- NPM package with WS. - Restore npm during build. - Load npm modules in test-main.js. Co-authored-by: Pavel Savara <pavel.savara@gmail.com>
1 parent 4e48641 commit 3361b2f

14 files changed

Lines changed: 115 additions & 14 deletions

File tree

eng/testing/WasmRunnerTemplate.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if /I [%XHARNESS_COMMAND%] == [test] (
5454
)
5555

5656
if [%XHARNESS_ARGS%] == [] (
57-
set "XHARNESS_ARGS=%JS_ENGINE% %JS_ENGINE_ARGS% %BROWSER_PATH% %MAIN_JS%"
57+
set "XHARNESS_ARGS=%JS_ENGINE% %JS_ENGINE_ARGS% %BROWSER_PATH% %MAIN_JS% %WASM_XHARNESS_MONO_ARGS%"
5858
)
5959

6060
echo EXECUTION_DIR=%EXECUTION_DIR%

eng/testing/WasmRunnerTemplate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then
5050
fi
5151

5252
if [[ -z "$XHARNESS_ARGS" ]]; then
53-
XHARNESS_ARGS="$JS_ENGINE $JS_ENGINE_ARGS $MAIN_JS"
53+
XHARNESS_ARGS="$JS_ENGINE $JS_ENGINE_ARGS $MAIN_JS $WASM_XHARNESS_MONO_ARGS"
5454
fi
5555

5656
echo EXECUTION_DIR=$EXECUTION_DIR

eng/testing/tests.wasm.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
See also eng\testing\WasmRunnerTemplate.sh
3030
-->
3131
<ItemGroup Condition="'$(OS)' != 'Windows_NT'">
32-
<SetScriptCommands Condition="'$(Scenario)' != ''" Include="export SCENARIO=$(Scenario)" />
32+
<SetScriptCommands Condition="'$(Scenario)' != '' and '$(ContinuousIntegrationBuild)' != 'true'" Include="export SCENARIO=$(Scenario)" />
3333
<SetScriptCommands Condition="'$(JSEngine)' != ''" Include="export JS_ENGINE=--engine=$(JSEngine)" />
3434
<SetScriptCommands Condition="'$(JSEngineArgs)' != ''" Include="export JS_ENGINE_ARGS=$(JSEngineArgs)" />
3535
<SetScriptCommands Condition="'$(_WasmMainJSFileName)' != ''" Include="export MAIN_JS=--js-file=$(_WasmMainJSFileName)" />
3636
</ItemGroup>
3737
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
38-
<SetScriptCommands Condition="'$(Scenario)' != ''" Include="set &quot;SCENARIO=$(Scenario)&quot;" />
38+
<SetScriptCommands Condition="'$(Scenario)' != '' and '$(ContinuousIntegrationBuild)' != 'true'" Include="set &quot;SCENARIO=$(Scenario)&quot;" />
3939
<SetScriptCommands Condition="'$(JSEngine)' != ''" Include="set &quot;JS_ENGINE=--engine^=$(JSEngine)&quot;" />
4040
<SetScriptCommands Condition="'$(JSEngineArgs)' != ''" Include="set &quot;JS_ENGINE_ARGS=$(JSEngineArgs)&quot;" />
4141
<SetScriptCommands Condition="'$(_WasmMainJSFileName)' != ''" Include="set &quot;MAIN_JS=--js-file^=$(_WasmMainJSFileName)&quot;" />

src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<Project>
22
<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
3-
<Scenario>WasmTestOnBrowser</Scenario>
4-
<TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot>
5-
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
6-
73
<!-- handle different path to middleware in Helix -->
84
<_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' == 'Windows_NT'">%HELIX_CORRELATION_PAYLOAD%/xharness/TestEchoMiddleware</_TestEchoMiddleware>
95
<_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' != 'Windows_NT'">$HELIX_CORRELATION_PAYLOAD/xharness/TestEchoMiddleware</_TestEchoMiddleware>

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ public static partial class PlatformDetection
6969
public static bool IsSpeedOptimized => !IsSizeOptimized;
7070
public static bool IsSizeOptimized => IsBrowser || IsAndroid || IsAppleMobile;
7171

72-
public static bool IsBrowserDomSupported => GetIsBrowserDomSupported();
73-
public static bool IsBrowserDomSupportedOrNotBrowser => IsNotBrowser || GetIsBrowserDomSupported();
72+
public static bool IsBrowserDomSupported => IsEnvironmentVariableTrue("IsBrowserDomSupported");
73+
public static bool IsBrowserDomSupportedOrNotBrowser => IsNotBrowser || IsBrowserDomSupported;
7474
public static bool IsNotBrowserDomSupported => !IsBrowserDomSupported;
75+
public static bool IsWebSocketSupported => IsEnvironmentVariableTrue("IsWebSocketSupported");
7576
public static bool LocalEchoServerIsNotAvailable => !LocalEchoServerIsAvailable;
7677
public static bool LocalEchoServerIsAvailable => IsBrowser;
7778

@@ -499,12 +500,12 @@ private static bool GetIsRunningOnMonoInterpreter()
499500
#endif
500501
}
501502

502-
private static bool GetIsBrowserDomSupported()
503+
private static bool IsEnvironmentVariableTrue(string variableName)
503504
{
504505
if (!IsBrowser)
505506
return false;
506507

507-
var val = Environment.GetEnvironmentVariable("IsBrowserDomSupported");
508+
var val = Environment.GetEnvironmentVariable(variableName);
508509
return (val != null && val == "true");
509510
}
510511
}

src/libraries/System.Net.WebSockets.Client/tests/AbortTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public AbortTest(ITestOutputHelper output) : base(output) { }
1717

1818
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
1919
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
20+
[ActiveIssue("https://github.com/dotnet/runtime/issues/63673", TestPlatforms.Browser)]
2021
public async Task Abort_ConnectAndAbort_ThrowsWebSocketExceptionWithmessage(Uri server)
2122
{
2223
using (var cws = new ClientWebSocket())

src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public async Task ConnectAsync_CookieHeaders_Success(Uri server)
170170

171171
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
172172
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
173+
[ActiveIssue("https://github.com/dotnet/runtime/issues/63681", TestPlatforms.Browser)]
173174
public async Task ConnectAsync_PassNoSubProtocol_ServerRequires_ThrowsWebSocketException(Uri server)
174175
{
175176
const string AcceptedProtocol = "CustomProtocol";
@@ -256,6 +257,7 @@ public async Task ConnectAndCloseAsync_UseProxyServer_ExpectedClosedState(Uri se
256257
}
257258

258259
[ConditionalFact(nameof(WebSocketsSupported))]
260+
[ActiveIssue("https://github.com/dotnet/runtime/issues/63672", TestPlatforms.Browser)]
259261
public async Task ConnectAsync_CancellationRequestedBeforeConnect_ThrowsOperationCanceledException()
260262
{
261263
using (var clientSocket = new ClientWebSocket())
@@ -268,6 +270,7 @@ public async Task ConnectAsync_CancellationRequestedBeforeConnect_ThrowsOperatio
268270
}
269271

270272
[ConditionalFact(nameof(WebSocketsSupported))]
273+
[ActiveIssue("https://github.com/dotnet/runtime/issues/63672", TestPlatforms.Browser)]
271274
public async Task ConnectAsync_CancellationRequestedInflightConnect_ThrowsOperationCanceledException()
272275
{
273276
using (var clientSocket = new ClientWebSocket())
@@ -281,6 +284,7 @@ public async Task ConnectAsync_CancellationRequestedInflightConnect_ThrowsOperat
281284

282285
[ConditionalFact(nameof(WebSocketsSupported))]
283286
[ActiveIssue("https://github.com/dotnet/runtime/issues/34690", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
287+
[ActiveIssue("https://github.com/dotnet/runtime/issues/63671", TestPlatforms.Browser)]
284288
public async Task ConnectAsync_CancellationRequestedAfterConnect_ThrowsOperationCanceledException()
285289
{
286290
var releaseServer = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,35 @@
66
</PropertyGroup>
77

88
<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
9+
<!-- This doesn't run on V8 because it lacks websocket support -->
910
<Scenario>WasmTestOnBrowser</Scenario>
10-
<TestArchiveTestsRoot>$(TestArchiveRoot)browseronly/</TestArchiveTestsRoot>
11+
<TestArchiveTestsRoot>$(TestArchiveRoot)browserornodejs/</TestArchiveTestsRoot>
1112
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
1213
<DefineConstants>$(DefineConstants);TARGET_BROWSER</DefineConstants>
1314
</PropertyGroup>
1415

1516
<Import Condition="'$(TargetOS)' == 'Browser'" Project="$(CommonTestPath)System/Net/Prerequisites/LocalEchoServer.props" />
1617

18+
<ItemGroup>
19+
<WasmExtraFilesToDeploy Include="package.json" />
20+
<WasmExtraFilesToDeploy Include="package-lock.json" />
21+
</ItemGroup>
22+
23+
<ItemGroup Condition="'$(OS)' != 'Windows_NT'">
24+
<!-- WebSocket tests use self-signed certificates for wss protocol that are refused by NodeJS -->
25+
<SetScriptCommands Include="if [[ &quot;$SCENARIO&quot; == &quot;WasmTestOnNodeJs&quot; || &quot;$SCENARIO&quot; == &quot;wasmtestonnodejs&quot; ]]; then export NODE_TLS_REJECT_UNAUTHORIZED=0; fi" />
26+
<SetScriptCommands Include="if [[ &quot;$SCENARIO&quot; == &quot;WasmTestOnNodeJs&quot; || &quot;$SCENARIO&quot; == &quot;wasmtestonnodejs&quot; ]]; then export WASM_XHARNESS_MONO_ARGS=--setenv=NPM_MODULES=ws:WebSocket; fi" />
27+
<!-- Restore NPM packages -->
28+
<RunScriptCommands Include="if [[ &quot;$SCENARIO&quot; == &quot;WasmTestOnNodeJs&quot; || &quot;$SCENARIO&quot; == &quot;wasmtestonnodejs&quot; ]]; then npm ci; fi" />
29+
</ItemGroup>
30+
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
31+
<!-- WebSocket tests use self-signed certificates for wss protocol that are refused by NodeJS -->
32+
<SetScriptCommands Include="if /I [%SCENARIO%]==[WasmTestOnNodeJS] ( set &quot;NODE_TLS_REJECT_UNAUTHORIZED=0&quot; )" />
33+
<SetScriptCommands Include="if /I [%SCENARIO%]==[WasmTestOnNodeJS] ( set &quot;WASM_XHARNESS_MONO_ARGS=--setenv=NPM_MODULES=ws:WebSocket&quot; )" />
34+
<!-- Restore NPM packages -->
35+
<RunScriptCommands Include="if /I [%SCENARIO%]==[WasmTestOnNodeJS] ( call npm ci )" />
36+
</ItemGroup>
37+
1738
<!-- Browser specific files -->
1839
<ItemGroup Condition="'$(TargetOS)' == 'Browser'">
1940
<ProjectReference Include="$(CommonTestPath)System/Net/Prerequisites/NetCoreServer/NetCoreServer.csproj" ReferenceOutputAssembly="false"/>

src/libraries/System.Net.WebSockets.Client/tests/WebSocketHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static async Task<T> Retry<T>(ITestOutputHelper output, Func<Task<T>> fun
125125
private static bool InitWebSocketSupported()
126126
{
127127
ClientWebSocket cws = null;
128-
if (PlatformDetection.IsBrowser && !PlatformDetection.IsBrowserDomSupported)
128+
if (PlatformDetection.IsBrowser && !PlatformDetection.IsWebSocketSupported)
129129
{
130130
return false;
131131
}

src/libraries/System.Net.WebSockets.Client/tests/package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)