@@ -57,19 +57,27 @@ function suiteFilePath() {
57
57
return filePath ;
58
58
}
59
59
60
- /**
61
- * Run a benchmarking task, i.e. a single operation whose performance to measure.
62
- */
63
- export function task ( description : string , operation : Task [ 'operation' ] ) {
60
+ export function describe ( suiteName : string , suiteFn : ( ) => void ) {
64
61
const filePath = suiteFilePath ( ) ;
65
62
66
- suites [ filePath ] ||= { hooks : { } , tasks : [ ] } ;
67
- suites [ filePath ] . tasks . push ( { description, operation } ) ;
63
+ suites [ filePath ] = { name : suiteName , hooks : { } , tasks : [ ] } ;
64
+
65
+ suiteFn ( ) ;
68
66
}
69
67
68
+ export function task ( taskName : string , operation : Task [ 'operation' ] ) {
69
+ const filePath = suiteFilePath ( ) ;
70
+
71
+ suites [ filePath ] . tasks . push ( {
72
+ description : suites [ filePath ] . name + ' ' + taskName ,
73
+ operation,
74
+ } ) ;
75
+ }
76
+
77
+ // @TODO : Rename next two utils to dismbiguate?
78
+
70
79
/**
71
- * Setup step to run once before each benchmarking task in a suite.
72
- * Only one `beforeEach` is allowed per suite.
80
+ * Setup step to run once before all iterations of each benchmarking task in a suite.
73
81
*/
74
82
export function beforeEach ( fn : Callback ) {
75
83
const filePath = suiteFilePath ( ) ;
@@ -78,13 +86,11 @@ export function beforeEach(fn: Callback) {
78
86
throw new DuplicateHookError ( 'beforeEach' , filePath ) ;
79
87
}
80
88
81
- suites [ filePath ] ||= { hooks : { } , tasks : [ ] } ;
82
89
suites [ filePath ] . hooks . beforeEach = fn ;
83
90
}
84
91
85
92
/**
86
- * Teardown step to run once after each benchmarking task in a suite.
87
- * Only one `afterEach` is allowed per suite.
93
+ * Teardown step to run once after all iterations of each benchmarking task in a suite.
88
94
*/
89
95
export function afterEach ( fn : Callback ) {
90
96
const filePath = suiteFilePath ( ) ;
@@ -93,6 +99,5 @@ export function afterEach(fn: Callback) {
93
99
throw new DuplicateHookError ( 'afterEach' , filePath ) ;
94
100
}
95
101
96
- suites [ filePath ] ||= { hooks : { } , tasks : [ ] } ;
97
102
suites [ filePath ] . hooks . afterEach = fn ;
98
103
}
0 commit comments