net/http: improve useFakeNetwork check to allow browsers to run tests in wasm #32289
Comments
What do you propose? |
Actually, I can't recall why the 2nd version was changed. The only difference between 2nd and 3rd is that from catching all node-spawned processes, now it catches all tests under js,wasm flag. Perhaps - len(os.Args) > 0 && path.Base(os.Args[0]) == "node" && strings.HasSuffix(os.Args[0], ".test") sounds better ? Since it filters both node processes and tests, allowing browser tests to run. |
The reason it was introduced was to allow the gerrit tests to pass, so if such a change would still allow the gerrit tests to pass while allowing tests to be run in the browser then I think that sounds good. |
I meant what exactly changed in the logic from v2 to v3 to allow trybots to pass. AFAIU, v3 generalizes the logic to follow a non-wasm path for all tests. But v2 already allowed node. So how did it fail ? (assuming wasm trybots failed) Anyways, I am afk at the moment, but I will check if my suggestion passes both node and browser tests. |
Change https://golang.org/cl/179118 mentions this issue: |
What version of Go are you using (
go version
)?net/http/rountrip_js.go has this code:
This code has gone through several iterations. First it was:
Then, it was changed to:
And finally,
The latest version will always return true if any code is invoked with
go test
. That prevents wasm codepath from being taken if the test is being run using a binary (by replacing the-exec
flag) which spins up a browser, and loads the wasm file in it and captures the logs. Essentially a test environment for wasm code inside the browser.I stumbled onto this while writing a tool like that. The current workaround from my end is to rename the binary to .wasm if it ends with .test. But ideally, this should be fixed in the code.
@johanbrandhorst @neelance @bradfitz
The text was updated successfully, but these errors were encountered: