How can I see console output when testing with PocketIC + Jest

I am testing my Motoko project locally using PIC and Jest

To run my test suite I run the command: ./build.sh && jest -c ./jest.config.ts

The problem is that I cannot see my canister debug print out.

Is there a way to see the console printout generrated by my canister running locally?

Solution is to modify global.setup.ts as follows:

module.exports = async function (): Promise<void> {
  //const pic = await PocketIcServer.start();
  const pic = await PocketIcServer.start({showRuntimeLogs:true, showCanisterLogs:true
  });
2 Likes

@NathanosDev if I remember accorectly I had the exact same question, have you considered showing the logs by default - i.e. making the log options an opt-out config instead of opt-in?

Just thinking out at loud for future developers.

1 Like

That’s an interesting question. I’d love to know how a broader range of developers feel about this in order to make an educated decision on this.

My personal preference is to hide logs until they are necessary and then turn them on only for debugging purposes. Since I am usually debugging less often than I am debugging.

But if I can somehow understand that the majority of developers prefer the opposite then I’m happy to make that adjustment.

2 Likes

Another criterion could be comparing with existing test tooling.

For example, vitest prints out the logs by default unless the developers set the option silent to true (doc). So, in that case, we can maybe assume that “all” the developers using it expect their logs to be printed out by default as well?

Note that I am not suggesting changing the option because of that, just thinking out loud.

2 Likes

I think that’s a very good point. I’ll follow up on this soon and check out a few tools to see if there’s a consistent approach to this, thanks for that hint!

2 Likes