Giter VIP home page Giter VIP logo

Comments (14)

agnivade avatar agnivade commented on May 26, 2024

I am not sure I follow. You write tests as usual, using goroutines/channels and what not, and then just use the tool to execute them in the browser.

from wasmbrowsertest.

unicomp21 avatar unicomp21 commented on May 26, 2024

What if I want to run goroutines inside the browser, as part of the component being tested? Doesn't the go scheduler need to be invoked somehow by the browser event loop?

from wasmbrowsertest.

agnivade avatar agnivade commented on May 26, 2024

The entire Go runtime is compiled into the wasm binary. You can create goroutines as normal and they will be executed as if GOMAXPROCS was 1. I'd suggest to read some more tutorials on Go WASM to understand it a bit more.

from wasmbrowsertest.

unicomp21 avatar unicomp21 commented on May 26, 2024

The primary thread, ie GOMAXPROCS 1, in the browser, where does it run? Is it a web worker thread? Or does it share time on the main browser thread? If there is a link somewhere explaining all this, I'd be grateful. I've been googling around trying to find an explanation.

from wasmbrowsertest.

unicomp21 avatar unicomp21 commented on May 26, 2024

I guess this is it?

https://github.com/tinygo-org/tinygo/blob/157382600535c95bdbf5d6e8c4b9e5ca71749018/targets/wasm_exec.js

from wasmbrowsertest.

unicomp21 avatar unicomp21 commented on May 26, 2024

Maybe I'm asking the wrong questions. Is there a wasmbrowser test, where the go component being tested is using goroutines, already in github somewhere?

from wasmbrowsertest.

Gregory-Ledray avatar Gregory-Ledray commented on May 26, 2024

@unicomp21 what is your overall goal here? If your goal is to build a simple program with Go running in the browser, this is a great resource to help you get started: https://www.aaron-powell.com/posts/2019-02-04-golang-wasm-1-introduction/

If you have already taken that step and want to take the next step - writing an app in the browser - then you'll undoubtedly want to also run tests in your browser. wasmbrowsertest helps you do this by spinning up Chrome / Chromedp and the taking your test binary which is compiled with the WASM target, loading it into the browser, and then executing the tests for you and reporting on the test results for you. I think of wasmbrowsertest as a thin layer over top of Go's built in WASM support whose sole purpose is to make sure your tests work in your target GOOS/GOARCH. From a Go language development perspective, it was super important to be able to regression test the Go language across every GOOS/GOARCH it is targeting. Wasmbrowsertest fulfills that need for the WASM compilation target. From an app development perspective this is also helpful - I usually would run my tests against a windows compilation target but the WASM compilation target has some nuances so it's best to test against it too.

I personally took both of the above steps maybe a year ago? The next step was to test code which interacts across the WASM <-> Javascript divide. To do this, you will ultimately need to write your own javascript which interacts with your Go program. Tinygo has some tutorials on how to do this and you can find some other information in the Golang language's WASM help center. This step will NOT involve wasmbrowsertest because wasmbrowsertest was not created to run your func main - it was created to run your func TestMain. To complete this step I did a lot of manual testing.

If you understand the basics of how the whole chain of technologies work together - Go, WASM, JS - then at least for me I had an "ah ha!" moment and I understood how wasmbrowsertest works.

from wasmbrowsertest.

Gregory-Ledray avatar Gregory-Ledray commented on May 26, 2024

I think the problem right now @unicomp21 is that your questions don't exactly make sense.

wasmbrowsertest is an infrastructure tool. It does not know or care how Golang deals with GOMAXPROCS, goroutines, or any other language feature is mapped into WASM. Its job is to take a WASM binary which was compiled by the Go language, put it into a browser, run the binary, and then convert the outputs from the WASM code into a format which is identical or nearly identical to the outputs from the go test command we all know and love.

from wasmbrowsertest.

Gregory-Ledray avatar Gregory-Ledray commented on May 26, 2024

If your goal is to learn about how Go's WASM compilation target works, I strongly recommend first following that tutorial I linked and then reading all of the files in https://github.com/golang/go/tree/master/misc/wasm

TinyGo has similar files which you have already linked which have similar educational value (although I personally am completely unaware of how TinyGo works).

from wasmbrowsertest.

unicomp21 avatar unicomp21 commented on May 26, 2024

It does not know or care how Golang deals with GOMAXPROCS

That's the problem, I do care. My struggle is understanding how the executor/scheduler is working in both the test runner and in the actual web browser app.

from wasmbrowsertest.

agnivade avatar agnivade commented on May 26, 2024

@unicomp21

The primary thread, ie GOMAXPROCS 1, in the browser, where does it run? Is it a web worker thread?

I feel like you are asking how does WebAssembly work. There are tons of material out there which should help you get started.

Here are some talks that you can watch: https://github.com/golang/go/wiki/webassembly#go-webassembly-talks
Here's an introductory blog post I wrote: https://blog.gopheracademy.com/advent-2018/go-in-the-browser/.

If you have further questions, please feel free to drop in to the #webassembly channel in Gophers slack.

I'll close the issue as I think it's out of scope for this tool. But if you have any questions on the tool, please feel free to create a new issue.

from wasmbrowsertest.

unicomp21 avatar unicomp21 commented on May 26, 2024

from wasmbrowsertest.

Gregory-Ledray avatar Gregory-Ledray commented on May 26, 2024

lol

The slack channel is perfect for the questions you are asking.

from wasmbrowsertest.

agnivade avatar agnivade commented on May 26, 2024

Perhaps this would have been better in discussions ;)

Not really, what you are asking about isn't about wasmbrowsertest. :) The slack channel would be great for this.

from wasmbrowsertest.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.