Skip to content

Commit

Permalink
fix(vitest): auto-enable "github-actions" only where users didn't con…
Browse files Browse the repository at this point in the history
…figure reporters (#5158)
  • Loading branch information
hi-ogawa authored Feb 9, 2024
1 parent 5ed537f commit ef0440c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 11 additions & 1 deletion docs/guide/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,17 @@ export default defineConfig({
### Github Actions Reporter <Badge type="info">1.3.0+</Badge>

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'],
},
})
```

<img alt="Github Actions" img-dark src="https://github.com/vitest-dev/vitest/assets/4232207/336cddc2-df6b-4b8a-8e72-4d00010e37f5">
<img alt="Github Actions" img-light src="https://github.com/vitest-dev/vitest/assets/4232207/ce8447c1-0eab-4fe1-abef-d0d322290dca">
Expand Down
9 changes: 5 additions & 4 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef0440c

Please sign in to comment.