Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 51 additions & 0 deletions packages/cli/src/reporters/__tests__/github-md-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<!\\)\|/g)).toHaveLength(7)
}
})
test('labels a check the CLI stopped waiting for as timed out, not failed', () => {
const row = (name: string, timedOut: boolean) => [`seq-${name}`, {
Expand Down Expand Up @@ -199,4 +205,49 @@ describe('GithubMdBuilder', () => {
expect(line.match(/(?<!\\)\|/g)).toHaveLength(6)
}
})

test('renders - instead of `undefined` when a check lacks sourceFile in a mixed map', () => {
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|-|- ||')
})
})
19 changes: 14 additions & 5 deletions packages/cli/src/reporters/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export class GithubMdBuilder {
this.tableHeaders = this.tableHeaders.concat(this.extraTableHeadersWithLinks)
}

// Under a Filename column, checks without a source file (e.g. fetched by `checkly trigger`
// alongside local ones) get a placeholder.
const fileCell = (sourceFile?: string) => this.hasFilenames
? (sourceFile ? `\`${escapeCell(sourceFile)}\`` : '-')
: undefined

for (const [, checkMap] of this.checkFilesMap.entries()) {
for (const [, { check, result, testResultId, numRetries }] of checkMap.entries()) {
const retries = numRetries ? ` (${numRetries} ${numRetries === 1 ? 'retry' : 'retries'})` : ''
Expand All @@ -88,7 +94,7 @@ export class GithubMdBuilder {
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,
fileCell(check?.getSourceFile?.()),
'- ',
this.testSessionId ? '' : undefined,
].filter(nonNullable).join(this.tableSeparator) + this.tableSeparator)
Expand All @@ -104,13 +110,16 @@ 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,
fileCell(result.sourceFile),
`${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)
if (this.testSessionId) {
// A check that failed with a run error has no test result to link to, but its row
// still needs the cell to stay aligned with the header.
tableRow.push(testResultId
? `[Full test report](${getTestSessionUrl(this.testSessionId)}/results/${testResultId})`
: '')
}

this.tableRows.push(this.tableSeparator + tableRow.join(this.tableSeparator) + this.tableSeparator)
Expand Down