Skip to content

Commit bb2bc12

Browse files
sorccushafiktanbirclaude
authored
fix(cli): keep Link column aligned on runError rows in GitHub reporter [RED-1572] [ship] (#1619)
* fix(cli): keep Link column aligned on runError rows in GitHub reporter * refactor(cli): share the GitHub reporter's Filename and Link cell logic Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Shafikul Islam Tanbir <58387559+shafiktanbir@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1b61af9 commit bb2bc12

3 files changed

Lines changed: 66 additions & 6 deletions

File tree

‎packages/cli/src/reporters/__tests__/__snapshots__/github-md-builder.spec.ts.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Ran **1** checks in **eu-west-1**.
2727
[View detailed test session summary](https://app.checklyhq.com/accounts/test-account-123/test-sessions/0c4c64b3-79c5-44a6-ae07-b580ce73f328)
2828
|Result|Name|Check Type|Filename|Duration|Link|
2929
|:-|:-|:-|:-|:-|:-|
30-
|❌ Fail|Timed out check|-|\`folder/timeout.check.ts\`|- |
30+
|❌ Fail|Timed out check|-|\`folder/timeout.check.ts\`|- ||
3131
3232
## Execution Errors
3333

‎packages/cli/src/reporters/__tests__/github-md-builder.spec.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ describe('GithubMdBuilder', () => {
6565
expect(markdown).not.toContain('NaN')
6666
expect(markdown).toContain('## Execution Errors')
6767
expect(markdown).toContain(runError)
68+
69+
const tableLines = markdown.split('\n').filter(line => line.startsWith('|'))
70+
// 6 columns (including Link) -> 7 delimiters per line
71+
for (const line of tableLines) {
72+
expect(line.match(/(?<!\\)\|/g)).toHaveLength(7)
73+
}
6874
})
6975
test('labels a check the CLI stopped waiting for as timed out, not failed', () => {
7076
const row = (name: string, timedOut: boolean) => [`seq-${name}`, {
@@ -199,4 +205,49 @@ describe('GithubMdBuilder', () => {
199205
expect(line.match(/(?<!\\)\|/g)).toHaveLength(6)
200206
}
201207
})
208+
209+
test('renders - instead of `undefined` when a check lacks sourceFile in a mixed map', () => {
210+
const map: checkFilesMap = new Map([
211+
['folder/api.check.ts', new Map([
212+
['seq-with-file', {
213+
result: {
214+
name: 'File Check',
215+
sourceFile: 'folder/api.check.ts',
216+
checkType: 'API',
217+
responseTime: 10,
218+
} as any,
219+
titleString: 'File Check',
220+
numRetries: 0,
221+
}],
222+
])],
223+
[undefined, new Map([
224+
['seq-remote-done', {
225+
result: {
226+
name: 'Remote Finished',
227+
checkType: 'API',
228+
responseTime: 25,
229+
} as any,
230+
titleString: 'Remote Finished',
231+
numRetries: 0,
232+
}],
233+
['seq-remote-pending', {
234+
check: { name: 'Remote Pending', checkType: 'API' } as any,
235+
titleString: 'Remote Pending',
236+
numRetries: 0,
237+
}],
238+
])],
239+
])
240+
241+
const markdown = new GithubMdBuilder({
242+
testSessionId,
243+
numChecks: 3,
244+
runLocation,
245+
checkFilesMap: map,
246+
}).render()
247+
248+
expect(markdown).not.toContain('undefined')
249+
expect(markdown).toContain('|✅ Pass|File Check|API|`folder/api.check.ts`|10ms ||')
250+
expect(markdown).toContain('|✅ Pass|Remote Finished|API|-|25ms ||')
251+
expect(markdown).toContain('|⏹️ Not finished|Remote Pending|API|-|- ||')
252+
})
202253
})

‎packages/cli/src/reporters/github.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export class GithubMdBuilder {
7878
this.tableHeaders = this.tableHeaders.concat(this.extraTableHeadersWithLinks)
7979
}
8080

81+
// Under a Filename column, checks without a source file (e.g. fetched by `checkly trigger`
82+
// alongside local ones) get a placeholder.
83+
const fileCell = (sourceFile?: string) => this.hasFilenames
84+
? (sourceFile ? `\`${escapeCell(sourceFile)}\`` : '-')
85+
: undefined
86+
8187
for (const [, checkMap] of this.checkFilesMap.entries()) {
8288
for (const [, { check, result, testResultId, numRetries }] of checkMap.entries()) {
8389
const retries = numRetries ? ` (${numRetries} ${numRetries === 1 ? 'retry' : 'retries'})` : ''
@@ -88,7 +94,7 @@ export class GithubMdBuilder {
8894
escapeCell((check as any)?.name),
8995
// Checks fetched for `checkly trigger` carry their type; local constructs do not.
9096
escapeCell((check as any)?.checkType ?? '-'),
91-
this.hasFilenames ? `\`${escapeCell(check?.getSourceFile?.())}\`` : undefined,
97+
fileCell(check?.getSourceFile?.()),
9298
'- ',
9399
this.testSessionId ? '' : undefined,
94100
].filter(nonNullable).join(this.tableSeparator) + this.tableSeparator)
@@ -104,13 +110,16 @@ export class GithubMdBuilder {
104110
// A check that failed with a run error (e.g. the CLI timing out while waiting for
105111
// a result) has no check type or response time, so fall back to a placeholder.
106112
escapeCell(result.checkType ?? '-'),
107-
this.hasFilenames ? `\`${escapeCell(result.sourceFile)}\`` : undefined,
113+
fileCell(result.sourceFile),
108114
`${result.responseTime != null ? formatDuration(result.responseTime) : '-'} `,
109115
].filter(nonNullable)
110116

111-
if (this.testSessionId && testResultId) {
112-
const linkColumn = `[Full test report](${getTestSessionUrl(this.testSessionId)}/results/${testResultId})`
113-
tableRow.push(linkColumn)
117+
if (this.testSessionId) {
118+
// A check that failed with a run error has no test result to link to, but its row
119+
// still needs the cell to stay aligned with the header.
120+
tableRow.push(testResultId
121+
? `[Full test report](${getTestSessionUrl(this.testSessionId)}/results/${testResultId})`
122+
: '')
114123
}
115124

116125
this.tableRows.push(this.tableSeparator + tableRow.join(this.tableSeparator) + this.tableSeparator)

0 commit comments

Comments
 (0)