-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Show console logging in vitests when the --no-silent flag is set #7467
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,22 @@ | ||||||||||||||||||
export function resolveVerbosity(argv = process.argv, env = process.env) { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding JSDoc documentation to explain the function's behavior and the different flags it handles:
Suggested change
|
||||||||||||||||||
// Check if --no-silent flag is used (native vitest flag) | ||||||||||||||||||
const cliNoSilent = argv.includes("--no-silent") || argv.includes("--silent=false") | ||||||||||||||||||
const silent = !cliNoSilent // Silent by default | ||||||||||||||||||
|
||||||||||||||||||
// Check if verbose reporter is requested | ||||||||||||||||||
const wantsVerboseReporter = argv.some( | ||||||||||||||||||
(a) => a === "--reporter=verbose" || a === "-r=verbose" || a === "--reporter", | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this check for standalone |
||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
return { | ||||||||||||||||||
silent, | ||||||||||||||||||
reporters: ["dot", ...(wantsVerboseReporter ? ["verbose"] : [])], | ||||||||||||||||||
onConsoleLog: (_log: string, type: string) => { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding proper typing for better type safety and IDE support:
Suggested change
|
||||||||||||||||||
// When verbose, show everything | ||||||||||||||||||
// When silent, allow errors/warnings and drop info/log/warn noise | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment mentions "drop info/log/warn noise" but warnings typically go to stderr, so they would still appear even in silent mode with this logic. Is this the intended behavior? If warnings should be suppressed in silent mode, you might need to handle them differently. |
||||||||||||||||||
if (!silent || type === "stderr") return | ||||||||||||||||||
|
||||||||||||||||||
return false // Drop info/log/warn noise | ||||||||||||||||||
}, | ||||||||||||||||||
} | ||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new utility function should have comprehensive test coverage. Could we add unit tests to ensure it correctly handles different CLI argument combinations? This is critical configuration that affects test behavior.
Consider creating src/utils/tests/vitest-verbosity.spec.ts with tests for: