Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify logging when using Vitest test runner #50

Open
peterpeterparker opened this issue Jun 4, 2024 · 4 comments
Open

Clarify logging when using Vitest test runner #50

peterpeterparker opened this issue Jun 4, 2024 · 4 comments

Comments

@peterpeterparker
Copy link

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
Copy link
Contributor

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: vitest-dev/vscode#117.

@peterpeterparker
Copy link
Author

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
Copy link
Author

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 nathanosdev reopened this Jun 5, 2024
@nathanosdev
Copy link
Contributor

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 :)

@nathanosdev nathanosdev changed the title Clarify logging Clarify logging when using Vitest test runner Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants