PocketIC error: Error: Jest: Got error running globalSetup

@NathanosDev, I am creating my testing setup for a Motoko project with PocketIC

When I run jest -c ./jest.config.ts, from command line I get the following error:

Error: Jest: Got error running globalSetup - /home/ildefons/neutrinite/rechain_icrc3/test/global-setup.ts, reason: Could not find the PocketIC binary. The PocketIC binary could not be found at /home/ildefons/neutrinite/rechain_icrc3/test/node_modules/@hadronous/pic/pocket-ic. Please try installing @hadronous/pic again.

I tried calling manually PocketIC by just calling explicitly /home/ildefons/neutrinite/rechain_icrc3/test/node_modules/@hadronous/pic/pocket-ic

and it successfully started the PockedIC server:
INFO pocket_ic_server: The PocketIC server is listening on port 44225

For more details about my setup: 22.04.2-Ubuntu

Any idea of what I could be doing wrong?

1 Like

Recent version of PicJS - assuming you are using PicJS - requires a global setup to spin PocketIC in the background.

Nathan describes the step in the documentation: https://hadronous.github.io/pic-js/docs/guides/using-jest

See " The PocketIC server needs to be started before running tests and stopped once they’re finished running. This can be done by creating global-setup.ts and global-teardown.ts files in your project’s root directory:"

2 Likes

Side node: if you are about to setup a full new suites of tests, I would maybe suggest to use Vitest instead of Jest. A bit more modern. If it can be useful, that’s the setting, PicJS + Vitest, in Juno: https://github.com/junobuild/juno

1 Like

I do have both files in my setup but I have the same exact error
image

Your jest-config.ts does reference the global-setup.ts and global-teardown.ts?

From Nathan’s doc:

import type { Config } from 'jest';

const config: Config = {
  watch: false,
  preset: 'ts-jest/presets/js-with-ts',
  testEnvironment: 'node',
  globalSetup: '<rootDir>/global-setup.ts', // <------------- here
  globalTeardown: '<rootDir>/global-teardown.ts', // <------------- and there
  testTimeout: 30_000,
};

export default config;
1 Like

Yes, configuration files are correct but we found the “error”:
I was using an old vesion of node (18.2), so by just updating node to (21.4) now it works

2 Likes

Coolio!

I’m using Node LTS, i.e. v20 works too. Have fun testing, PicJS is awesome.

1 Like