@@ -136,19 +136,44 @@ class RemoteRunner {
136136 }
137137}
138138
139- function BenchmarkReporter ( runner ) {
139+ function BenchmarkConsoleReporter ( runner ) {
140140 runner . on ( 'benchmark:result' , function ( obj ) {
141141 console . log ( ' ' , obj ) ;
142142 } ) ;
143143}
144144
145+ function BenchmarkJsonReporter ( runner ) {
146+ runner . on ( 'end' , results => {
147+ if ( runner . completed ) {
148+ const { mkdirSync, writeFileSync } = require ( 'fs' ) ;
149+
150+ const resultsDir = 'perf-test-results' ;
151+ mkdirSync ( resultsDir , { recursive : true } ) ;
152+
153+ const jsonPath = `${ resultsDir } /${ new Date ( ) . toISOString ( ) } .json` ;
154+ writeFileSync ( jsonPath , JSON . stringify ( results , null , 2 ) ) ;
155+ console . log ( 'Wrote JSON results to:' , jsonPath ) ;
156+ } else {
157+ console . log ( 'Runner failed; JSON will not be writted.' ) ;
158+ }
159+ } ) ;
160+ }
161+
145162async function startTest ( ) {
146163
147164 console . log ( 'Starting' , browserName , 'on' , testUrl ) ;
148165
149166 const runner = new RemoteRunner ( ) ;
150167 new MochaSpecReporter ( runner ) ;
151- new BenchmarkReporter ( runner ) ;
168+ new BenchmarkConsoleReporter ( runner ) ;
169+
170+ if ( process . env . JSON_REPORTER ) {
171+ if ( ! process . env . PERF ) {
172+ console . log ( '!!! JSON_REPORTER should only be set if PERF is also set.' ) ;
173+ process . exit ( 1 ) ;
174+ }
175+ new BenchmarkJsonReporter ( runner ) ;
176+ }
152177
153178 const options = {
154179 headless : true ,
0 commit comments