Using wasm modult 'ic-vetkd-utils' in Jest

We are using the ic-vetkd-utils WASM module successfully in our frontend to benefit from an easy access to the latest VetKD features provided by dfinity (find it here: https://github.com/dfinity/examples/tree/master/rust/vetkd)

import * as vetkd from 'ic-vetkd-utils';
const seed = window.crypto.getRandomValues(new Uint8Array(32));
const tsk = new vetkd.TransportSecretKey(seed);

However, for e2e integration tests we are using Jest and we cannot import the very same module with the same code as above, it simply results in Cannot find module 'ic-vetkd-utils' from 'tests/my.test.js'

Any ideas?

It depends on how you’ve set your project up. How are you resolving the module for your frontend code and how is your Jest config setup?

The module is stored in the root directory as ic-vetkd-utils-0.1.0.tgz and referenced in package.json:

"ic-vetkd-utils": "file:ic-vetkd-utils-0.1.0.tgz",

That works fine for the frontend code, I can import and use the module as described in the code above.

So far I started on a green field with Jest, having simply this file:

import * as vetkd from 'ic-vetkd-utils';

describe("My Tests", () => {
    test("it should use vetkd", async () => {
        //const seed = crypto.randomBytes(32);
        //const tsk = new vetkd.TransportSecretKey(seed);
    }, 10000); // Set timeout to 10s
});

No Jest config yet, and simply this import fails with Cannot find module 'ic-vetkd-utils' from 'tests/my.test.js'

I think you need the moduleNameMapper config option from Jest: Configuring Jest · Jest
There you can map ic-vetkd-utils to <rootDir>/ic-vetkd-utils-0.1.0.tgz.

Thanks, will try out tonight…

By the way, ic-vetkd-utils seems to be a normal module available in node_modules:
Screenshot 2023-09-26 at 07.08.23

No luck so far with the moduleNameMapper, need to investigate further…