Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/vitest/src/node/reporters/github-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class GithubActionsReporter implements Reporter {
}

if (this.options.jobSummary.enabled === true && this.options.jobSummary.outputPath) {
const summary = renderSummary(collectSummaryData(testModules), this.options.jobSummary.fileLinks)
const summary = renderSummary(collectSummaryData(testModules), this.options.jobSummary.fileLinks, this.ctx.config.name)

try {
writeFileSync(
Expand Down Expand Up @@ -440,10 +440,11 @@ function renderStats({ fileStats, testsStats }: SummaryData): string {

const SUMMARY_HEADER = '## Vitest Test Report\n'

function renderSummary(summaryData: SummaryData, fileLinks?: JobSummaryOptions['fileLinks']): string {
function renderSummary(summaryData: SummaryData, fileLinks?: JobSummaryOptions['fileLinks'], name?: string): string {
const fileLinkCreator = createGitHubFileLinkCreator(fileLinks)

let summary = `${SUMMARY_HEADER}${renderStats(summaryData)}`
const heading = name ? `## Vitest Test Report (${name})\n` : SUMMARY_HEADER
let summary = `${heading}${renderStats(summaryData)}`

if (summaryData.flakyTests.length > 0) {
summary += '\n### Flaky Tests\n\nThese tests passed only after one or more retries, indicating potential instability.\n'
Expand Down
31 changes: 31 additions & 0 deletions test/cli/test/reporters/github-actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ describe(GithubActionsReporter, () => {
`)
})

it('includes project name in heading when set', async ({ onTestFinished }) => {
const outputPath = resolve(tmpdir(), randomUUID())

onTestFinished(async () => {
await rm(outputPath).catch(() => {
console.error(`Could not remove ${outputPath}`)
})
})

const workspacePath = resolve(import.meta.dirname, '..', '..', '..', '..')

await runVitest({
name: 'my-project',
reporters: new GithubActionsReporter({
jobSummary: {
outputPath,
fileLinks: {
commitHash: 'aaa',
repository: 'owner/repo',
workspacePath,
},
},
}),
root: './fixtures/reporters/github-actions',
})

const summary = await readFile(outputPath, 'utf8')

expect(summary.startsWith('## Vitest Test Report (my-project)\n')).toBe(true)
})

it.for([{ enabled: false }, { outputPath: undefined }] as const)('does not write one when disabled or without `outputPath`', async (options) => {
const outputPath = resolve(tmpdir(), randomUUID())

Expand Down