@@ -31,15 +31,26 @@ const testSuiteMap = {
3131 */
3232const afterStats = parseFile ( 'performance-results.json' ) ;
3333
34+ if ( ! afterStats . length ) {
35+ console . error ( 'No results file found' ) ;
36+ process . exit ( 1 ) ;
37+ }
38+
3439/**
3540 * @type {Array<{file: string, title: string, results: Record<string,number[]>[]}> }
3641 */
3742const baseStats = parseFile ( 'base-performance-results.json' ) ;
3843
44+ if ( ! baseStats . length ) {
45+ console . error ( 'No base results file found' ) ;
46+ process . exit ( 1 ) ;
47+ }
48+
3949/**
4050 * @type {Record<string, number> }
4151 */
4252const metrics = { } ;
53+
4354/**
4455 * @type {Record<string, number> }
4556 */
@@ -65,38 +76,14 @@ for ( const { title, results } of afterStats ) {
6576 }
6677}
6778
68- process . exit ( 0 ) ;
69-
70- /**
71- * Gets the array of metrics from a list of results.
72- *
73- * @param {Object[] } results A list of results to format.
74- * @return {Object } Metrics.
75- */
76- const formatResults = ( results ) => {
77- return results . reduce ( ( result , { key, file } ) => {
78- return {
79- ...result ,
80- ...Object . fromEntries (
81- Object . entries ( parseFile ( file ) ?? { } ) . map (
82- ( [ metric , value ] ) => [
83- key + '-' + metric ,
84- median ( value ) ,
85- ]
86- )
87- ) ,
88- } ;
89- } , { } ) ;
90- } ;
91-
9279const data = new TextEncoder ( ) . encode (
9380 JSON . stringify ( {
9481 branch,
9582 hash,
9683 baseHash,
9784 timestamp : parseInt ( timestamp , 10 ) ,
98- metrics : formatResults ( testResults ) ,
99- baseMetrics : formatResults ( baseResults ) ,
85+ metrics : metrics ,
86+ baseMetrics : baseMetrics ,
10087 } )
10188) ;
10289
0 commit comments