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