5
5
formatResults,
6
6
} = require ( './format' ) ;
7
7
8
+ // Strip ANSI color codes from strings, as they make CI sad.
9
+ const sanitizeString = ( str ) => {
10
+ return str
11
+ . replaceAll ( '\x1B[31m' , '' )
12
+ . replaceAll ( '\x1B[32m' , '' )
13
+ . replaceAll ( '\x1B[33m' , '' )
14
+ . replaceAll ( '\x1B[36m' , '' )
15
+ . replaceAll ( '\x1B[39m' , '' ) ;
16
+ } ;
17
+
8
18
describe ( 'format' , ( ) => {
9
19
const getCategories = ( { score } ) => [
10
20
{
@@ -42,13 +52,12 @@ describe('format', () => {
42
52
} ,
43
53
} ;
44
54
45
- // Awkward formatting as the strings contain ANSI escape codes for colours.
46
55
const formattedError = {
47
56
details :
48
- " '\x1B[36mrobots .txt is valid\x1B[39m ' received a score of \x1B[33m0\x1B[39m \n" +
49
- " '\x1B[36mTap targets are sized appropriately\x1B[39m ' received a score of \x1B[33m0.5\x1B[39m " ,
57
+ " 'robots .txt is valid' received a score of 0 \n" +
58
+ " 'Tap targets are sized appropriately' received a score of 0.5 " ,
50
59
message :
51
- 'Expected category \x1B[36mPerformance\x1B[39m to be greater or equal to \x1B[32m1\x1B[39m but got \x1B[31m0.5\x1B[39m ' ,
60
+ 'Expected category Performance to be greater or equal to 1 but got 0.5 ' ,
52
61
} ;
53
62
54
63
it ( 'returns an expected error message and list of details with valid score' , ( ) => {
@@ -58,7 +67,12 @@ describe('format', () => {
58
67
getCategories ( { score : 0.5 } ) ,
59
68
audits ,
60
69
) ;
61
- expect ( errorMessage ) . toEqual ( formattedError ) ;
70
+ expect ( sanitizeString ( errorMessage . details ) ) . toEqual (
71
+ formattedError . details ,
72
+ ) ;
73
+ expect ( sanitizeString ( errorMessage . message ) ) . toEqual (
74
+ formattedError . message ,
75
+ ) ;
62
76
} ) ;
63
77
64
78
describe ( 'belowThreshold' , ( ) => {
@@ -92,8 +106,8 @@ describe('format', () => {
92
106
audits ,
93
107
) ;
94
108
// Matching is awkward as the strings contain ANSI escape codes for colours.
95
- expect ( errorMessage . message ) . toContain (
96
- 'to be greater or equal to \x1B[32m1\x1B[39m but got \x1B[31munknown\x1B[39m ' ,
109
+ expect ( sanitizeString ( errorMessage . message ) ) . toContain (
110
+ 'to be greater or equal to 1 but got unknown ' ,
97
111
) ;
98
112
} ) ;
99
113
} ) ;
@@ -170,7 +184,12 @@ describe('format', () => {
170
184
results : getResults ( ) ,
171
185
thresholds,
172
186
} ) ;
173
- expect ( formattedResults . errors ) . toEqual ( [ formattedError ] ) ;
187
+ expect ( sanitizeString ( formattedResults . errors [ 0 ] . message ) ) . toEqual (
188
+ formattedError . message ,
189
+ ) ;
190
+ expect ( sanitizeString ( formattedResults . errors [ 0 ] . details ) ) . toEqual (
191
+ formattedError . details ,
192
+ ) ;
174
193
expect ( formattedResults . summary ) . toEqual ( [
175
194
{
176
195
id : 'performance' ,
0 commit comments