fix(cli): fix quiet mode tests by capturing console before host creation (#10827)

This commit is contained in:
Chris Estreich 2026-01-18 10:07:49 -08:00 committed by GitHub
parent 4093bff3ae
commit ea62173792
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 10 deletions

View file

@ -100,16 +100,17 @@ describe("ExtensionHost", () => {
ephemeral: false,
debug: false,
exitOnComplete: false,
integrationTest: true, // Set explicitly for testing
}
const host = new ExtensionHost(options)
// Options are stored but integrationTest is set to true
// Options are stored as-is
const storedOptions = getPrivate<ExtensionHostOptions>(host, "options")
expect(storedOptions.mode).toBe(options.mode)
expect(storedOptions.workspacePath).toBe(options.workspacePath)
expect(storedOptions.extensionPath).toBe(options.extensionPath)
expect(storedOptions.integrationTest).toBe(true) // Always set to true in constructor
expect(storedOptions.integrationTest).toBe(true)
})
it("should be an EventEmitter instance", () => {
@ -298,16 +299,19 @@ describe("ExtensionHost", () => {
})
it("should suppress console when integrationTest is false", () => {
const host = createTestHost()
// Capture the real console.log before any host is created
const originalLog = console.log
// Override integrationTest to false
// Create host with integrationTest: true to prevent constructor from suppressing
const host = createTestHost({ integrationTest: true })
// Override integrationTest to false to test suppression
const options = getPrivate<ExtensionHostOptions>(host, "options")
options.integrationTest = false
callPrivate(host, "setupQuietMode")
// Console should be modified
// Console should be modified (suppressed)
expect(console.log).not.toBe(originalLog)
// Restore for other tests
@ -332,9 +336,12 @@ describe("ExtensionHost", () => {
describe("restoreConsole", () => {
it("should restore original console methods when suppressed", () => {
const host = createTestHost()
// Capture the real console.log before any host is created
const originalLog = console.log
// Create host with integrationTest: true to prevent constructor from suppressing
const host = createTestHost({ integrationTest: true })
// Override integrationTest to false to actually suppress
const options = getPrivate<ExtensionHostOptions>(host, "options")
options.integrationTest = false

View file

@ -152,10 +152,7 @@ export class ExtensionHost extends EventEmitter implements ExtensionHostInterfac
constructor(options: ExtensionHostOptions) {
super()
this.options = {
...options,
integrationTest: true, // Always set to true in CLI mode to allow tests to control console suppression
}
this.options = options
// Set up quiet mode early, before any extension code runs.
// This suppresses console output from the extension during load.