@@ -6,7 +6,7 @@ const reporter = require('../fixtures/empty-test-reporter');
66const { it } = require ( 'node:test' ) ;
77
88const bench = common . createBenchmark ( main , {
9- n : [ 100 , 1000 ] ,
9+ n : [ 1 , 10 , 100 , 1000 ] ,
1010 option : [
1111 'none' ,
1212 'skip' ,
@@ -23,72 +23,102 @@ const bench = common.createBenchmark(main, {
2323 flags : [ '--test-reporter=./benchmark/fixtures/empty-test-reporter.js' ] ,
2424} ) ;
2525
26- async function run ( { n, option } ) {
27- // eslint-disable-next-line no-unused-vars
28- let avoidV8Optimization ;
26+ const allTests = {
27+ 'none' : ( loopAmount , avoidV8Optimization ) => {
28+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
29+ it ( `${ i } ` , ( ) => {
30+ avoidV8Optimization = i ;
31+ } ) ;
32+ }
2933
30- for ( let i = 0 ; i < n ; i ++ ) {
31- switch ( option ) {
32- case 'none' :
33- it ( `${ i } ` , ( ) => {
34- avoidV8Optimization = i ;
35- } ) ;
36- break ;
37- case 'skip' :
38- it ( `${ i } ` , { skip : true } , ( ) => {
39- throw new Error ( 'This test should not run.' ) ;
40- } ) ;
41- break ;
42- case 'skip-with-message' :
43- it ( `${ i } ` , { skip : 'skip reason' } , ( ) => {
44- throw new Error ( 'This test should not run.' ) ;
45- } ) ;
46- break ;
47- case 'skip-method' :
48- it ( `${ i } ` , ( t ) => {
49- avoidV8Optimization = i ;
50- t . skip ( ) ;
51- } ) ;
52- break ;
53- case 'skip-method-with-message' :
54- it ( `${ i } ` , ( t ) => {
55- avoidV8Optimization = i ;
56- t . skip ( 'skip reason' ) ;
57- } ) ;
58- break ;
59- case 'todo' :
60- it ( `${ i } ` , { todo : true } , ( ) => {
61- avoidV8Optimization = i ;
62- } ) ;
63- break ;
64- case 'todo-with-message' :
65- it ( `${ i } ` , { todo : 'todo reason' } , ( ) => {
66- avoidV8Optimization = i ;
67- } ) ;
68- break ;
69- case 'todo-method' :
70- it ( `${ i } ` , ( t ) => {
71- avoidV8Optimization = i ;
72- t . todo ( ) ;
73- } ) ;
74- break ;
75- case 'todo-method-with-message' :
76- it ( `${ i } ` , ( t ) => {
77- avoidV8Optimization = i ;
78- t . todo ( 'todo reason' ) ;
79- } ) ;
80- break ;
34+ return finished ( reporter ) ;
35+ } ,
36+ 'skip' : ( loopAmount ) => {
37+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
38+ it ( `${ i } ` , { skip : true } , ( ) => {
39+ throw new Error ( 'This test should not run.' ) ;
40+ } ) ;
8141 }
82- }
8342
84- await finished ( reporter ) ;
85- return n ;
86- }
43+ return finished ( reporter ) ;
44+ } ,
45+ 'skip-with-message' : ( loopAmount ) => {
46+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
47+ it ( `${ i } ` , { skip : 'skip reason' } , ( ) => {
48+ throw new Error ( 'This test should not run.' ) ;
49+ } ) ;
50+ }
51+
52+ return finished ( reporter ) ;
53+ } ,
54+ 'skip-method' : ( loopAmount , avoidV8Optimization ) => {
55+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
56+ it ( `${ i } ` , ( t ) => {
57+ avoidV8Optimization = i ;
58+ t . skip ( ) ;
59+ } ) ;
60+ }
61+
62+ return finished ( reporter ) ;
63+ } ,
64+ 'skip-method-with-message' : ( loopAmount , avoidV8Optimization ) => {
65+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
66+ it ( `${ i } ` , ( t ) => {
67+ avoidV8Optimization = i ;
68+ t . skip ( 'skip reason' ) ;
69+ } ) ;
70+ }
71+
72+ return finished ( reporter ) ;
73+ } ,
74+ 'todo' : ( loopAmount , avoidV8Optimization ) => {
75+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
76+ it ( `${ i } ` , { todo : true } , ( ) => {
77+ avoidV8Optimization = i ;
78+ } ) ;
79+ }
80+
81+ return finished ( reporter ) ;
82+ } ,
83+ 'todo-with-message' : ( loopAmount , avoidV8Optimization ) => {
84+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
85+ it ( `${ i } ` , { todo : 'todo reason' } , ( ) => {
86+ avoidV8Optimization = i ;
87+ } ) ;
88+ }
89+
90+ return finished ( reporter ) ;
91+ } ,
92+ 'todo-method' : ( loopAmount , avoidV8Optimization ) => {
93+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
94+ it ( `${ i } ` , ( t ) => {
95+ avoidV8Optimization = i ;
96+ t . todo ( ) ;
97+ } ) ;
98+ }
99+
100+ return finished ( reporter ) ;
101+ } ,
102+ 'todo-method-with-message' : ( loopAmount , avoidV8Optimization ) => {
103+ for ( let i = 0 ; i < loopAmount ; i ++ ) {
104+ it ( `${ i } ` , ( t ) => {
105+ avoidV8Optimization = i ;
106+ t . todo ( 'todo reason' ) ;
107+ } ) ;
108+ }
109+
110+ return finished ( reporter ) ;
111+ } ,
112+ } ;
113+
114+ function main ( { n, option } ) {
115+ // eslint-disable-next-line prefer-const
116+ let avoidV8Optimization = 0 ;
117+ const runOption = allTests [ option ] ;
87118
88- function main ( params ) {
89119 bench . start ( ) ;
90120
91- run ( params ) . then ( ( ops ) => {
92- bench . end ( ops ) ;
121+ runOption ( n , avoidV8Optimization ) . then ( ( ) => {
122+ bench . end ( n ) ;
93123 } ) ;
94124}
0 commit comments