MCPcopy
hub / github.com/tinygo-org/tinygo / TestWasmExportJS

Function TestWasmExportJS

main_test.go:801–841  ·  view source on GitHub ↗

Test //go:wasmexport in JavaScript (using NodeJS).

(t *testing.T)

Source from the content-addressed store, hash-verified

799
800// Test //go:wasmexport in JavaScript (using NodeJS).
801func TestWasmExportJS(t *testing.T) {
802 t.Parallel()
803 type testCase struct {
804 name string
805 buildMode string
806 }
807
808 tests := []testCase{
809 {name: "default"},
810 {name: "c-shared", buildMode: "c-shared"},
811 }
812 for _, tc := range tests {
813 tc := tc
814 t.Run(tc.name, func(t *testing.T) {
815 t.Parallel()
816 // Build the wasm binary.
817 tmpdir := t.TempDir()
818 options := optionsFromTarget("wasm", sema)
819 options.BuildMode = tc.buildMode
820 buildConfig, err := builder.NewConfig(&options)
821 if err != nil {
822 t.Fatal(err)
823 }
824 result, err := builder.Build("testdata/wasmexport-noscheduler.go", ".wasm", tmpdir, buildConfig)
825 if err != nil {
826 t.Fatal("failed to build binary:", err)
827 }
828
829 // Test the resulting binary using NodeJS.
830 output := &bytes.Buffer{}
831 cmd := exec.Command("node", "testdata/wasmexport.js", result.Binary, buildConfig.BuildMode())
832 cmd.Stdout = output
833 cmd.Stderr = output
834 err = cmd.Run()
835 if err != nil {
836 t.Error("failed to run node:", err)
837 }
838 checkOutput(t, "testdata/wasmexport.txt", output.Bytes())
839 })
840 }
841}
842
843// Test whether Go.run() (in wasm_exec.js) normally returns and returns the
844// right exit code.

Callers

nothing calls this directly

Calls 11

BuildModeMethod · 0.95
NewConfigFunction · 0.92
BuildFunction · 0.92
optionsFromTargetFunction · 0.85
checkOutputFunction · 0.85
ParallelMethod · 0.80
TempDirMethod · 0.65
FatalMethod · 0.65
ErrorMethod · 0.65
RunMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected