Skip to content

Commit 1e7d33e

Browse files
hassoncsChris Hasson
authored andcommitted
Show console logging in vitests when the --no-silent flag is set (RooCodeInc#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 <[email protected]>
1 parent cb2efe2 commit 1e7d33e

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

src/utils/vitest-verbosity.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export function resolveVerbosity(argv = process.argv, env = process.env) {
2+
// Check if --no-silent flag is used (native vitest flag)
3+
const cliNoSilent = argv.includes("--no-silent") || argv.includes("--silent=false")
4+
const silent = !cliNoSilent // Silent by default
5+
6+
// Check if verbose reporter is requested
7+
const wantsVerboseReporter = argv.some(
8+
(a) => a === "--reporter=verbose" || a === "-r=verbose" || a === "--reporter",
9+
)
10+
11+
return {
12+
silent,
13+
reporters: ["dot", ...(wantsVerboseReporter ? ["verbose"] : [])],
14+
onConsoleLog: (_log: string, type: string) => {
15+
// When verbose, show everything
16+
// When silent, allow errors/warnings and drop info/log/warn noise
17+
if (!silent || type === "stderr") return
18+
19+
return false // Drop info/log/warn noise
20+
},
21+
}
22+
}

src/vitest.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { defineConfig } from "vitest/config"
22
import path from "path"
3+
import { resolveVerbosity } from "./utils/vitest-verbosity"
4+
5+
const { silent, reporters, onConsoleLog } = resolveVerbosity()
36

47
export default defineConfig({
58
test: {
69
globals: true,
710
setupFiles: ["./vitest.setup.ts"],
811
watch: false,
9-
reporters: ["dot"],
10-
silent: true,
12+
reporters,
13+
silent,
1114
testTimeout: 20_000,
1215
hookTimeout: 20_000,
16+
onConsoleLog,
1317
},
1418
resolve: {
1519
alias: {

src/vitest.setup.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,3 @@ export function allowNetConnect(host?: string | RegExp) {
1515

1616
// Global mocks that many tests expect.
1717
global.structuredClone = global.structuredClone || ((obj: any) => JSON.parse(JSON.stringify(obj)))
18-
19-
// Suppress console.log during tests to reduce noise.
20-
// Keep console.error for actual errors.
21-
const originalConsoleLog = console.log
22-
const originalConsoleWarn = console.warn
23-
const originalConsoleInfo = console.info
24-
25-
console.log = () => {}
26-
console.warn = () => {}
27-
console.info = () => {}
28-
29-
afterAll(() => {
30-
console.log = originalConsoleLog
31-
console.warn = originalConsoleWarn
32-
console.info = originalConsoleInfo
33-
})

webview-ui/vitest.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { defineConfig } from "vitest/config"
22
import path from "path"
3+
import { resolveVerbosity } from "../src/utils/vitest-verbosity"
4+
5+
const { silent, reporters, onConsoleLog } = resolveVerbosity()
36

47
export default defineConfig({
58
test: {
69
globals: true,
710
setupFiles: ["./vitest.setup.ts"],
811
watch: false,
9-
reporters: ["dot"],
10-
silent: true,
12+
reporters,
13+
silent,
1114
environment: "jsdom",
1215
include: ["src/**/*.spec.ts", "src/**/*.spec.tsx"],
16+
onConsoleLog,
1317
},
1418
resolve: {
1519
alias: {

webview-ui/vitest.setup.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,3 @@ Object.defineProperty(window, "matchMedia", {
5050

5151
// Mock scrollIntoView which is not available in jsdom
5252
Element.prototype.scrollIntoView = vi.fn()
53-
54-
// Suppress console.log during tests to reduce noise.
55-
// Keep console.error for actual errors.
56-
const originalConsoleLog = console.log
57-
const originalConsoleWarn = console.warn
58-
const originalConsoleInfo = console.info
59-
60-
console.log = () => {}
61-
console.warn = () => {}
62-
console.info = () => {}
63-
64-
afterAll(() => {
65-
console.log = originalConsoleLog
66-
console.warn = originalConsoleWarn
67-
console.info = originalConsoleInfo
68-
})

0 commit comments

Comments
 (0)