Skip to content

Commit

Permalink
fix(ci): filter failed scans when creating report
Browse files Browse the repository at this point in the history
Fixes #204
  • Loading branch information
harlan-zw committed Apr 13, 2024
1 parent 80ca6c8 commit 7b9eeea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
21 changes: 14 additions & 7 deletions packages/cli/src/reporters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,29 @@ export function generateReportPayload(reporter: 'jsonExpanded', reports: Unlight
export function generateReportPayload(reporter: 'jsonSimple' | 'json', reports: UnlighthouseRouteReport[]): ReportJsonSimple
export function generateReportPayload(reporter: 'csvSimple' | 'csv', reports: UnlighthouseRouteReport[]): string
export function generateReportPayload(reporter: 'csvExpanded', reports: UnlighthouseRouteReport[], config?: ReporterConfig): string
export function generateReportPayload(reporter: string, reports: UnlighthouseRouteReport[], config?: ReporterConfig): any {
const sortedReporters = reports.sort((a, b) => a.route.path.localeCompare(b.route.path))
export function generateReportPayload(reporter: string, _reports: UnlighthouseRouteReport[], config?: ReporterConfig): any {
const reports = _reports
.sort((a, b) => a.route.path.localeCompare(b.route.path))
.filter((r) => {
if (!r.report?.categories)
return false
return r.report.audits
})

if (reporter.startsWith('json')) {
if (reporter === 'jsonSimple' || reporter === 'json')
return reportJsonSimple(sortedReporters)
return reportJsonSimple(reports)
if (reporter === 'jsonExpanded')
return reportJsonExpanded(sortedReporters)
return reportJsonExpanded(reports)
}
if (reporter.startsWith('csv')) {
if (reporter === 'csvSimple' || reporter === 'csv')
return reportCSVSimple(sortedReporters)
return reportCSVSimple(reports)
if (reporter === 'csvExpanded')
return reportCSVExpanded(sortedReporters, config)
return reportCSVExpanded(reports, config)
}
if (reporter === 'lighthouseServer')
return reportLighthouseServer(sortedReporters, config)
return reportLighthouseServer(reports, config)

throw new Error(`Unsupported reporter: ${reporter}.`)
}
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/reporters/jsonExpanded.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { UnlighthouseRouteReport } from '@unlighthouse/core/src'
import type { CategoryAverageScore, CategoryScore, ExpandedRouteReport, MetricAverageScore, MetricScore, ReportJsonExpanded } from './types'

const relevantMetrics = [
Expand All @@ -9,12 +10,12 @@ const relevantMetrics = [
'interactive',
]

export function reportJsonExpanded(unlighthouseRouteReports): ReportJsonExpanded {
export function reportJsonExpanded(reports: UnlighthouseRouteReport[]): ReportJsonExpanded {
let metadata = {
metrics: {},
categories: {},
}
const routes = unlighthouseRouteReports
const routes = reports
.map((report) => {
const categories = Object.values(report.report?.categories ?? {}).reduce(
(prev: { [key: string]: CategoryScore }, category: any): any => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/reporters/jsonSimple.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { UnlighthouseRouteReport } from '../types'
import type { ReportJsonSimple } from './types'
import type { ReportJsonSimple, SimpleRouteReport } from './types'

export function reportJsonSimple(reports: UnlighthouseRouteReport[]): ReportJsonSimple {
return reports
Expand All @@ -9,7 +9,7 @@ export function reportJsonSimple(reports: UnlighthouseRouteReport[]): ReportJson
// @ts-expect-error untyped
scores[category.key] = category.score
})
return {
return <SimpleRouteReport> {
path: report.route.path,
score: report.report?.score,
...scores,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/reporters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export interface MetricScore {

export interface SimpleRouteReport {
path: string
score?: string
score?: number | string | null
[key: string]: string | number | null
}

export interface ExpandedRouteReport extends SimpleRouteReport {
Expand Down

0 comments on commit 7b9eeea

Please sign in to comment.