@@ -23,7 +23,7 @@ const benchOptions: Benchmark.Options = {
23
23
24
24
describe ( "Benchmark" , ( ) => {
25
25
it ( "simple benchmark" , async ( ) => {
26
- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
26
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
27
27
const bench = withCodSpeed (
28
28
new Benchmark (
29
29
"RegExp" ,
@@ -37,11 +37,12 @@ describe("Benchmark", () => {
37
37
bench . on ( "complete" , onComplete ) ;
38
38
await bench . run ( ) ;
39
39
expect ( onComplete ) . toHaveBeenCalled ( ) ;
40
- expect ( mockCore . Measurement . startInstrumentation ) . not . toHaveBeenCalled ( ) ;
41
- expect ( mockCore . Measurement . stopInstrumentation ) . not . toHaveBeenCalled ( ) ;
40
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . not . toHaveBeenCalled ( ) ;
41
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . not . toHaveBeenCalled ( ) ;
42
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . not . toHaveBeenCalled ( ) ;
42
43
} ) ;
43
44
it ( "check core methods are called" , async ( ) => {
44
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
45
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
45
46
46
47
const bench = withCodSpeed (
47
48
new Benchmark (
@@ -56,13 +57,15 @@ describe("Benchmark", () => {
56
57
bench . on ( "complete" , onComplete ) ;
57
58
await bench . run ( ) ;
58
59
expect ( onComplete ) . toHaveBeenCalled ( ) ;
59
- expect ( mockCore . Measurement . startInstrumentation ) . toHaveBeenCalled ( ) ;
60
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
60
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . toHaveBeenCalled ( ) ;
61
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
62
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
63
+ process . pid ,
61
64
"packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExpSingle"
62
65
) ;
63
66
} ) ;
64
67
it ( "check error handling" , async ( ) => {
65
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
68
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
66
69
const bench = withCodSpeed (
67
70
new Benchmark (
68
71
"throwing" ,
@@ -79,7 +82,7 @@ describe("Benchmark", () => {
79
82
async ( instrumented ) => {
80
83
const logSpy = jest . spyOn ( console , "log" ) ;
81
84
const warnSpy = jest . spyOn ( console , "warn" ) ;
82
- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
85
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
83
86
await withCodSpeed (
84
87
new Benchmark (
85
88
"RegExpSingle" ,
@@ -108,7 +111,7 @@ describe("Benchmark", () => {
108
111
}
109
112
) ;
110
113
it ( "should call setup and teardown" , async ( ) => {
111
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
114
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
112
115
const setup = jest . fn ( ) ;
113
116
const teardown = jest . fn ( ) ;
114
117
const bench = withCodSpeed (
@@ -128,7 +131,7 @@ describe("Benchmark", () => {
128
131
129
132
describe ( "Benchmark.Suite" , ( ) => {
130
133
it ( "simple suite" , async ( ) => {
131
- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
134
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
132
135
const suite = withCodSpeed ( new Benchmark . Suite ( ) ) ;
133
136
suite . add (
134
137
"RegExp" ,
@@ -141,11 +144,12 @@ describe("Benchmark.Suite", () => {
141
144
suite . on ( "complete" , onComplete ) ;
142
145
await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
143
146
expect ( onComplete ) . toHaveBeenCalled ( ) ;
144
- expect ( mockCore . Measurement . startInstrumentation ) . not . toHaveBeenCalled ( ) ;
145
- expect ( mockCore . Measurement . stopInstrumentation ) . not . toHaveBeenCalled ( ) ;
147
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . not . toHaveBeenCalled ( ) ;
148
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . not . toHaveBeenCalled ( ) ;
149
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . not . toHaveBeenCalled ( ) ;
146
150
} ) ;
147
151
it ( "check core methods are called" , async ( ) => {
148
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
152
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
149
153
const suite = withCodSpeed ( new Benchmark . Suite ( ) ) . add (
150
154
"RegExp" ,
151
155
function ( ) {
@@ -156,13 +160,15 @@ describe("Benchmark.Suite", () => {
156
160
const onComplete = jest . fn ( ) ;
157
161
suite . on ( "complete" , onComplete ) ;
158
162
await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
159
- expect ( mockCore . Measurement . startInstrumentation ) . toHaveBeenCalled ( ) ;
160
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
163
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . toHaveBeenCalled ( ) ;
164
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
165
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
166
+ process . pid ,
161
167
"packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExp"
162
168
) ;
163
169
} ) ;
164
170
it ( "check suite name is in the uri" , async ( ) => {
165
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
171
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
166
172
await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
167
173
. add (
168
174
"RegExp" ,
@@ -175,15 +181,18 @@ describe("Benchmark.Suite", () => {
175
181
/ o / . test ( "Hello World!" ) ;
176
182
} , benchOptions )
177
183
. run ( ) ;
178
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
184
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalledTimes ( 2 ) ;
185
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
186
+ process . pid ,
179
187
"packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::RegExp"
180
188
) ;
181
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
189
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
190
+ process . pid ,
182
191
"packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::unknown_1"
183
192
) ;
184
193
} ) ;
185
194
it ( "check error handling" , async ( ) => {
186
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
195
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
187
196
const bench = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) . add (
188
197
"throwing" ,
189
198
( ) => {
@@ -197,7 +206,7 @@ describe("Benchmark.Suite", () => {
197
206
async ( instrumented ) => {
198
207
const logSpy = jest . spyOn ( console , "log" ) ;
199
208
const warnSpy = jest . spyOn ( console , "warn" ) ;
200
- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
209
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
201
210
await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
202
211
. add (
203
212
"RegExp" ,
@@ -229,35 +238,40 @@ describe("Benchmark.Suite", () => {
229
238
}
230
239
) ;
231
240
it ( "check nested file path is in the uri when bench is registered in another file" , async ( ) => {
232
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
241
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
233
242
const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
234
243
registerBenchmarks ( suite ) ;
235
244
const onComplete = jest . fn ( ) ;
236
245
suite . on ( "complete" , onComplete ) ;
237
246
await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
238
- expect ( mockCore . Measurement . startInstrumentation ) . toHaveBeenCalled ( ) ;
239
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
247
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . toHaveBeenCalled ( ) ;
248
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
249
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
250
+ process . pid ,
240
251
"packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
241
252
) ;
242
253
} ) ;
243
254
it ( "check that benchmarks with same name have different URIs when registered in different files" , async ( ) => {
244
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
255
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
245
256
const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
246
257
registerBenchmarks ( suite ) ;
247
258
registerOtherBenchmarks ( suite ) ;
248
259
const onComplete = jest . fn ( ) ;
249
260
suite . on ( "complete" , onComplete ) ;
250
261
await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
251
- expect ( mockCore . Measurement . startInstrumentation ) . toHaveBeenCalled ( ) ;
252
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
262
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . toHaveBeenCalled ( ) ;
263
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalledTimes ( 2 ) ;
264
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
265
+ process . pid ,
253
266
"packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
254
267
) ;
255
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
268
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
269
+ process . pid ,
256
270
"packages/benchmark.js-plugin/tests/registerOtherBenchmarks.ts::thesuite::RegExp"
257
271
) ;
258
272
} ) ;
259
273
it ( "should call setupCore and teardownCore only once after run()" , async ( ) => {
260
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
274
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
261
275
const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
262
276
registerBenchmarks ( suite ) ;
263
277
registerOtherBenchmarks ( suite ) ;
@@ -271,7 +285,7 @@ describe("Benchmark.Suite", () => {
271
285
expect ( mockCore . teardownCore ) . toHaveBeenCalledTimes ( 1 ) ;
272
286
} ) ;
273
287
it ( "should call setup and teardown" , async ( ) => {
274
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
288
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
275
289
const setup = jest . fn ( ) ;
276
290
const teardown = jest . fn ( ) ;
277
291
0 commit comments