1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00
This commit is contained in:
Zxilly 2024-09-06 13:07:27 +08:00
parent fb4bdb64e0
commit 140640b414
No known key found for this signature in database
GPG Key ID: 47AB1DEC841BC6A2
2 changed files with 12 additions and 3 deletions

View File

@ -21,6 +21,16 @@ globalThis.crypto ??= require("crypto");
require("./wasm_exec"); require("./wasm_exec");
// Disable fetch API in tests so that
// RoundTrip ends up talking over the same fake
// network the HTTP servers currently use in
// various tests and examples.
// See net/http/roundtrip_js.go.
// See go.dev/issue/57613.
if (process.argv[2].endsWith(".test")) {
globalThis["JSFetchDisabledInTest"] = true;
}
const go = new Go(); const go = new Go();
go.argv = process.argv.slice(2); go.argv = process.argv.slice(2);
go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env); go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env);

View File

@ -13,7 +13,6 @@ import (
"net/http/internal/ascii" "net/http/internal/ascii"
"strconv" "strconv"
"syscall/js" "syscall/js"
"testing"
) )
var uint8Array = js.Global().Get("Uint8Array") var uint8Array = js.Global().Get("Uint8Array")
@ -47,13 +46,13 @@ const jsFetchRedirect = "js.fetch:redirect"
var jsFetchMissing = js.Global().Get("fetch").IsUndefined() var jsFetchMissing = js.Global().Get("fetch").IsUndefined()
// jsFetchDisabled controls whether the use of Fetch API is disabled. // jsFetchDisabled controls whether the use of Fetch API is disabled.
// It's set to true when we detect we're running in Node.js, so that // It's set to true when we detect we're running in test, so that
// RoundTrip ends up talking over the same fake network the HTTP servers // RoundTrip ends up talking over the same fake network the HTTP servers
// currently use in various tests and examples. See go.dev/issue/57613. // currently use in various tests and examples. See go.dev/issue/57613.
// //
// TODO(go.dev/issue/60810): See if it's viable to test the Fetch API // TODO(go.dev/issue/60810): See if it's viable to test the Fetch API
// code path. // code path.
var jsFetchDisabled = testing.Testing() var jsFetchDisabled = !js.Global().Get("JSFetchDisabledInTest").IsUndefined()
// RoundTrip implements the [RoundTripper] interface using the WHATWG Fetch API. // RoundTrip implements the [RoundTripper] interface using the WHATWG Fetch API.
func (t *Transport) RoundTrip(req *Request) (*Response, error) { func (t *Transport) RoundTrip(req *Request) (*Response, error) {