@@ -12,6 +12,8 @@ const {
1212 textReport,
1313} = require ( "../lib" ) ;
1414
15+ const { analyze } = require ( "../lib/utils/analyze.js" ) ;
16+
1517describe ( "chartReport outputs benchmark results as a bar chart" , async ( t ) => {
1618 let output = "" ;
1719
@@ -285,6 +287,42 @@ describe("prettyReport outputs a beautiful report", async (t) => {
285287 } ) ;
286288} ) ;
287289
290+ describe ( "analyse" , async ( t ) => {
291+ let analysis ;
292+
293+ before ( async ( ) => {
294+ // Create a new Suite with the pretty reporter
295+ const suite = new Suite ( { } ) ;
296+
297+ // Add benchmarks with one being the baseline
298+ suite
299+ . add ( "baseline-test" , { baseline : true } , ( ) => {
300+ // Medium-speed operation
301+ for ( let i = 0 ; i < 10000 ; i ++ ) { }
302+ } )
303+ . add ( "other-test" , ( ) => {
304+ // Faster operation
305+ for ( let i = 0 ; i < 1000 ; i ++ ) { }
306+ } )
307+ . add ( "faster-test" , ( ) => {
308+ // Slower operation
309+ for ( let i = 0 ; i < 100 ; i ++ ) { }
310+ } ) ;
311+
312+ // Run the suite
313+ const results = await suite . run ( ) ;
314+ analysis = analyze ( results , false ) ;
315+ } ) ;
316+
317+ it ( "annotates the fastest result" , ( ) => {
318+ assert . equal ( analysis [ 2 ] . fastest , true , "fastest result" ) ;
319+ } ) ;
320+
321+ it ( "annotates the slowest result" , ( ) => {
322+ assert . equal ( analysis [ 0 ] . slowest , true , "slowest result" ) ;
323+ } ) ;
324+ } ) ;
325+
288326describe ( "baseline comparisons" , async ( t ) => {
289327 let results ;
290328
@@ -311,6 +349,22 @@ describe("baseline comparisons", async (t) => {
311349 results = await suite . run ( ) ;
312350 } ) ;
313351
352+ describe ( "analyze" , ( ) => {
353+ let analysis ;
354+
355+ before ( ( ) => {
356+ analysis = analyze ( results ) ;
357+ } ) ;
358+
359+ it ( "annotates the fastest result" , ( ) => {
360+ assert . equal ( results [ 1 ] . fastest , true , "fastest result" ) ;
361+ } ) ;
362+
363+ it ( "annotates the slowest result" , ( ) => {
364+ assert . equal ( results [ 2 ] . slowest , true , "slowest result" ) ;
365+ } ) ;
366+ } ) ;
367+
314368 describe ( "for prettyReport" , async ( t ) => {
315369 let output = "" ;
316370
0 commit comments