Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/utils/vitest-verbosity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export function resolveVerbosity(argv = process.argv, env = process.env) {
Copy link

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:

  • --no-silent flag
  • --silent=false flag
  • --reporter=verbose flag
  • combinations of flags
  • default behavior

Copy link

Choose a reason for hiding this comment

The 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
export function resolveVerbosity(argv = process.argv, env = process.env) {
/**
* Resolves vitest verbosity settings based on CLI arguments
* @param argv - Process arguments array (defaults to process.argv)
* @param env - Process environment object (defaults to process.env)
* @returns Configuration object with silent mode, reporters, and console log handler
*/
export function resolveVerbosity(argv = process.argv, env = process.env) {

// 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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check for standalone --reporter intentional? It seems incomplete as it would match if someone just passes --reporter alone without a value. Should this be checking for --reporter verbose as a complete argument instead?

)

return {
silent,
reporters: ["dot", ...(wantsVerboseReporter ? ["verbose"] : [])],
onConsoleLog: (_log: string, type: string) => {
Copy link

Choose a reason for hiding this comment

The 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
onConsoleLog: (_log: string, type: string) => {
onConsoleLog: (_log: string, type: 'stdout' | 'stderr'): false | void => {

// When verbose, show everything
// When silent, allow errors/warnings and drop info/log/warn noise
Copy link

Choose a reason for hiding this comment

The 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
},
}
}
8 changes: 6 additions & 2 deletions src/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { defineConfig } from "vitest/config"
import path from "path"
import { resolveVerbosity } from "./utils/vitest-verbosity"

const { silent, reporters, onConsoleLog } = resolveVerbosity()

export default defineConfig({
test: {
globals: true,
setupFiles: ["./vitest.setup.ts"],
watch: false,
reporters: ["dot"],
silent: true,
reporters,
silent,
testTimeout: 20_000,
hookTimeout: 20_000,
onConsoleLog,
},
resolve: {
alias: {
Expand Down
16 changes: 0 additions & 16 deletions src/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,3 @@ export function allowNetConnect(host?: string | RegExp) {

// Global mocks that many tests expect.
global.structuredClone = global.structuredClone || ((obj: any) => JSON.parse(JSON.stringify(obj)))

// Suppress console.log during tests to reduce noise.
// Keep console.error for actual errors.
const originalConsoleLog = console.log
const originalConsoleWarn = console.warn
const originalConsoleInfo = console.info

console.log = () => {}
console.warn = () => {}
console.info = () => {}

afterAll(() => {
console.log = originalConsoleLog
console.warn = originalConsoleWarn
console.info = originalConsoleInfo
})
8 changes: 6 additions & 2 deletions webview-ui/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { defineConfig } from "vitest/config"
import path from "path"
import { resolveVerbosity } from "../src/utils/vitest-verbosity"

const { silent, reporters, onConsoleLog } = resolveVerbosity()

export default defineConfig({
test: {
globals: true,
setupFiles: ["./vitest.setup.ts"],
watch: false,
reporters: ["dot"],
silent: true,
reporters,
silent,
environment: "jsdom",
include: ["src/**/*.spec.ts", "src/**/*.spec.tsx"],
onConsoleLog,
},
resolve: {
alias: {
Expand Down
16 changes: 0 additions & 16 deletions webview-ui/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,3 @@ Object.defineProperty(window, "matchMedia", {

// Mock scrollIntoView which is not available in jsdom
Element.prototype.scrollIntoView = vi.fn()

// Suppress console.log during tests to reduce noise.
// Keep console.error for actual errors.
const originalConsoleLog = console.log
const originalConsoleWarn = console.warn
const originalConsoleInfo = console.info

console.log = () => {}
console.warn = () => {}
console.info = () => {}

afterAll(() => {
console.log = originalConsoleLog
console.warn = originalConsoleWarn
console.info = originalConsoleInfo
})
Loading