@@ -47,32 +47,47 @@ const belowThreshold = (id, expected, categories) => {
47
47
return actual < expected ;
48
48
} ;
49
49
50
- const getError = ( id , expected , results ) => {
51
- const category = results . find ( ( c ) => c . id === id ) ;
52
- return `Expected category ${ chalk . magenta (
50
+ const getError = ( id , expected , categories , audits ) => {
51
+ const category = categories . find ( ( c ) => c . id === id ) ;
52
+
53
+ const categoryError = `Expected category ${ chalk . magenta (
53
54
category . title ,
54
55
) } to be greater or equal to ${ chalk . green ( expected ) } but got ${ chalk . red (
55
56
category . score !== null ? category . score : 'unknown' ,
56
57
) } `;
58
+
59
+ const categoryAudits = category . auditRefs
60
+ . filter ( ( { weight, id } ) => weight > 0 && audits [ id ] . score < 1 )
61
+ . map ( ( ref ) => {
62
+ const audit = audits [ ref . id ] ;
63
+ return ` '${ chalk . magenta (
64
+ audit . title ,
65
+ ) } ' received a score of ${ chalk . yellow ( audit . score ) } `;
66
+ } )
67
+ . join ( '\n' ) ;
68
+
69
+ return categoryAudits ? `${ categoryError } \n${ categoryAudits } ` : categoryError ;
57
70
} ;
58
71
59
72
const formatResults = ( { results, thresholds } ) => {
60
73
const categories = Object . values (
61
74
results . lhr . categories ,
62
- ) . map ( ( { title, score, id } ) => ( { title, score, id } ) ) ;
75
+ ) . map ( ( { title, score, id, auditRefs } ) => ( { title, score, id, auditRefs } ) ) ;
63
76
64
77
const categoriesBelowThreshold = Object . entries (
65
78
thresholds ,
66
79
) . filter ( ( [ id , expected ] ) => belowThreshold ( id , expected , categories ) ) ;
67
80
68
81
const errors = categoriesBelowThreshold . map ( ( [ id , expected ] ) =>
69
- getError ( id , expected , categories ) ,
82
+ getError ( id , expected , categories , results . lhr . audits ) ,
70
83
) ;
71
84
72
85
const summary = {
73
- results : categories . map ( ( cat ) => ( {
74
- ...cat ,
75
- ...( thresholds [ cat . id ] ? { threshold : thresholds [ cat . id ] } : { } ) ,
86
+ results : categories . map ( ( { title, score, id } ) => ( {
87
+ title,
88
+ score,
89
+ id,
90
+ ...( thresholds [ id ] ? { threshold : thresholds [ id ] } : { } ) ,
76
91
} ) ) ,
77
92
} ;
78
93
0 commit comments