Skip to content

Commit

Permalink
fix links for github and json report
Browse files Browse the repository at this point in the history
  • Loading branch information
clample committed Jul 19, 2024
1 parent a6e94a9 commit ce8466a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
19 changes: 10 additions & 9 deletions packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,17 @@ export default class Test extends AuthCommand {
}, links))
})

runner.on(Events.CHECK_SUCCESSFUL, (sequenceId: SequenceId, check, result, links?: TestResultsShortLinks) => {
if (result.hasFailures) {
process.exitCode = 1
}
runner.on(Events.CHECK_SUCCESSFUL,
(sequenceId: SequenceId, check, result, testResultId, links?: TestResultsShortLinks) => {
if (result.hasFailures) {
process.exitCode = 1
}

reporters.forEach(r => r.onCheckEnd(sequenceId, {
logicalId: check.logicalId,
sourceFile: check.getSourceFile(),
...result,
}, links))
reporters.forEach(r => r.onCheckEnd(sequenceId, {
logicalId: check.logicalId,
sourceFile: check.getSourceFile(),
...result,
}, testResultId, links))
})

Check failure on line 285 in packages/cli/src/commands/test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 4
runner.on(Events.CHECK_FAILED, (sequenceId: SequenceId, check, message: string) => {
reporters.forEach(r => r.onCheckEnd(sequenceId, {
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/commands/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ export default class Trigger extends AuthCommand {
runner.on(Events.CHECK_ATTEMPT_RESULT, (sequenceId: SequenceId, check, result, links?: TestResultsShortLinks) => {
reporters.forEach(r => r.onCheckAttemptResult(sequenceId, result, links))
})
runner.on(Events.CHECK_SUCCESSFUL, (sequenceId: SequenceId, _, result, links?: TestResultsShortLinks) => {
if (result.hasFailures) {
process.exitCode = 1
}
reporters.forEach(r => r.onCheckEnd(sequenceId, result, links))
})
runner.on(Events.CHECK_SUCCESSFUL,
(sequenceId: SequenceId, _, result, testResultId, links?: TestResultsShortLinks) => {
if (result.hasFailures) {
process.exitCode = 1
}
reporters.forEach(r => r.onCheckEnd(sequenceId, result, testResultId, links))
})
runner.on(Events.CHECK_FAILED, (sequenceId: SequenceId, check, message: string) => {
reporters.forEach(r => r.onCheckEnd(sequenceId, {
...check,
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/reporters/abstract-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type checkFilesMap = Map<string|undefined, Map<SequenceId, {
result?: any,
titleString: string,
checkStatus?: CheckStatus,
testResultId?: string,
links?: TestResultsShortLinks,
numRetries: number,
}>>
Expand Down Expand Up @@ -80,10 +81,11 @@ export default abstract class AbstractListReporter implements Reporter {
checkFile.numRetries++
}

onCheckEnd (sequenceId: SequenceId, checkResult: any, links?: TestResultsShortLinks) {
onCheckEnd (sequenceId: SequenceId, checkResult: any, testResultId?: string, links?: TestResultsShortLinks) {
const checkStatus = this.checkFilesMap!.get(checkResult.sourceFile)!.get(sequenceId)!
checkStatus.result = checkResult
checkStatus.links = links
checkStatus.testResultId = testResultId
checkStatus.checkStatus = checkResult.hasFailures ? CheckStatus.FAILED : CheckStatus.SUCCESSFUL
checkStatus.titleString = formatCheckTitle(checkStatus.checkStatus, checkResult, {
includeSourceFile: false,
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/reporters/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class GithubMdBuilder {
}

for (const [_, checkMap] of this.checkFilesMap.entries()) {
for (const [_, { result, links }] of checkMap.entries()) {
for (const [_, { result, testResultId }] of checkMap.entries()) {
const tableRow: Array<string> = [
`${result.hasFailures ? '❌ Fail' : '✅ Pass'}`,
`${result.name}`,
Expand All @@ -72,8 +72,8 @@ export class GithubMdBuilder {
`${formatDuration(result.responseTime)} `,
].filter(nonNullable)

if (links?.testResultLink) {
const linkColumn = `[Full test report](${links?.testResultLink})`
if (this.testSessionId && testResultId) {
const linkColumn = `[Full test report](${getTestSessionUrl(this.testSessionId)}/results/${testResultId})`
tableRow.push(linkColumn)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path'

import AbstractListReporter, { checkFilesMap } from './abstract-list'
import { CheckRunId, SequenceId } from '../services/abstract-check-runner'
import { printLn } from './util'
import { printLn, getTestSessionUrl } from './util'

const outputFile = './checkly-json-report.json'

Expand Down Expand Up @@ -40,7 +40,7 @@ export class JsonBuilder {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [_, checkMap] of this.checkFilesMap.entries()) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const [_, { result, links, numRetries }] of checkMap.entries()) {
for (const [_, { result, testResultId, numRetries }] of checkMap.entries()) {
const check: any = {
result: result.hasFailures ? 'Fail' : 'Pass',
name: result.name,
Expand All @@ -56,8 +56,8 @@ export class JsonBuilder {
check.filename = result.sourceFile
}

if (links?.testResultLink) {
check.link = links?.testResultLink
if (this.testSessionId && testResultId) {
check.link = `${getTestSessionUrl(this.testSessionId)}/results/${testResultId}`
}

testSessionSummary.checks.push(check)
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/reporters/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export default class ListReporter extends AbstractListReporter {
this._printSummary()
}

onCheckEnd (sequenceId: SequenceId, checkResult: any, links?: TestResultsShortLinks) {
super.onCheckEnd(sequenceId, checkResult)
onCheckEnd (sequenceId: SequenceId, checkResult: any, testResultId?: string, links?: TestResultsShortLinks) {
super.onCheckEnd(sequenceId, checkResult, testResultId, links)
this._clearSummary()

if (this.verbose) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/reporters/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Reporter {
onBegin(checks: Array<{ check: any, sequenceId: SequenceId }>, testSessionId?: string): void;
onCheckInProgress(check: any, sequenceId: SequenceId): void;
onCheckAttemptResult(sequenceId: SequenceId, checkResult: any, links?: TestResultsShortLinks): void;
onCheckEnd(sequenceId: SequenceId, checkResult: any, links?: TestResultsShortLinks): void;
onCheckEnd(sequenceId: SequenceId, checkResult: any, testResultId?: string, links?: TestResultsShortLinks): void;
onEnd(): void;
onError(err: Error): void,
onSchedulingDelayExceeded(): void
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/services/abstract-check-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default abstract class AbstractCheckRunner extends EventEmitter {
const links = testResultId && result.hasFailures && await this.getShortLinks(testResultId)
if (resultType === 'FINAL') {
this.disableTimeout(sequenceId)
this.emit(Events.CHECK_SUCCESSFUL, sequenceId, check, result, links)
this.emit(Events.CHECK_SUCCESSFUL, sequenceId, check, result, testResultId, links)
this.emit(Events.CHECK_FINISHED, check)
} else if (resultType === 'ATTEMPT') {
this.emit(Events.CHECK_ATTEMPT_RESULT, sequenceId, check, result, links)
Expand Down

0 comments on commit ce8466a

Please sign in to comment.