Show console logging in vitests when the --no-silent flag is set (#7467)

By default, all of the tests run in silent mode with monkey-patched the console logging so no console logging will ever appear in test output.
This confuses the agent- sometimes it will add console logging to help it debug things, and it won't see the logs that it expects.

Adds src/utils/vitest-verbosity.ts to handle verbosity resolution and console logging.
Modifies src/vitest.config.ts and webview-ui/vitest.config.ts to integrate the new verbosity control.
Removes manual console suppression from src/vitest.setup.ts and webview-ui/vitest.setup.ts as it's now handled dynamically.

Co-authored-by: Chris Hasson <noreply@example.com>
This commit is contained in:
Chris Hasson 2025-08-28 09:51:21 -07:00 committed by GitHub
parent 88409029aa
commit aee531a143
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 36 deletions

View file

@ -0,0 +1,22 @@
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",
)
return {
silent,
reporters: ["dot", ...(wantsVerboseReporter ? ["verbose"] : [])],
onConsoleLog: (_log: string, type: string) => {
// When verbose, show everything
// When silent, allow errors/warnings and drop info/log/warn noise
if (!silent || type === "stderr") return
return false // Drop info/log/warn noise
},
}
}

View file

@ -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: {

View file

@ -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
})

View file

@ -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: {

View file

@ -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
})