@@ -14,143 +14,145 @@ const {
1414
1515const { analyze } = require ( "../lib/utils/analyze.js" ) ;
1616
17- describe ( "chartReport outputs benchmark results as a bar chart" , async ( t ) => {
18- let output = "" ;
17+ describe ( "chartReport" , ( ) => {
18+ describe ( "outputs benchmark results as a bar chart" , async ( t ) => {
19+ let output = "" ;
1920
20- before ( async ( ) => {
21- const originalStdoutWrite = process . stdout . write ;
22- process . stdout . write = ( data ) => {
23- output += data ;
24- } ;
21+ before ( async ( ) => {
22+ const originalStdoutWrite = process . stdout . write ;
23+ process . stdout . write = ( data ) => {
24+ output += data ;
25+ } ;
2526
26- const suite = new Suite ( {
27- reporter : chartReport ,
27+ const suite = new Suite ( {
28+ reporter : chartReport ,
29+ } ) ;
30+
31+ suite
32+ . add ( "single with matcher" , ( ) => {
33+ const pattern = / [ 1 2 3 ] / g;
34+ const replacements = { 1 : "a" , 2 : "b" , 3 : "c" } ;
35+ const subject = "123123123123123123123123123123123123123123123123" ;
36+ const r = subject . replace ( pattern , ( m ) => replacements [ m ] ) ;
37+ assert . ok ( r ) ;
38+ } )
39+ . add ( "multiple replaces" , ( ) => {
40+ const subject = "123123123123123123123123123123123123123123123123" ;
41+ const r = subject
42+ . replace ( / 1 / g, "a" )
43+ . replace ( / 2 / g, "b" )
44+ . replace ( / 3 / g, "c" ) ;
45+ assert . ok ( r ) ;
46+ } ) ;
47+ await suite . run ( ) ;
48+
49+ process . stdout . write = originalStdoutWrite ;
2850 } ) ;
2951
30- suite
31- . add ( "single with matcher" , ( ) => {
32- const pattern = / [ 1 2 3 ] / g;
33- const replacements = { 1 : "a" , 2 : "b" , 3 : "c" } ;
34- const subject = "123123123123123123123123123123123123123123123123" ;
35- const r = subject . replace ( pattern , ( m ) => replacements [ m ] ) ;
36- assert . ok ( r ) ;
37- } )
38- . add ( "multiple replaces" , ( ) => {
39- const subject = "123123123123123123123123123123123123123123123123" ;
40- const r = subject
41- . replace ( / 1 / g, "a" )
42- . replace ( / 2 / g, "b" )
43- . replace ( / 3 / g, "c" ) ;
44- assert . ok ( r ) ;
45- } ) ;
46- await suite . run ( ) ;
52+ it ( "should include bar chart chars" , ( ) => {
53+ assert . ok ( output . includes ( "█" ) ) ;
54+ } ) ;
4755
48- process . stdout . write = originalStdoutWrite ;
49- } ) ;
56+ it ( "should include ops/sec" , ( ) => {
57+ assert . ok ( output . includes ( "ops/sec" ) ) ;
58+ } ) ;
5059
51- it ( "should include bar chart chars" , ( ) => {
52- assert . ok ( output . includes ( "█" ) ) ;
53- } ) ;
60+ it ( "should include benchmark names" , ( ) => {
61+ assert . ok ( output . includes ( "single with matcher" ) ) ;
62+ assert . ok ( output . includes ( "multiple replaces" ) ) ;
63+ } ) ;
5464
55- it ( "should include ops/sec " , ( ) => {
56- assert . ok ( output . includes ( "ops/sec " ) ) ;
57- } ) ;
65+ it ( "should include sample count " , ( ) => {
66+ assert . ok ( output . includes ( "samples " ) ) ;
67+ } ) ;
5868
59- it ( "should include benchmark names" , ( ) => {
60- assert . ok ( output . includes ( "single with matcher" ) ) ;
61- assert . ok ( output . includes ( "multiple replaces" ) ) ;
62- } ) ;
69+ it ( "should include Node.js version" , ( ) => {
70+ const regex = / N o d e \. j s v e r s i o n : v \d + \. \d + \. \d + / ;
6371
64- it ( "should include sample count" , ( ) => {
65- assert . ok ( output . includes ( "samples" ) ) ;
72+ assert . ok ( output . match ( regex ) ) ;
73+ } ) ;
6674 } ) ;
6775
68- it ( "should include Node.js version" , ( ) => {
69- const regex = / N o d e \. j s v e r s i o n : v \d + \. \d + \. \d + / ;
76+ describe ( "respects reporterOptions.printHeader" , async ( t ) => {
77+ let outputWithHeader = "" ;
78+ let outputWithoutHeader = "" ;
7079
71- assert . ok ( output . match ( regex ) ) ;
72- } ) ;
73- } ) ;
80+ before ( async ( ) => {
81+ const originalStdoutWrite = process . stdout . write ;
7482
75- describe ( "chartReport respects reporterOptions.printHeader" , async ( t ) => {
76- let outputWithHeader = "" ;
77- let outputWithoutHeader = "" ;
83+ // Test with default settings (printHeader: true)
84+ process . stdout . write = ( data ) => {
85+ outputWithHeader += data ;
86+ } ;
7887
79- before ( async ( ) => {
80- const originalStdoutWrite = process . stdout . write ;
88+ const suiteWithHeader = new Suite ( {
89+ reporter : chartReport ,
90+ reporterOptions : {
91+ printHeader : true ,
92+ } ,
93+ } ) ;
8194
82- // Test with default settings (printHeader: true)
83- process . stdout . write = ( data ) => {
84- outputWithHeader += data ;
85- } ;
95+ suiteWithHeader . add ( "test benchmark" , ( ) => {
96+ const a = 1 + 1 ;
97+ assert . strictEqual ( a , 2 ) ;
98+ } ) ;
99+ await suiteWithHeader . run ( ) ;
86100
87- const suiteWithHeader = new Suite ( {
88- reporter : chartReport ,
89- reporterOptions : {
90- printHeader : true ,
91- } ,
92- } ) ;
101+ // Test with printHeader: false
102+ outputWithoutHeader = "" ;
103+ process . stdout . write = ( data ) => {
104+ outputWithoutHeader += data ;
105+ } ;
93106
94- suiteWithHeader . add ( "test benchmark" , ( ) => {
95- const a = 1 + 1 ;
96- assert . strictEqual ( a , 2 ) ;
97- } ) ;
98- await suiteWithHeader . run ( ) ;
107+ const suiteWithoutHeader = new Suite ( {
108+ reporter : chartReport ,
109+ reporterOptions : {
110+ printHeader : false ,
111+ } ,
112+ } ) ;
99113
100- // Test with printHeader: false
101- outputWithoutHeader = "" ;
102- process . stdout . write = ( data ) => {
103- outputWithoutHeader += data ;
104- } ;
114+ suiteWithoutHeader . add ( "test benchmark" , ( ) => {
115+ const a = 1 + 1 ;
116+ assert . strictEqual ( a , 2 ) ;
117+ } ) ;
118+ await suiteWithoutHeader . run ( ) ;
105119
106- const suiteWithoutHeader = new Suite ( {
107- reporter : chartReport ,
108- reporterOptions : {
109- printHeader : false ,
110- } ,
120+ process . stdout . write = originalStdoutWrite ;
111121 } ) ;
112122
113- suiteWithoutHeader . add ( "test benchmark ", ( ) => {
114- const a = 1 + 1 ;
115- assert . strictEqual ( a , 2 ) ;
123+ it ( "should include Node.js version when printHeader is true ", ( ) => {
124+ const regex = / N o d e \. j s v e r s i o n : v \d + \. \d + \. \d + / ;
125+ assert . ok ( outputWithHeader . match ( regex ) ) ;
116126 } ) ;
117- await suiteWithoutHeader . run ( ) ;
118127
119- process . stdout . write = originalStdoutWrite ;
120- } ) ;
121-
122- it ( "should include Node.js version when printHeader is true" , ( ) => {
123- const regex = / N o d e \. j s v e r s i o n : v \d + \. \d + \. \d + / ;
124- assert . ok ( outputWithHeader . match ( regex ) ) ;
125- } ) ;
126-
127- it ( "should include Platform when printHeader is true" , ( ) => {
128- assert . ok ( outputWithHeader . includes ( "Platform:" ) ) ;
129- } ) ;
128+ it ( "should include Platform when printHeader is true" , ( ) => {
129+ assert . ok ( outputWithHeader . includes ( "Platform:" ) ) ;
130+ } ) ;
130131
131- it ( "should include CPU Cores when printHeader is true" , ( ) => {
132- assert . ok ( outputWithHeader . includes ( "CPU Cores:" ) ) ;
133- } ) ;
132+ it ( "should include CPU Cores when printHeader is true" , ( ) => {
133+ assert . ok ( outputWithHeader . includes ( "CPU Cores:" ) ) ;
134+ } ) ;
134135
135- it ( "should NOT include Node.js version when printHeader is false" , ( ) => {
136- const regex = / N o d e \. j s v e r s i o n : v \d + \. \d + \. \d + / ;
137- assert . ok ( ! outputWithoutHeader . match ( regex ) ) ;
138- } ) ;
136+ it ( "should NOT include Node.js version when printHeader is false" , ( ) => {
137+ const regex = / N o d e \. j s v e r s i o n : v \d + \. \d + \. \d + / ;
138+ assert . ok ( ! outputWithoutHeader . match ( regex ) ) ;
139+ } ) ;
139140
140- it ( "should NOT include Platform when printHeader is false" , ( ) => {
141- assert . ok ( ! outputWithoutHeader . includes ( "Platform:" ) ) ;
142- } ) ;
141+ it ( "should NOT include Platform when printHeader is false" , ( ) => {
142+ assert . ok ( ! outputWithoutHeader . includes ( "Platform:" ) ) ;
143+ } ) ;
143144
144- it ( "should NOT include CPU Cores when printHeader is false" , ( ) => {
145- assert . ok ( ! outputWithoutHeader . includes ( "CPU Cores:" ) ) ;
146- } ) ;
145+ it ( "should NOT include CPU Cores when printHeader is false" , ( ) => {
146+ assert . ok ( ! outputWithoutHeader . includes ( "CPU Cores:" ) ) ;
147+ } ) ;
147148
148- it ( "should still include benchmark data with or without header" , ( ) => {
149- // Both outputs should still have benchmark bars and results
150- assert . ok ( outputWithHeader . includes ( "█" ) ) ;
151- assert . ok ( outputWithoutHeader . includes ( "█" ) ) ;
152- assert . ok ( outputWithHeader . includes ( "test benchmark" ) ) ;
153- assert . ok ( outputWithoutHeader . includes ( "test benchmark" ) ) ;
149+ it ( "should still include benchmark data with or without header" , ( ) => {
150+ // Both outputs should still have benchmark bars and results
151+ assert . ok ( outputWithHeader . includes ( "█" ) ) ;
152+ assert . ok ( outputWithoutHeader . includes ( "█" ) ) ;
153+ assert . ok ( outputWithHeader . includes ( "test benchmark" ) ) ;
154+ assert . ok ( outputWithoutHeader . includes ( "test benchmark" ) ) ;
155+ } ) ;
154156 } ) ;
155157} ) ;
156158
0 commit comments