Skip to content

Testing with jest #8400

Open
Open
@franckyinuk

Description

@franckyinuk

Hi,

I have emscripten working nicely (using emcc 1.38.30):

  • I have c++ functions and classes exported
  • They use binding in the c++ files like this
EMSCRIPTEN_BINDINGS(MyClass)
{
    class_<MyOperation>("MYOperation");

    class_<OperationArray>("OperationArray")
        .constructor<>()
        .function<int>("GetSize", &OperationArray::GetSize)
        .function<ApiOperation*&, int>("GetAt", &OperationArray::GetAt)
        ;
}
  • Then they are compiled with those arguments
    -Oz -s WASM=1 -s INLINING_LIMIT=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s ALLOW_MEMORY_GROWTH=1 -s DISABLE_EXCEPTION_CATCHING=0 -Wno-switch -std=c++11 -c --bind -fvisibility-ms-compat
  • And they are linked with -s WASM=1 --bind -fvisibility-ms-compat
  • All my functions are getting called from some served javascript successfully

Now to the problem.
We have found that the bindings are a bit fleaky and sometime some functions become not visible from our javascript code.
So we thought we would had some jest tests to check programmatically if all our functions are being correctly exported.

So I tried 2 things.
1, I have found some tutorials showing how to test wasm files by instanciating the wasm file directly (https://hub.packtpub.com/testing-webassembly-modules-with-jest-tutorial/), but when I try to do the same I get lots of link errors like this one:
LinkError: WebAssembly Instantiation: Import #1 module="env" function="nullFunc_di" error: function import requires a callable
I get this for about 20-30 functions, and true enough those functions are all defined in the js file generated by emcc
I have tried to create all the missing functions but then the error I was getting changed:
LinkError: WebAssembly Instantiation: Import #43 module="env" function="tempDoublePtr" error: global import must be a number or WebAssembly.Global object

Why are all those functions needed by my wasm file?

2 Then I tried to load the js file generated by emcc but I get this error message
console.log ../builds/wasmMyClass/MyClass.js:4292
both async and sync fetching of the wasm failed

Any idea on this error?

Is it possible at all to test wasm file from jest?
Would there be another way to test that the exported functions are working as expected in javascript?

Any help would be appreciated,
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions