From ef0440cbd326f7aff2f1a732a409a85940ff908a Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Fri, 9 Feb 2024 19:16:28 +0900 Subject: [PATCH] fix(vitest): auto-enable "github-actions" only where users didn't configure reporters (#5158) --- docs/guide/reporters.md | 12 +++++++++++- packages/vitest/src/node/config.ts | 9 +++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/guide/reporters.md b/docs/guide/reporters.md index 699bec9d6435..b69b73fb8b20 100644 --- a/docs/guide/reporters.md +++ b/docs/guide/reporters.md @@ -447,7 +447,17 @@ export default defineConfig({ ### Github Actions Reporter 1.3.0+ Output [workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message) -to provide annotations for test failures. This reporter is automatically enabled when `process.env.GITHUB_ACTIONS === 'true'`, thus it doesn't require any configuration. +to provide annotations for test failures. This reporter is automatically enabled with a [`default`](#default-reporter) reporter when `process.env.GITHUB_ACTIONS === 'true'`. + +If you configure non-default reporters, you need to explicitly add `github-actions`. + +```ts +export default defineConfig({ + test: { + reporters: process.env.GITHUB_ACTIONS ? ['dot', 'github-actions'] : ['dot'], + }, +}) +``` Github Actions Github Actions diff --git a/packages/vitest/src/node/config.ts b/packages/vitest/src/node/config.ts index 363f81b8062c..e1e46d16c6af 100644 --- a/packages/vitest/src/node/config.ts +++ b/packages/vitest/src/node/config.ts @@ -419,12 +419,13 @@ export function resolveConfig( resolved.reporters = Array.from(new Set(toArray(cliReporters))).filter(Boolean).map(reporter => [reporter, {}]) } - if (!resolved.reporters.length) + if (!resolved.reporters.length) { resolved.reporters.push(['default', {}]) - // automatically enable github-actions reporter - if (process.env.GITHUB_ACTIONS === 'true' && !resolved.reporters.some(v => Array.isArray(v) && v[0] === 'github-actions')) - resolved.reporters.push(['github-actions', {}]) + // also enable github-actions reporter as a default + if (process.env.GITHUB_ACTIONS === 'true') + resolved.reporters.push(['github-actions', {}]) + } if (resolved.changed) resolved.passWithNoTests ??= true