@@ -15,6 +15,8 @@ jest.mock("@codspeed/core", () => {
1515beforeEach ( ( ) => {
1616 mockReset ( mockCore ) ;
1717 jest . clearAllMocks ( ) ;
18+ // Set up mock return values
19+ mockCore . InstrumentHooks . startBenchmark . mockReturnValue ( 1 ) ;
1820} ) ;
1921
2022const benchOptions : Benchmark . Options = {
@@ -23,7 +25,7 @@ const benchOptions: Benchmark.Options = {
2325
2426describe ( "Benchmark" , ( ) => {
2527 it ( "simple benchmark" , async ( ) => {
26- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
28+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
2729 const bench = withCodSpeed (
2830 new Benchmark (
2931 "RegExp" ,
@@ -37,11 +39,11 @@ describe("Benchmark", () => {
3739 bench . on ( "complete" , onComplete ) ;
3840 await bench . run ( ) ;
3941 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 ( ) ;
4244 } ) ;
4345 it ( "check core methods are called" , async ( ) => {
44- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
46+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
4547
4648 const bench = withCodSpeed (
4749 new Benchmark (
@@ -56,13 +58,15 @@ describe("Benchmark", () => {
5658 bench . on ( "complete" , onComplete ) ;
5759 await bench . run ( ) ;
5860 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 ) ,
6165 "packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExpSingle"
6266 ) ;
6367 } ) ;
6468 it ( "check error handling" , async ( ) => {
65- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
69+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
6670 const bench = withCodSpeed (
6771 new Benchmark (
6872 "throwing" ,
@@ -79,7 +83,7 @@ describe("Benchmark", () => {
7983 async ( instrumented ) => {
8084 const logSpy = jest . spyOn ( console , "log" ) ;
8185 const warnSpy = jest . spyOn ( console , "warn" ) ;
82- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
86+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
8387 await withCodSpeed (
8488 new Benchmark (
8589 "RegExpSingle" ,
@@ -108,7 +112,7 @@ describe("Benchmark", () => {
108112 }
109113 ) ;
110114 it ( "should call setup and teardown" , async ( ) => {
111- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
115+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
112116 const setup = jest . fn ( ) ;
113117 const teardown = jest . fn ( ) ;
114118 const bench = withCodSpeed (
@@ -128,7 +132,7 @@ describe("Benchmark", () => {
128132
129133describe ( "Benchmark.Suite" , ( ) => {
130134 it ( "simple suite" , async ( ) => {
131- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
135+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
132136 const suite = withCodSpeed ( new Benchmark . Suite ( ) ) ;
133137 suite . add (
134138 "RegExp" ,
@@ -141,11 +145,11 @@ describe("Benchmark.Suite", () => {
141145 suite . on ( "complete" , onComplete ) ;
142146 await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
143147 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 ( ) ;
146150 } ) ;
147151 it ( "check core methods are called" , async ( ) => {
148- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
152+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
149153 const suite = withCodSpeed ( new Benchmark . Suite ( ) ) . add (
150154 "RegExp" ,
151155 function ( ) {
@@ -156,13 +160,15 @@ describe("Benchmark.Suite", () => {
156160 const onComplete = jest . fn ( ) ;
157161 suite . on ( "complete" , onComplete ) ;
158162 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 ) ,
161167 "packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExp"
162168 ) ;
163169 } ) ;
164170 it ( "check suite name is in the uri" , async ( ) => {
165- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
171+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
166172 await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
167173 . add (
168174 "RegExp" ,
@@ -175,15 +181,19 @@ describe("Benchmark.Suite", () => {
175181 / o / . test ( "Hello World!" ) ;
176182 } , benchOptions )
177183 . run ( ) ;
178- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
184+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
185+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
186+ expect . any ( Number ) ,
179187 "packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::RegExp"
180188 ) ;
181- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
189+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
190+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
191+ expect . any ( Number ) ,
182192 "packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::unknown_1"
183193 ) ;
184194 } ) ;
185195 it ( "check error handling" , async ( ) => {
186- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
196+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
187197 const bench = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) . add (
188198 "throwing" ,
189199 ( ) => {
@@ -197,7 +207,7 @@ describe("Benchmark.Suite", () => {
197207 async ( instrumented ) => {
198208 const logSpy = jest . spyOn ( console , "log" ) ;
199209 const warnSpy = jest . spyOn ( console , "warn" ) ;
200- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
210+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
201211 await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
202212 . add (
203213 "RegExp" ,
@@ -229,35 +239,41 @@ describe("Benchmark.Suite", () => {
229239 }
230240 ) ;
231241 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 ) ;
233243 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
234244 registerBenchmarks ( suite ) ;
235245 const onComplete = jest . fn ( ) ;
236246 suite . on ( "complete" , onComplete ) ;
237247 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 ) ,
240252 "packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
241253 ) ;
242254 } ) ;
243255 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 ) ;
245257 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
246258 registerBenchmarks ( suite ) ;
247259 registerOtherBenchmarks ( suite ) ;
248260 const onComplete = jest . fn ( ) ;
249261 suite . on ( "complete" , onComplete ) ;
250262 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 ) ,
253267 "packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
254268 ) ;
255- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
269+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalled ( ) ;
270+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
271+ expect . any ( Number ) ,
256272 "packages/benchmark.js-plugin/tests/registerOtherBenchmarks.ts::thesuite::RegExp"
257273 ) ;
258274 } ) ;
259275 it ( "should call setupCore and teardownCore only once after run()" , async ( ) => {
260- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
276+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
261277 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
262278 registerBenchmarks ( suite ) ;
263279 registerOtherBenchmarks ( suite ) ;
@@ -271,7 +287,7 @@ describe("Benchmark.Suite", () => {
271287 expect ( mockCore . teardownCore ) . toHaveBeenCalledTimes ( 1 ) ;
272288 } ) ;
273289 it ( "should call setup and teardown" , async ( ) => {
274- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
290+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
275291 const setup = jest . fn ( ) ;
276292 const teardown = jest . fn ( ) ;
277293
0 commit comments