@@ -106,29 +106,22 @@ function cleanTrace(trace) {
106106 return trace ;
107107}
108108
109- function filterPasses ( passes , audits , rootPath ) {
109+ function validatePasses ( passes , audits , rootPath ) {
110+ if ( ! Array . isArray ( passes ) ) {
111+ return ;
112+ }
110113 const requiredGatherers = getGatherersNeededByAudits ( audits ) ;
111114
112- // Make sure we only have the gatherers that are needed by the audits
113- // that have been listed in the config.
114- const filteredPasses = passes . map ( pass => {
115- const freshPass = Object . assign ( { } , pass ) ;
116-
117- freshPass . gatherers = freshPass . gatherers . filter ( gatherer => {
115+ // Log if we are running gathers that are not needed by the audits listed in the config
116+ passes . forEach ( pass => {
117+ pass . gatherers . forEach ( gatherer => {
118118 const GathererClass = GatherRunner . getGathererClass ( gatherer , rootPath ) ;
119119 const isGatherRequiredByAudits = requiredGatherers . has ( GathererClass . name ) ;
120120 if ( isGatherRequiredByAudits === false ) {
121- log . warn ( 'config' , `Skipping ${ GathererClass . name } gatherer as no audit requires it.` ) ;
121+ log . warn ( 'config' , `${ GathererClass . name } is included, however no audit requires it.` ) ;
122122 }
123- return isGatherRequiredByAudits ;
124123 } ) ;
125-
126- return freshPass ;
127- } )
128-
129- // Now remove any passes which no longer have gatherers.
130- . filter ( p => p . gatherers . length > 0 ) ;
131- return filteredPasses ;
124+ } ) ;
132125}
133126
134127function getGatherersNeededByAudits ( audits ) {
@@ -144,33 +137,10 @@ function getGatherersNeededByAudits(audits) {
144137 } , new Set ( ) ) ;
145138}
146139
147- function filterAudits ( audits , auditWhitelist ) {
148- // If there is no whitelist, assume all.
149- if ( ! auditWhitelist ) {
150- return Array . from ( audits ) ;
151- }
152-
153- const rejected = [ ] ;
154- const filteredAudits = audits . filter ( a => {
155- const auditName = a . toLowerCase ( ) ;
156- const inWhitelist = auditWhitelist . has ( auditName ) ;
157-
158- if ( ! inWhitelist ) {
159- rejected . push ( auditName ) ;
160- }
161-
162- return inWhitelist ;
163- } ) ;
164-
165- if ( rejected . length ) {
166- log . log ( 'info' , 'Running these audits:' , `${ filteredAudits . join ( ', ' ) } ` ) ;
167- log . log ( 'info' , 'Skipping these audits:' , `${ rejected . join ( ', ' ) } ` ) ;
140+ function requireAudits ( audits , rootPath ) {
141+ if ( ! audits ) {
142+ return null ;
168143 }
169-
170- return filteredAudits ;
171- }
172-
173- function expandAudits ( audits , rootPath ) {
174144 const Runner = require ( '../runner' ) ;
175145
176146 return audits . map ( audit => {
@@ -247,8 +217,9 @@ function assertValidAudit(audit, auditDefinition) {
247217}
248218
249219function expandArtifacts ( artifacts ) {
250- const expandedArtifacts = Object . assign ( { } , artifacts ) ;
251-
220+ if ( ! artifacts ) {
221+ return null ;
222+ }
252223 // currently only trace logs and performance logs should be imported
253224 if ( artifacts . traces ) {
254225 Object . keys ( artifacts . traces ) . forEach ( key => {
@@ -264,15 +235,14 @@ function expandArtifacts(artifacts) {
264235 }
265236 trace = cleanTrace ( trace ) ;
266237
267- expandedArtifacts . traces [ key ] = trace ;
238+ artifacts . traces [ key ] = trace ;
268239 } ) ;
269240 }
270-
271241 if ( artifacts . performanceLog ) {
272- expandedArtifacts . networkRecords = recordsFromLogs ( require ( artifacts . performanceLog ) ) ;
242+ artifacts . networkRecords = recordsFromLogs ( require ( artifacts . performanceLog ) ) ;
273243 }
274244
275- return expandedArtifacts ;
245+ return artifacts ;
276246}
277247
278248/**
@@ -283,27 +253,24 @@ class Config {
283253 * @constructor
284254 * @param {Object } config
285255 */
286- constructor ( configJSON , auditWhitelist , configPath ) {
256+ constructor ( configJSON , configPath ) {
287257 if ( ! configJSON ) {
288258 configJSON = defaultConfig ;
289259 }
290-
260+ // We don't want to mutate the original config object
261+ configJSON = JSON . parse ( JSON . stringify ( configJSON ) ) ;
291262 // Store the directory of the config path, if one was provided.
292263 this . _configDir = configPath ? path . dirname ( configPath ) : undefined ;
293264
294- this . _audits = configJSON . audits ? expandAudits (
295- filterAudits ( configJSON . audits , auditWhitelist ) , this . _configDir
296- ) : null ;
297- // filterPasses expects audits to have been expanded
298- this . _passes = configJSON . passes ?
299- filterPasses ( configJSON . passes , this . _audits , this . _configDir ) :
300- null ;
301- this . _auditResults = configJSON . auditResults ? Array . from ( configJSON . auditResults ) : null ;
302- this . _artifacts = null ;
303- if ( configJSON . artifacts ) {
304- this . _artifacts = expandArtifacts ( configJSON . artifacts ) ;
305- }
306- this . _aggregations = configJSON . aggregations ? Array . from ( configJSON . aggregations ) : null ;
265+ this . _passes = configJSON . passes || null ;
266+ this . _auditResults = configJSON . auditResults || null ;
267+ this . _aggregations = configJSON . aggregations || null ;
268+
269+ this . _audits = requireAudits ( configJSON . audits , this . _configDir ) ;
270+ this . _artifacts = expandArtifacts ( configJSON . artifacts ) ;
271+
272+ // validatePasses must follow after audits are required
273+ validatePasses ( configJSON . passes , this . _audits , this . _configDir ) ;
307274 }
308275
309276 /** @type {string } */
0 commit comments