hadronous / pic-js

An Internet Computer Protocol canister testing library for TypeScript and JavaScript.
https://hadronous.github.io/pic-js/
Apache License 2.0
11 stars 6 forks source link

Clarify logging when using Vitest test runner #50

Open peterpeterparker opened 5 months ago

peterpeterparker commented 5 months ago

Hi,

I followed the running-tests documentation and tried both options showCanisterLogs and showRuntimeLogs but, none of those allowed me to retrieve the ic_cdk::print I logged in my canister.

Therefore, I'm not sure if it's a potential issue or a feature. If the first, maybe I missed something (I'm using vitest), if the latest, it would maybe be nice to clarify that in the documentation.

Best

nathanosdev commented 5 months ago

For me, using showCanisterLogs allows me to see ic_cdk::print calls in my canister when using Jest or Bun, but I've had some issues related to Vitest swallowing console logs. Maybe something here will help you: https://github.com/vitest-dev/vscode/discussions/117.

peterpeterparker commented 5 months ago

Thanks for the feedback. I actually have no issue with console.log and vitest. It's stricly the ic_cdk::print that I did not managed to print out. 🤷‍♂️

I guess the documentation is then clear enough and if it works with jest and bun, then I guess something fishy on my hand. I'll close this.

peterpeterparker commented 5 months ago

Found it! I read the thread you shared again, thanks a lot, and noticed that --reporter was mentionned few times which resolved the issue - i.e. specifying the basic reporter.

import { resolve } from 'node:path';
import { defineConfig } from 'vitest/config';

export default defineConfig({
    test: {
        globalSetup: './vitest.setup.ts',
        globals: true,
        watch: false,
        silent: false,
        reporters: ['basic'],
        environment: 'node',
        poolOptions: {
            threads: {
                singleThread: true
            }
        }
    },
    resolve: {
        alias: [
            {
                find: '$declarations',
                replacement: resolve(__dirname, 'src/declarations')
            }
        ]
    }
});
nathanosdev commented 5 months ago

Awesome, thanks for letting me know. I re-opened the issue as a reminder for me to add a note about this into the docs :)