Skip to content

Commit 382a013

Browse files
committed
More informative check summary
1 parent 2649c1a commit 382a013

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

__tests__/github/handler.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ describe('createStatusCheck', () => {
125125
const report: Report = {
126126
results: {
127127
summary: {
128-
failed: 0
128+
passed: 5,
129+
skipped: 2
129130
}
130131
}
131132
} as Report
@@ -139,7 +140,7 @@ describe('createStatusCheck', () => {
139140
'Test Status',
140141
'completed',
141142
'success',
142-
'Test Results',
143+
'5 passed, 2 skipped',
143144
'Test summary'
144145
)
145146
})
@@ -167,7 +168,7 @@ describe('createStatusCheck', () => {
167168
'Test Status',
168169
'completed',
169170
'failure',
170-
'Test Results',
171+
'1 failed',
171172
'Test summary'
172173
)
173174
})
@@ -184,6 +185,7 @@ describe('createStatusCheck', () => {
184185
const report: Report = {
185186
results: {
186187
summary: {
188+
passed: 10,
187189
failed: 0
188190
}
189191
}
@@ -201,7 +203,7 @@ describe('createStatusCheck', () => {
201203
'Test Status',
202204
'completed',
203205
'success',
204-
'Test Results',
206+
'10 passed',
205207
expect.stringMatching(/^a{65000}$/)
206208
)
207209
})

src/github/handler.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,42 @@ async function postOrUpdateIssueComment(
267267
}
268268
}
269269

270+
/**
271+
* Formats the test summary into a string like "10 passed, 1 failed, 2 skipped".
272+
* @param summary - The test summary object
273+
* @returns Formatted summary string
274+
*/
275+
function formatTestSummary(summary: { passed: number; failed: number; skipped: number; pending: number; other: number }): string {
276+
const parts: string[] = []
277+
278+
if (summary.passed > 0) {
279+
parts.push(`${summary.passed} passed`)
280+
}
281+
282+
if (summary.failed > 0) {
283+
parts.push(`${summary.failed} failed`)
284+
}
285+
286+
if (summary.skipped > 0) {
287+
parts.push(`${summary.skipped} skipped`)
288+
}
289+
290+
if (summary.pending > 0) {
291+
parts.push(`${summary.pending} pending`)
292+
}
293+
294+
if (summary.other > 0) {
295+
parts.push(`${summary.other} other`)
296+
}
297+
298+
if (parts.length === 0) {
299+
return 'No tests'
300+
}
301+
302+
return parts.join(', ')
303+
}
304+
305+
270306
/**
271307
* Creates a status check for a action.
272308
*
@@ -285,14 +321,16 @@ export async function createStatusCheck(
285321
}
286322

287323
try {
324+
const formattedSummary = formatTestSummary(report.results.summary)
325+
288326
await createCheckRun(
289327
context.repo.owner,
290328
context.repo.repo,
291329
context.sha,
292330
inputs.statusCheckName,
293331
'completed',
294332
report.results.summary.failed > 0 ? 'failure' : 'success',
295-
'Test Results',
333+
formattedSummary,
296334
summary
297335
)
298336
} catch (error) {

0 commit comments

Comments
 (0)