fix NodeJS fetch detection (#89393)
authorPavel Savara <pavel.savara@gmail.com>
Tue, 25 Jul 2023 10:52:49 +0000 (12:52 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Jul 2023 10:52:49 +0000 (12:52 +0200)
src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs
src/mono/wasm/runtime/loader/polyfills.ts

index bb9441a..746feb4 100644 (file)
@@ -584,7 +584,7 @@ namespace System.Net.Http.Functional.Tests
         {
         }
 
-        [Fact]
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNodeJS))]
         public async Task RequestDuration_EnrichmentHandler_ContentLengthError_Recorded()
         {
             await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
index d77ceab..f9aae41 100644 (file)
@@ -81,9 +81,10 @@ export async function detect_features_and_polyfill(module: DotnetModuleInternal)
     }
 }
 
-const hasFetch = typeof (globalThis.fetch) === "function";
 export async function fetch_like(url: string, init?: RequestInit): Promise<Response> {
     try {
+        // this need to be detected only after we import node modules in onConfigLoaded
+        const hasFetch = typeof (globalThis.fetch) === "function";
         if (ENVIRONMENT_IS_NODE) {
             const isFileUrl = url.startsWith("file://");
             if (!isFileUrl && hasFetch) {