diff --git a/packages/vitest/src/node/config/resolveConfig.ts b/packages/vitest/src/node/config/resolveConfig.ts index 1b9703369..d484fc1d7 100644 --- a/packages/vitest/src/node/config/resolveConfig.ts +++ b/packages/vitest/src/node/config/resolveConfig.ts @@ -188,6 +188,7 @@ function captureProvidedOptions( fsModuleCache: sources.some(source => source?.fsModuleCache != null || (source?.experimental as { fsModuleCache?: boolean } | undefined)?.fsModuleCache != null), + silent: sources.some(source => source?.silent != null), } } diff --git a/packages/vitest/src/node/reporters/minimal.ts b/packages/vitest/src/node/reporters/minimal.ts index c2923edf5..9d7caf2af 100644 --- a/packages/vitest/src/node/reporters/minimal.ts +++ b/packages/vitest/src/node/reporters/minimal.ts @@ -1,3 +1,4 @@ +import type { Vitest } from '../core' import type { TestSpecification } from '../test-specification' import type { DefaultReporterOptions } from './default' import type { TestCase, TestModule, TestModuleState } from './reported-tasks' @@ -7,7 +8,14 @@ export class MinimalReporter extends DefaultReporter { renderSucceed = false constructor(options: DefaultReporterOptions = {}) { - super({ silent: 'passed-only', ...options, summary: false }) + super({ ...options, summary: false }) + } + + onInit(ctx: Vitest): void { + if (this.silent == null && !ctx.config.providedOptions.silent) { + this.silent = 'passed-only' + } + super.onInit(ctx) } onTestRunStart(specifications: ReadonlyArray): void { diff --git a/packages/vitest/src/node/types/config.ts b/packages/vitest/src/node/types/config.ts index c23edb203..a6e3dc6ad 100644 --- a/packages/vitest/src/node/types/config.ts +++ b/packages/vitest/src/node/types/config.ts @@ -1347,6 +1347,7 @@ export interface ResolvedConfig isolate: boolean environment: boolean fsModuleCache: boolean + silent: boolean } cliOptions: CliOptions diff --git a/test/e2e/test/reporters/agent.test.ts b/test/e2e/test/reporters/agent.test.ts index 784e31e26..6638cf3dc 100644 --- a/test/e2e/test/reporters/agent.test.ts +++ b/test/e2e/test/reporters/agent.test.ts @@ -64,6 +64,23 @@ describe('agent reporter', async () => { `) }) + test.each([true, false])('respects global silent: %s', async (silent) => { + const { stdout } = await runVitest({ + config: false, + include: ['./fixtures/reporters/console-some-failing.test.ts'], + silent, + reporters: [['agent', { isTTY: true }]], + }) + + if (silent) { + expect(stdout).not.toContain('Log from') + } + else { + expect(stdout).toContain('Log from passed test') + expect(stdout).toContain('Log from failed test') + } + }) + test('does not change silent behavior for other reporters', async () => { const { stdout } = await runVitest({ config: false,