From a8750c07f51cbff6945acad949d7b9346ba108a4 Mon Sep 17 00:00:00 2001 From: Shafikul Islam Tanbir <58387559+shafiktanbir@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:37:44 +0600 Subject: [PATCH] fix(cli): keep Link column aligned on runError rows in GitHub reporter --- .../github-md-builder.spec.ts.snap | 2 +- .../__tests__/github-md-builder.spec.ts | 51 +++++++++++++++++++ packages/cli/src/reporters/github.ts | 7 ++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/reporters/__tests__/__snapshots__/github-md-builder.spec.ts.snap b/packages/cli/src/reporters/__tests__/__snapshots__/github-md-builder.spec.ts.snap index c1448e640..5152f1898 100644 --- a/packages/cli/src/reporters/__tests__/__snapshots__/github-md-builder.spec.ts.snap +++ b/packages/cli/src/reporters/__tests__/__snapshots__/github-md-builder.spec.ts.snap @@ -27,7 +27,7 @@ Ran **1** checks in **eu-west-1**. [View detailed test session summary](https://app.checklyhq.com/accounts/test-account-123/test-sessions/0c4c64b3-79c5-44a6-ae07-b580ce73f328) |Result|Name|Check Type|Filename|Duration|Link| |:-|:-|:-|:-|:-|:-| -|❌ Fail|Timed out check|-|\`folder/timeout.check.ts\`|- | +|❌ Fail|Timed out check|-|\`folder/timeout.check.ts\`|- || ## Execution Errors diff --git a/packages/cli/src/reporters/__tests__/github-md-builder.spec.ts b/packages/cli/src/reporters/__tests__/github-md-builder.spec.ts index 758bb8485..022bc016e 100644 --- a/packages/cli/src/reporters/__tests__/github-md-builder.spec.ts +++ b/packages/cli/src/reporters/__tests__/github-md-builder.spec.ts @@ -65,6 +65,12 @@ describe('GithubMdBuilder', () => { expect(markdown).not.toContain('NaN') expect(markdown).toContain('## Execution Errors') expect(markdown).toContain(runError) + + const tableLines = markdown.split('\n').filter(line => line.startsWith('|')) + // 6 columns (including Link) -> 7 delimiters per line + for (const line of tableLines) { + expect(line.match(/(? { const row = (name: string, timedOut: boolean) => [`seq-${name}`, { @@ -199,4 +205,49 @@ describe('GithubMdBuilder', () => { expect(line.match(/(? { + const map: checkFilesMap = new Map([ + ['folder/api.check.ts', new Map([ + ['seq-with-file', { + result: { + name: 'File Check', + sourceFile: 'folder/api.check.ts', + checkType: 'API', + responseTime: 10, + } as any, + titleString: 'File Check', + numRetries: 0, + }], + ])], + [undefined, new Map([ + ['seq-remote-done', { + result: { + name: 'Remote Finished', + checkType: 'API', + responseTime: 25, + } as any, + titleString: 'Remote Finished', + numRetries: 0, + }], + ['seq-remote-pending', { + check: { name: 'Remote Pending', checkType: 'API' } as any, + titleString: 'Remote Pending', + numRetries: 0, + }], + ])], + ]) + + const markdown = new GithubMdBuilder({ + testSessionId, + numChecks: 3, + runLocation, + checkFilesMap: map, + }).render() + + expect(markdown).not.toContain('undefined') + expect(markdown).toContain('|✅ Pass|File Check|API|`folder/api.check.ts`|10ms ||') + expect(markdown).toContain('|✅ Pass|Remote Finished|API|-|25ms ||') + expect(markdown).toContain('|⏹️ Not finished|Remote Pending|API|-|- ||') + }) }) diff --git a/packages/cli/src/reporters/github.ts b/packages/cli/src/reporters/github.ts index f4c1f2c5b..3069bd38c 100644 --- a/packages/cli/src/reporters/github.ts +++ b/packages/cli/src/reporters/github.ts @@ -83,12 +83,13 @@ export class GithubMdBuilder { const retries = numRetries ? ` (${numRetries} ${numRetries === 1 ? 'retry' : 'retries'})` : '' if (!result) { // Only a run that stopped early leaves checks without a result. + const sourceFile = check?.getSourceFile?.() this.tableRows.push(this.tableSeparator + [ `⏹️ Not finished${retries}`, escapeCell((check as any)?.name), // Checks fetched for `checkly trigger` carry their type; local constructs do not. escapeCell((check as any)?.checkType ?? '-'), - this.hasFilenames ? `\`${escapeCell(check?.getSourceFile?.())}\`` : undefined, + this.hasFilenames ? (sourceFile ? `\`${escapeCell(sourceFile)}\`` : '-') : undefined, '- ', this.testSessionId ? '' : undefined, ].filter(nonNullable).join(this.tableSeparator) + this.tableSeparator) @@ -104,13 +105,15 @@ export class GithubMdBuilder { // A check that failed with a run error (e.g. the CLI timing out while waiting for // a result) has no check type or response time, so fall back to a placeholder. escapeCell(result.checkType ?? '-'), - this.hasFilenames ? `\`${escapeCell(result.sourceFile)}\`` : undefined, + this.hasFilenames ? (result.sourceFile ? `\`${escapeCell(result.sourceFile)}\`` : '-') : undefined, `${result.responseTime != null ? formatDuration(result.responseTime) : '-'} `, ].filter(nonNullable) if (this.testSessionId && testResultId) { const linkColumn = `[Full test report](${getTestSessionUrl(this.testSessionId)}/results/${testResultId})` tableRow.push(linkColumn) + } else if (this.testSessionId) { + tableRow.push('') } this.tableRows.push(this.tableSeparator + tableRow.join(this.tableSeparator) + this.tableSeparator)