@@ -285,19 +285,12 @@ describe("prettyReport outputs a beautiful report", async (t) => {
285285 } ) ;
286286} ) ;
287287
288- describe ( "prettyReport shows baseline comparisons" , async ( t ) => {
289- let output = "" ;
288+ describe ( "baseline comparisons" , async ( t ) => {
289+ let results ;
290290
291291 before ( async ( ) => {
292- const originalStdoutWrite = process . stdout . write ;
293- process . stdout . write = ( data ) => {
294- output += data ;
295- } ;
296-
297292 // Create a new Suite with the pretty reporter
298- const suite = new Suite ( {
299- reporter : prettyReport ,
300- } ) ;
293+ const suite = new Suite ( { } ) ;
301294
302295 // Add benchmarks with one being the baseline
303296 suite
@@ -315,73 +308,91 @@ describe("prettyReport shows baseline comparisons", async (t) => {
315308 } ) ;
316309
317310 // Run the suite
318- await suite . run ( ) ;
319-
320- process . stdout . write = originalStdoutWrite ;
311+ results = await suite . run ( ) ;
321312 } ) ;
322313
323- it ( "should include a summary section" , ( ) => {
324- assert . ok ( output . includes ( "Summary (vs. baseline):" ) ) ;
325- } ) ;
314+ describe ( "for prettyReport" , async ( t ) => {
315+ let output = "" ;
326316
327- it ( "should show 'faster' comparison in summary" , ( ) => {
328- const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
329- assert . ok ( summary . includes ( "faster" ) ) ;
330- } ) ;
317+ before ( async ( ) => {
318+ const originalStdoutWrite = process . stdout . write ;
319+ process . stdout . write = ( data ) => {
320+ output += data ;
321+ } ;
331322
332- it ( "should show 'slower' comparison in summary" , ( ) => {
333- const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
334- assert . ok ( summary . includes ( "slower" ) ) ;
323+ prettyReport ( results ) ;
324+ process . stdout . write = originalStdoutWrite ;
325+ } ) ;
326+
327+ it ( "should include a summary section" , ( ) => {
328+ assert . ok ( output . includes ( "Summary (vs. baseline):" ) ) ;
329+ } ) ;
330+
331+ it ( "should show 'faster' comparison in summary" , ( ) => {
332+ const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
333+ assert . ok ( summary . includes ( "faster" ) ) ;
334+ } ) ;
335+
336+ it ( "should show 'slower' comparison in summary" , ( ) => {
337+ const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
338+ assert . ok ( summary . includes ( "slower" ) ) ;
339+ } ) ;
335340 } ) ;
336- } ) ;
337341
338- describe ( "textReport shows baseline comparisons " , async ( t ) => {
339- let output = "" ;
342+ describe ( "for textReport " , async ( t ) => {
343+ let output = "" ;
340344
341- before ( async ( ) => {
342- const originalStdoutWrite = process . stdout . write ;
343- process . stdout . write = ( data ) => {
344- output += data ;
345- } ;
345+ before ( async ( ) => {
346+ const originalStdoutWrite = process . stdout . write ;
347+ process . stdout . write = ( data ) => {
348+ output += data ;
349+ } ;
346350
347- // Create a new Suite with the text reporter
348- const suite = new Suite ( {
349- reporter : textReport ,
351+ textReport ( results ) ;
352+ process . stdout . write = originalStdoutWrite ;
350353 } ) ;
351354
352- // Add benchmarks with one being the baseline
353- suite
354- . add ( "baseline-test" , { baseline : true } , ( ) => {
355- // Medium-speed operation
356- for ( let i = 0 ; i < 1000 ; i ++ ) { }
357- } )
358- . add ( "faster-test" , ( ) => {
359- // Faster operation
360- for ( let i = 0 ; i < 100 ; i ++ ) { }
361- } )
362- . add ( "slower-test" , ( ) => {
363- // Slower operation
364- for ( let i = 0 ; i < 10000 ; i ++ ) { }
365- } ) ;
355+ it ( "should include a summary section" , ( ) => {
356+ assert . ok ( output . includes ( "Summary (vs. baseline):" ) ) ;
357+ } ) ;
366358
367- // Run the suite
368- await suite . run ( ) ;
359+ it ( "should show 'faster' comparison in summary" , ( ) => {
360+ const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
361+ assert . ok ( summary . includes ( "faster" ) ) ;
362+ } ) ;
369363
370- process . stdout . write = originalStdoutWrite ;
364+ it ( "should show 'slower' comparison in summary" , ( ) => {
365+ const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
366+ assert . ok ( summary . includes ( "slower" ) ) ;
367+ } ) ;
371368 } ) ;
372369
373- it ( "should include a summary section" , ( ) => {
374- assert . ok ( output . includes ( "Summary (vs. baseline):" ) ) ;
375- } ) ;
370+ describe ( "for chartReport" , async ( t ) => {
371+ let output = "" ;
376372
377- it ( "should show 'faster' comparison in summary" , ( ) => {
378- const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
379- assert . ok ( summary . includes ( "faster" ) ) ;
380- } ) ;
373+ before ( async ( ) => {
374+ const originalStdoutWrite = process . stdout . write ;
375+ process . stdout . write = ( data ) => {
376+ output += data ;
377+ } ;
381378
382- it ( "should show 'slower' comparison in summary" , ( ) => {
383- const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
384- assert . ok ( summary . includes ( "slower" ) ) ;
379+ chartReport ( results ) ;
380+ process . stdout . write = originalStdoutWrite ;
381+ } ) ;
382+
383+ it ( "should include a summary section" , ( ) => {
384+ assert . ok ( output . includes ( "Summary (vs. baseline):" ) ) ;
385+ } ) ;
386+
387+ it ( "should show 'faster' comparison in summary" , ( ) => {
388+ const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
389+ assert . ok ( summary . includes ( "faster" ) ) ;
390+ } ) ;
391+
392+ it ( "should show 'slower' comparison in summary" , ( ) => {
393+ const summary = output . split ( "Summary (vs. baseline):" ) [ 1 ] ;
394+ assert . ok ( summary . includes ( "slower" ) ) ;
395+ } ) ;
385396 } ) ;
386397} ) ;
387398
0 commit comments