@@ -52,13 +52,21 @@ const persistResults = async ({ report, path }) => {
52
52
} ;
53
53
54
54
const getUtils = ( { utils } ) => {
55
+ // This function checks to see if we're running within the Netlify Build system,
56
+ // and if so, we use the util functions. If not, we're likely running locally
57
+ // so fall back using console.log to emulate the output.
58
+
59
+ // If available, fails the Netlify build with the supplied message
60
+ // https://docs.netlify.com/integrations/build-plugins/create-plugins/#error-reporting
55
61
const failBuild =
56
62
( utils && utils . build && utils . build . failBuild ) ||
57
63
( ( message , { error } = { } ) => {
58
64
console . error ( message , error && error . message ) ;
59
65
process . exitCode = 1 ;
60
66
} ) ;
61
67
68
+ // If available, displays the summary in the Netlify UI Deploy Summary section
69
+ // https://docs.netlify.com/integrations/build-plugins/create-plugins/#logging
62
70
const show =
63
71
( utils && utils . status && utils . status . show ) ||
64
72
( ( { summary } ) => console . log ( summary ) ) ;
@@ -94,10 +102,11 @@ const runAudit = async ({
94
102
if ( error ) {
95
103
return { error } ;
96
104
} else {
97
- const { summary, shortSummary, details, report, errors } = formatResults ( {
98
- results,
99
- thresholds,
100
- } ) ;
105
+ const { summary, shortSummary, details, report, errors, runtimeError } =
106
+ formatResults ( {
107
+ results,
108
+ thresholds,
109
+ } ) ;
101
110
102
111
if ( output_path ) {
103
112
await persistResults ( { report, path : join ( serveDir , output_path ) } ) ;
@@ -109,6 +118,7 @@ const runAudit = async ({
109
118
details,
110
119
report,
111
120
errors,
121
+ runtimeError,
112
122
} ;
113
123
}
114
124
} catch ( error ) {
@@ -161,28 +171,45 @@ const processResults = ({ data, errors }) => {
161
171
return {
162
172
error : err ,
163
173
summary : data
164
- . map ( ( { path, url, summary, shortSummary, details, report } ) => {
165
- const obj = { report, details } ;
174
+ . map (
175
+ ( {
176
+ path,
177
+ url,
178
+ summary,
179
+ shortSummary,
180
+ details,
181
+ report,
182
+ runtimeError,
183
+ } ) => {
184
+ const obj = { report, details } ;
166
185
167
- if ( summary ) {
168
- obj . summary = summary . reduce ( ( acc , item ) => {
169
- acc [ item . id ] = Math . round ( item . score * 100 ) ;
170
- return acc ;
171
- } , { } ) ;
172
- }
186
+ if ( ! runtimeError && summary ) {
187
+ obj . summary = summary . reduce ( ( acc , item ) => {
188
+ acc [ item . id ] = Math . round ( item . score * 100 ) ;
189
+ return acc ;
190
+ } , { } ) ;
191
+ }
173
192
174
- if ( path ) {
175
- obj . path = path ;
176
- reports . push ( obj ) ;
177
- return `Summary for path '${ chalk . magenta ( path ) } ': ${ shortSummary } ` ;
178
- }
179
- if ( url ) {
180
- obj . url = url ;
181
- reports . push ( obj ) ;
182
- return `Summary for url '${ chalk . magenta ( url ) } ': ${ shortSummary } ` ;
183
- }
184
- return `${ shortSummary } ` ;
185
- } )
193
+ if ( runtimeError ) {
194
+ reports . push ( obj ) ;
195
+ return `Error testing '${ chalk . magenta ( path || url ) } ': ${
196
+ runtimeError . message
197
+ } `;
198
+ }
199
+
200
+ if ( path ) {
201
+ obj . path = path ;
202
+ reports . push ( obj ) ;
203
+ return `Summary for path '${ chalk . magenta ( path ) } ': ${ shortSummary } ` ;
204
+ }
205
+ if ( url ) {
206
+ obj . url = url ;
207
+ reports . push ( obj ) ;
208
+ return `Summary for url '${ chalk . magenta ( url ) } ': ${ shortSummary } ` ;
209
+ }
210
+ return `${ shortSummary } ` ;
211
+ } ,
212
+ )
186
213
. join ( '\n' ) ,
187
214
extraData : reports ,
188
215
} ;
@@ -204,7 +231,7 @@ module.exports = {
204
231
const allErrors = [ ] ;
205
232
const data = [ ] ;
206
233
for ( const { serveDir, path, url, thresholds, output_path } of audits ) {
207
- const { errors, summary, shortSummary, details, report } =
234
+ const { errors, summary, shortSummary, details, report, runtimeError } =
208
235
await runAudit ( {
209
236
serveDir,
210
237
path,
@@ -213,9 +240,13 @@ module.exports = {
213
240
output_path,
214
241
settings,
215
242
} ) ;
216
- if ( summary ) {
243
+
244
+ if ( summary && ! runtimeError ) {
217
245
console . log ( { results : summary } ) ;
218
246
}
247
+ if ( runtimeError ) {
248
+ console . log ( { runtimeError } ) ;
249
+ }
219
250
220
251
const fullPath = [ serveDir , path ] . join ( '/' ) ;
221
252
if ( report ) {
@@ -239,6 +270,7 @@ module.exports = {
239
270
shortSummary,
240
271
details,
241
272
report,
273
+ runtimeError,
242
274
} ) ;
243
275
}
244
276
0 commit comments