@@ -22,6 +22,7 @@ const recordsFromLogs = require('../lib/network-recorder').recordsFromLogs;
2222const GatherRunner = require ( '../gather/gather-runner' ) ;
2323const log = require ( '../lib/log' ) ;
2424const path = require ( 'path' ) ;
25+ const Audit = require ( '../audits/audit' ) ;
2526
2627// cleanTrace is run to remove duplicate TracingStartedInPage events,
2728// and to change TracingStartedInBrowser events into TracingStartedInPage.
@@ -122,6 +123,21 @@ function validatePasses(passes, audits, rootPath) {
122123 }
123124 } ) ;
124125 } ) ;
126+
127+ // Log if multiple passes require trace or network data and could overwrite one another.
128+ const usedNames = new Set ( ) ;
129+ passes . forEach ( ( pass , index ) => {
130+ if ( ! pass . network && ! pass . trace ) {
131+ return ;
132+ }
133+
134+ const passName = pass . traceName || Audit . DEFAULT_PASS ;
135+ if ( usedNames . has ( passName ) ) {
136+ log . warn ( 'config' , `passes[${ index } ] may overwrite trace or network ` +
137+ `data of earlier pass without a unique traceName (repeated name: ${ passName } .` ) ;
138+ }
139+ usedNames . add ( passName ) ;
140+ } ) ;
125141}
126142
127143function getGatherersNeededByAudits ( audits ) {
@@ -238,8 +254,21 @@ function expandArtifacts(artifacts) {
238254 artifacts . traces [ key ] = trace ;
239255 } ) ;
240256 }
257+
241258 if ( artifacts . performanceLog ) {
242- artifacts . networkRecords = recordsFromLogs ( require ( artifacts . performanceLog ) ) ;
259+ if ( typeof artifacts . performanceLog === 'string' ) {
260+ // Support older format of a single performance log.
261+ const log = require ( artifacts . performanceLog ) ;
262+ artifacts . networkRecords = {
263+ [ Audit . DEFAULT_PASS ] : recordsFromLogs ( log )
264+ } ;
265+ } else {
266+ artifacts . networkRecords = { } ;
267+ Object . keys ( artifacts . performanceLog ) . forEach ( key => {
268+ const log = require ( artifacts . performanceLog [ key ] ) ;
269+ artifacts . networkRecords [ key ] = recordsFromLogs ( log ) ;
270+ } ) ;
271+ }
243272 }
244273
245274 return artifacts ;
0 commit comments