Skip to content

Commit ef0440c

Browse files
authoredFeb 9, 2024
fix(vitest): auto-enable "github-actions" only where users didn't configure reporters (#5158)
1 parent 5ed537f commit ef0440c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed
 

‎docs/guide/reporters.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,17 @@ export default defineConfig({
447447
### Github Actions Reporter <Badge type="info">1.3.0+</Badge>
448448

449449
Output [workflow commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message)
450-
to provide annotations for test failures. This reporter is automatically enabled when `process.env.GITHUB_ACTIONS === 'true'`, thus it doesn't require any configuration.
450+
to provide annotations for test failures. This reporter is automatically enabled with a [`default`](#default-reporter) reporter when `process.env.GITHUB_ACTIONS === 'true'`.
451+
452+
If you configure non-default reporters, you need to explicitly add `github-actions`.
453+
454+
```ts
455+
export default defineConfig({
456+
test: {
457+
reporters: process.env.GITHUB_ACTIONS ? ['dot', 'github-actions'] : ['dot'],
458+
},
459+
})
460+
```
451461

452462
<img alt="Github Actions" img-dark src="https://github.com/vitest-dev/vitest/assets/4232207/336cddc2-df6b-4b8a-8e72-4d00010e37f5">
453463
<img alt="Github Actions" img-light src="https://github.com/vitest-dev/vitest/assets/4232207/ce8447c1-0eab-4fe1-abef-d0d322290dca">

‎packages/vitest/src/node/config.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,13 @@ export function resolveConfig(
419419
resolved.reporters = Array.from(new Set(toArray(cliReporters))).filter(Boolean).map(reporter => [reporter, {}])
420420
}
421421

422-
if (!resolved.reporters.length)
422+
if (!resolved.reporters.length) {
423423
resolved.reporters.push(['default', {}])
424424

425-
// automatically enable github-actions reporter
426-
if (process.env.GITHUB_ACTIONS === 'true' && !resolved.reporters.some(v => Array.isArray(v) && v[0] === 'github-actions'))
427-
resolved.reporters.push(['github-actions', {}])
425+
// also enable github-actions reporter as a default
426+
if (process.env.GITHUB_ACTIONS === 'true')
427+
resolved.reporters.push(['github-actions', {}])
428+
}
428429

429430
if (resolved.changed)
430431
resolved.passWithNoTests ??= true

0 commit comments

Comments
 (0)
Please sign in to comment.