@@ -15,6 +15,8 @@ jest.mock("@codspeed/core", () => {
15
15
beforeEach ( ( ) => {
16
16
mockReset ( mockCore ) ;
17
17
jest . clearAllMocks ( ) ;
18
+ // Set up mock return values
19
+ mockCore . InstrumentHooks . startBenchmark . mockReturnValue ( 1 ) ;
18
20
} ) ;
19
21
20
22
const benchOptions : Benchmark . Options = {
@@ -23,7 +25,7 @@ const benchOptions: Benchmark.Options = {
23
25
24
26
describe ( "Benchmark" , ( ) => {
25
27
it ( "simple benchmark" , async ( ) => {
26
- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
28
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
27
29
const bench = withCodSpeed (
28
30
new Benchmark (
29
31
"RegExp" ,
@@ -37,11 +39,11 @@ describe("Benchmark", () => {
37
39
bench . on ( "complete" , onComplete ) ;
38
40
await bench . run ( ) ;
39
41
expect ( onComplete ) . toHaveBeenCalled ( ) ;
40
- expect ( mockCore . Measurement . startInstrumentation ) . not . toHaveBeenCalled ( ) ;
41
- expect ( mockCore . Measurement . stopInstrumentation ) . not . toHaveBeenCalled ( ) ;
42
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . not . toHaveBeenCalled ( ) ;
43
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . not . toHaveBeenCalled ( ) ;
42
44
} ) ;
43
45
it ( "check core methods are called" , async ( ) => {
44
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
46
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
45
47
46
48
const bench = withCodSpeed (
47
49
new Benchmark (
@@ -56,13 +58,15 @@ describe("Benchmark", () => {
56
58
bench . on ( "complete" , onComplete ) ;
57
59
await bench . run ( ) ;
58
60
expect ( onComplete ) . toHaveBeenCalled ( ) ;
59
- expect ( mockCore . Measurement . startInstrumentation ) . toHaveBeenCalled ( ) ;
60
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
61
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . toHaveBeenCalled ( ) ;
62
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
63
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
64
+ expect . any ( Number ) ,
61
65
"packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExpSingle"
62
66
) ;
63
67
} ) ;
64
68
it ( "check error handling" , async ( ) => {
65
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
69
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
66
70
const bench = withCodSpeed (
67
71
new Benchmark (
68
72
"throwing" ,
@@ -79,7 +83,7 @@ describe("Benchmark", () => {
79
83
async ( instrumented ) => {
80
84
const logSpy = jest . spyOn ( console , "log" ) ;
81
85
const warnSpy = jest . spyOn ( console , "warn" ) ;
82
- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
86
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
83
87
await withCodSpeed (
84
88
new Benchmark (
85
89
"RegExpSingle" ,
@@ -108,7 +112,7 @@ describe("Benchmark", () => {
108
112
}
109
113
) ;
110
114
it ( "should call setup and teardown" , async ( ) => {
111
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
115
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
112
116
const setup = jest . fn ( ) ;
113
117
const teardown = jest . fn ( ) ;
114
118
const bench = withCodSpeed (
@@ -128,7 +132,7 @@ describe("Benchmark", () => {
128
132
129
133
describe ( "Benchmark.Suite" , ( ) => {
130
134
it ( "simple suite" , async ( ) => {
131
- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
135
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
132
136
const suite = withCodSpeed ( new Benchmark . Suite ( ) ) ;
133
137
suite . add (
134
138
"RegExp" ,
@@ -141,11 +145,11 @@ describe("Benchmark.Suite", () => {
141
145
suite . on ( "complete" , onComplete ) ;
142
146
await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
143
147
expect ( onComplete ) . toHaveBeenCalled ( ) ;
144
- expect ( mockCore . Measurement . startInstrumentation ) . not . toHaveBeenCalled ( ) ;
145
- expect ( mockCore . Measurement . stopInstrumentation ) . not . toHaveBeenCalled ( ) ;
148
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . not . toHaveBeenCalled ( ) ;
149
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . 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
+ expect . any ( Number ) ,
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,19 @@ 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 ) . toHaveBeenCalled ( ) ;
185
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
186
+ expect . any ( Number ) ,
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 . stopBenchmark ) . toHaveBeenCalled ( ) ;
190
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
191
+ expect . any ( Number ) ,
182
192
"packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::unknown_1"
183
193
) ;
184
194
} ) ;
185
195
it ( "check error handling" , async ( ) => {
186
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
196
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
187
197
const bench = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) . add (
188
198
"throwing" ,
189
199
( ) => {
@@ -197,7 +207,7 @@ describe("Benchmark.Suite", () => {
197
207
async ( instrumented ) => {
198
208
const logSpy = jest . spyOn ( console , "log" ) ;
199
209
const warnSpy = jest . spyOn ( console , "warn" ) ;
200
- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
210
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
201
211
await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
202
212
. add (
203
213
"RegExp" ,
@@ -229,35 +239,41 @@ describe("Benchmark.Suite", () => {
229
239
}
230
240
) ;
231
241
it ( "check nested file path is in the uri when bench is registered in another file" , async ( ) => {
232
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
242
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
233
243
const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
234
244
registerBenchmarks ( suite ) ;
235
245
const onComplete = jest . fn ( ) ;
236
246
suite . on ( "complete" , onComplete ) ;
237
247
await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
238
- expect ( mockCore . Measurement . startInstrumentation ) . toHaveBeenCalled ( ) ;
239
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
248
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . toHaveBeenCalled ( ) ;
249
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
250
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
251
+ expect . any ( Number ) ,
240
252
"packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
241
253
) ;
242
254
} ) ;
243
255
it ( "check that benchmarks with same name have different URIs when registered in different files" , async ( ) => {
244
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
256
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
245
257
const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
246
258
registerBenchmarks ( suite ) ;
247
259
registerOtherBenchmarks ( suite ) ;
248
260
const onComplete = jest . fn ( ) ;
249
261
suite . on ( "complete" , onComplete ) ;
250
262
await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
251
- expect ( mockCore . Measurement . startInstrumentation ) . toHaveBeenCalled ( ) ;
252
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
263
+ expect ( mockCore . InstrumentHooks . startBenchmark ) . toHaveBeenCalled ( ) ;
264
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
265
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
266
+ expect . any ( Number ) ,
253
267
"packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
254
268
) ;
255
- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
269
+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
270
+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
271
+ expect . any ( Number ) ,
256
272
"packages/benchmark.js-plugin/tests/registerOtherBenchmarks.ts::thesuite::RegExp"
257
273
) ;
258
274
} ) ;
259
275
it ( "should call setupCore and teardownCore only once after run()" , async ( ) => {
260
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
276
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
261
277
const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
262
278
registerBenchmarks ( suite ) ;
263
279
registerOtherBenchmarks ( suite ) ;
@@ -271,7 +287,7 @@ describe("Benchmark.Suite", () => {
271
287
expect ( mockCore . teardownCore ) . toHaveBeenCalledTimes ( 1 ) ;
272
288
} ) ;
273
289
it ( "should call setup and teardown" , async ( ) => {
274
- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
290
+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
275
291
const setup = jest . fn ( ) ;
276
292
const teardown = jest . fn ( ) ;
277
293
0 commit comments