Skip to content

Commit 9072477

Browse files
authored
feat: adds degraded state to reporters [sc-00] (#1020)
1 parent df80080 commit 9072477

File tree

9 files changed

+65
-14
lines changed

9 files changed

+65
-14
lines changed

packages/cli/src/reporters/__tests__/__snapshots__/util.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ exports[`formatCheckResult() Browser Check result formats a Browser Check result
208208

209209
exports[`formatCheckResult() Browser Check result formats a basic Browser Check result : browser-check-result-basic-format 1`] = `""`;
210210

211+
exports[`formatCheckTitle() should print a degraded check title: degraded-check-title 1`] = `"⚠ /test/test-file.check.ts > Test Check (11s)"`;
212+
211213
exports[`formatCheckTitle() should print a failed check title: failed-check-title 1`] = `"✖ /test/test-file.check.ts > Test Check (11s)"`;
212214

213215
exports[`formatCheckTitle() should print a passed check title: passed-check-title 1`] = `"✔ /test/test-file.check.ts > Test Check (11s)"`;

packages/cli/src/reporters/__tests__/util.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { formatCheckTitle, formatCheckResult, CheckStatus } from '../util'
1+
import { formatCheckTitle, formatCheckResult, CheckStatus, resultToCheckStatus } from '../util'
22
import { simpleCheckFixture } from './fixtures/simple-check'
33
import { apiCheckResult } from './fixtures/api-check-result'
44
import { browserCheckResult } from './fixtures/browser-check-result'
@@ -23,6 +23,10 @@ describe('formatCheckTitle()', () => {
2323
expect(stripAnsi(formatCheckTitle(CheckStatus.SUCCESSFUL, simpleCheckFixture, { includeSourceFile: true })))
2424
.toMatchSnapshot('passed-check-title')
2525
})
26+
it('should print a degraded check title', () => {
27+
expect(stripAnsi(formatCheckTitle(CheckStatus.DEGRADED, simpleCheckFixture, { includeSourceFile: true })))
28+
.toMatchSnapshot('degraded-check-title')
29+
})
2630
it('should print a running check title', () => {
2731
expect(stripAnsi(formatCheckTitle(CheckStatus.RUNNING, simpleCheckFixture, { includeSourceFile: true })))
2832
.toMatchSnapshot('running-check-title')
@@ -85,3 +89,22 @@ describe('formatCheckResult()', () => {
8589
})
8690
})
8791
})
92+
93+
describe('resultToCheckStatus()', () => {
94+
it('returns a successful status', () => {
95+
expect(resultToCheckStatus({ hasFailures: false, isDegraded: false, hasErrors: false }))
96+
.toBe(CheckStatus.SUCCESSFUL)
97+
})
98+
it('returns a failed status', () => {
99+
expect(resultToCheckStatus({ hasFailures: true, isDegraded: false, hasErrors: false }))
100+
.toBe(CheckStatus.FAILED)
101+
})
102+
it('returns a failed status when also degraded', () => {
103+
expect(resultToCheckStatus({ hasFailures: true, isDegraded: true, hasErrors: false }))
104+
.toBe(CheckStatus.FAILED)
105+
})
106+
it('returns a degraded status', () => {
107+
expect(resultToCheckStatus({ hasFailures: false, isDegraded: true, hasErrors: false }))
108+
.toBe(CheckStatus.DEGRADED)
109+
})
110+
})

packages/cli/src/reporters/abstract-list.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import indentString from 'indent-string'
33

44
import { TestResultsShortLinks } from '../rest/test-sessions'
55
import { Reporter } from './reporter'
6-
import { CheckStatus, formatCheckTitle, getTestSessionUrl, printLn } from './util'
7-
import type { SequenceId, RunLocation } from '../services/abstract-check-runner'
6+
import { CheckStatus, formatCheckTitle, getTestSessionUrl, printLn, resultToCheckStatus } from './util'
7+
import type { RunLocation, SequenceId } from '../services/abstract-check-runner'
88
import { Check } from '../constructs/check'
99
import { testSessions } from '../rest/api'
1010

@@ -86,7 +86,7 @@ export default abstract class AbstractListReporter implements Reporter {
8686
checkStatus.result = checkResult
8787
checkStatus.links = links
8888
checkStatus.testResultId = testResultId
89-
checkStatus.checkStatus = checkResult.hasFailures ? CheckStatus.FAILED : CheckStatus.SUCCESSFUL
89+
checkStatus.checkStatus = resultToCheckStatus(checkResult)
9090
checkStatus.titleString = formatCheckTitle(checkStatus.checkStatus, checkResult, {
9191
includeSourceFile: false,
9292
})
@@ -104,7 +104,7 @@ export default abstract class AbstractListReporter implements Reporter {
104104
}
105105

106106
_printSummary (opts: { skipCheckCount?: boolean} = {}) {
107-
const counts = { numFailed: 0, numPassed: 0, numRunning: 0, numRetrying: 0, scheduling: 0 }
107+
const counts = { numFailed: 0, numPassed: 0, numDegraded: 0, numRunning: 0, numRetrying: 0, scheduling: 0 }
108108
const status = []
109109
if (this.checkFilesMap!.size === 1 && this.checkFilesMap!.has(undefined)) {
110110
status.push(chalk.bold('Summary:'))
@@ -120,6 +120,8 @@ export default abstract class AbstractListReporter implements Reporter {
120120
counts.numRunning++
121121
} else if (result.hasFailures) {
122122
counts.numFailed++
123+
} else if (result.isDegraded) {
124+
counts.numDegraded++
123125
} else {
124126
counts.numPassed++
125127
}
@@ -134,6 +136,7 @@ export default abstract class AbstractListReporter implements Reporter {
134136
counts.numRunning ? chalk.bold.magenta(`${counts.numRunning} running`) : undefined,
135137
counts.numRetrying ? chalk.bold(`${counts.numRetrying} retrying`) : undefined,
136138
counts.numFailed ? chalk.bold.red(`${counts.numFailed} failed`) : undefined,
139+
counts.numDegraded ? chalk.bold.yellow(`${counts.numDegraded} degraded`) : undefined,
137140
counts.numPassed ? chalk.bold.green(`${counts.numPassed} passed`) : undefined,
138141
`${this.numChecks} total`,
139142
].filter(Boolean).join(', '))
@@ -153,14 +156,16 @@ export default abstract class AbstractListReporter implements Reporter {
153156
}
154157

155158
_printBriefSummary () {
156-
const counts = { numFailed: 0, numPassed: 0, numPending: 0 }
159+
const counts = { numFailed: 0, numDegraded: 0, numPassed: 0, numPending: 0 }
157160
const status = []
158161
for (const [, checkMap] of this.checkFilesMap!.entries()) {
159162
for (const [_, { result }] of checkMap.entries()) {
160163
if (!result) {
161164
counts.numPending++
162165
} else if (result.hasFailures) {
163166
counts.numFailed++
167+
} else if (result.isDegraded) {
168+
counts.numDegraded++
164169
} else {
165170
counts.numPassed++
166171
}
@@ -169,6 +174,7 @@ export default abstract class AbstractListReporter implements Reporter {
169174
status.push('')
170175
status.push([
171176
counts.numFailed ? chalk.bold.red(`${counts.numFailed} failed`) : undefined,
177+
counts.numDegraded ? chalk.bold.yellow(`${counts.numDegraded} degraded`) : undefined,
172178
counts.numPassed ? chalk.bold.green(`${counts.numPassed} passed`) : undefined,
173179
counts.numPending ? chalk.bold.magenta(`${counts.numPending} pending`) : undefined,
174180
`${this.numChecks} total`,

packages/cli/src/reporters/ci.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import indentString from 'indent-string'
22

33
import AbstractListReporter from './abstract-list'
4-
import { formatCheckTitle, formatCheckResult, CheckStatus, printLn } from './util'
4+
import { formatCheckTitle, formatCheckResult, CheckStatus, printLn, resultToCheckStatus } from './util'
55
import { SequenceId } from '../services/abstract-check-runner'
66
import { TestResultsShortLinks } from '../rest/test-sessions'
77

@@ -27,7 +27,7 @@ export default class CiReporter extends AbstractListReporter {
2727

2828
onCheckEnd (sequenceId: SequenceId, checkResult: any) {
2929
super.onCheckEnd(sequenceId, checkResult)
30-
printLn(formatCheckTitle(checkResult.hasFailures ? CheckStatus.FAILED : CheckStatus.SUCCESSFUL, checkResult))
30+
printLn(formatCheckTitle(resultToCheckStatus(checkResult), checkResult))
3131

3232
if (this.verbose || checkResult.hasFailures) {
3333
printLn(indentString(formatCheckResult(checkResult), 4), 2, 1)

packages/cli/src/reporters/dot.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export default class DotReporter extends AbstractListReporter {
1818
super.onCheckEnd(sequenceId, checkResult)
1919
if (checkResult.hasFailures) {
2020
print(`${chalk.red('F')}`)
21+
} else if (checkResult.isDegraded) {
22+
print(`${chalk.yellow('D')}`)
2123
} else {
2224
print(`${chalk.green('.')}`)
2325
}

packages/cli/src/reporters/github.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33

44
import AbstractListReporter, { checkFilesMap } from './abstract-list'
55
import { SequenceId } from '../services/abstract-check-runner'
6-
import { formatDuration, printLn, getTestSessionUrl } from './util'
6+
import { CheckStatus, formatDuration, getTestSessionUrl, printLn, resultToCheckStatus } from './util'
77

88
const outputFile = './checkly-github-report.md'
99

@@ -64,8 +64,9 @@ export class GithubMdBuilder {
6464

6565
for (const [_, checkMap] of this.checkFilesMap.entries()) {
6666
for (const [_, { result, testResultId }] of checkMap.entries()) {
67+
const checkStatus = resultToCheckStatus(result)
6768
const tableRow: Array<string> = [
68-
`${result.hasFailures ? '❌ Fail' : '✅ Pass'}`,
69+
`${checkStatus === CheckStatus.FAILED ? '❌ Fail' : checkStatus === CheckStatus.DEGRADED ? '⚠️ Degraded' : '✅ Pass'}`,
6970
`${result.name}`,
7071
`${result.checkType}`,
7172
this.hasFilenames ? `\`${result.sourceFile}\`` : undefined,

packages/cli/src/reporters/json.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path'
33

44
import AbstractListReporter, { checkFilesMap } from './abstract-list'
55
import { CheckRunId, SequenceId } from '../services/abstract-check-runner'
6-
import { printLn, getTestSessionUrl } from './util'
6+
import { CheckStatus, getTestSessionUrl, printLn, resultToCheckStatus } from './util'
77

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

@@ -41,8 +41,9 @@ export class JsonBuilder {
4141
for (const [_, checkMap] of this.checkFilesMap.entries()) {
4242
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4343
for (const [_, { result, testResultId, numRetries }] of checkMap.entries()) {
44+
const checkStatus = resultToCheckStatus(result)
4445
const check: any = {
45-
result: result.hasFailures ? 'Fail' : 'Pass',
46+
result: checkStatus === CheckStatus.FAILED ? 'Fail' : checkStatus === CheckStatus.DEGRADED ? 'Degraded' : 'Pass',
4647
name: result.name,
4748
checkType: result.checkType,
4849
durationMilliseconds: result.responseTime ?? null,

packages/cli/src/reporters/list.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import chalk from 'chalk'
33

44
import AbstractListReporter from './abstract-list'
55
import { SequenceId } from '../services/abstract-check-runner'
6-
import { formatCheckTitle, formatCheckResult, CheckStatus, printLn } from './util'
6+
import { formatCheckTitle, formatCheckResult, CheckStatus, printLn, resultToCheckStatus } from './util'
77
import { TestResultsShortLinks } from '../rest/test-sessions'
88

99
export default class ListReporter extends AbstractListReporter {
@@ -58,13 +58,17 @@ export default class ListReporter extends AbstractListReporter {
5858
this._clearSummary()
5959

6060
if (this.verbose) {
61-
printLn(formatCheckTitle(checkResult.hasFailures ? CheckStatus.FAILED : CheckStatus.SUCCESSFUL, checkResult))
61+
printLn(formatCheckTitle(resultToCheckStatus(checkResult), checkResult))
6262
printLn(indentString(formatCheckResult(checkResult), 4), 2, 1)
6363
} else {
6464
if (checkResult.hasFailures) {
6565
printLn(formatCheckTitle(CheckStatus.FAILED, checkResult))
6666
printLn(indentString(formatCheckResult(checkResult), 4), 2, 1)
6767
}
68+
if (checkResult.isDegraded) {
69+
printLn(formatCheckTitle(CheckStatus.DEGRADED, checkResult))
70+
printLn(indentString(formatCheckResult(checkResult), 4), 2, 1)
71+
}
6872
}
6973

7074
if (links) {

packages/cli/src/reporters/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum CheckStatus {
1313
RETRIED,
1414
FAILED,
1515
SUCCESSFUL,
16+
DEGRADED,
1617
}
1718

1819
export function formatDuration (ms: number): string {
@@ -44,6 +45,9 @@ export function formatCheckTitle (
4445
} else if (status === CheckStatus.FAILED) {
4546
statusString = logSymbols.error
4647
format = chalk.bold.red
48+
} else if (status === CheckStatus.DEGRADED) {
49+
statusString = logSymbols.warning
50+
format = chalk.bold.yellow
4751
} else if (status === CheckStatus.SCHEDULING) {
4852
statusString = '~'
4953
format = chalk.bold.dim
@@ -440,6 +444,14 @@ function toString (val: any): string {
440444
}
441445
}
442446

447+
export function resultToCheckStatus (checkResult: any): CheckStatus {
448+
return checkResult.hasFailures
449+
? CheckStatus.FAILED
450+
: checkResult.isDegraded
451+
? CheckStatus.DEGRADED
452+
: CheckStatus.SUCCESSFUL
453+
}
454+
443455
export function print (text: string) {
444456
process.stdout.write(text)
445457
}

0 commit comments

Comments
 (0)