@@ -23,7 +23,7 @@ const benchOptions: Benchmark.Options = {
2323
2424describe ( "Benchmark" , ( ) => {
2525 it ( "simple benchmark" , async ( ) => {
26- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
26+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
2727 const bench = withCodSpeed (
2828 new Benchmark (
2929 "RegExp" ,
@@ -37,11 +37,12 @@ describe("Benchmark", () => {
3737 bench . on ( "complete" , onComplete ) ;
3838 await bench . run ( ) ;
3939 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 ( ) ;
4243 } ) ;
4344 it ( "check core methods are called" , async ( ) => {
44- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
45+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
4546
4647 const bench = withCodSpeed (
4748 new Benchmark (
@@ -56,13 +57,15 @@ describe("Benchmark", () => {
5657 bench . on ( "complete" , onComplete ) ;
5758 await bench . run ( ) ;
5859 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 ,
6164 "packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExpSingle"
6265 ) ;
6366 } ) ;
6467 it ( "check error handling" , async ( ) => {
65- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
68+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
6669 const bench = withCodSpeed (
6770 new Benchmark (
6871 "throwing" ,
@@ -79,7 +82,7 @@ describe("Benchmark", () => {
7982 async ( instrumented ) => {
8083 const logSpy = jest . spyOn ( console , "log" ) ;
8184 const warnSpy = jest . spyOn ( console , "warn" ) ;
82- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
85+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
8386 await withCodSpeed (
8487 new Benchmark (
8588 "RegExpSingle" ,
@@ -108,7 +111,7 @@ describe("Benchmark", () => {
108111 }
109112 ) ;
110113 it ( "should call setup and teardown" , async ( ) => {
111- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
114+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
112115 const setup = jest . fn ( ) ;
113116 const teardown = jest . fn ( ) ;
114117 const bench = withCodSpeed (
@@ -128,7 +131,7 @@ describe("Benchmark", () => {
128131
129132describe ( "Benchmark.Suite" , ( ) => {
130133 it ( "simple suite" , async ( ) => {
131- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
134+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
132135 const suite = withCodSpeed ( new Benchmark . Suite ( ) ) ;
133136 suite . add (
134137 "RegExp" ,
@@ -141,11 +144,12 @@ describe("Benchmark.Suite", () => {
141144 suite . on ( "complete" , onComplete ) ;
142145 await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
143146 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 ( ) ;
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+ process . pid ,
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,18 @@ describe("Benchmark.Suite", () => {
175181 / o / . test ( "Hello World!" ) ;
176182 } , benchOptions )
177183 . run ( ) ;
178- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
184+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalledTimes ( 2 ) ;
185+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
186+ process . pid ,
179187 "packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::RegExp"
180188 ) ;
181- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
189+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
190+ process . pid ,
182191 "packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::unknown_1"
183192 ) ;
184193 } ) ;
185194 it ( "check error handling" , async ( ) => {
186- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
195+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
187196 const bench = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) . add (
188197 "throwing" ,
189198 ( ) => {
@@ -197,7 +206,7 @@ describe("Benchmark.Suite", () => {
197206 async ( instrumented ) => {
198207 const logSpy = jest . spyOn ( console , "log" ) ;
199208 const warnSpy = jest . spyOn ( console , "warn" ) ;
200- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
209+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
201210 await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
202211 . add (
203212 "RegExp" ,
@@ -229,35 +238,40 @@ describe("Benchmark.Suite", () => {
229238 }
230239 ) ;
231240 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 ) ;
233242 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
234243 registerBenchmarks ( suite ) ;
235244 const onComplete = jest . fn ( ) ;
236245 suite . on ( "complete" , onComplete ) ;
237246 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 ,
240251 "packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
241252 ) ;
242253 } ) ;
243254 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 ) ;
245256 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
246257 registerBenchmarks ( suite ) ;
247258 registerOtherBenchmarks ( suite ) ;
248259 const onComplete = jest . fn ( ) ;
249260 suite . on ( "complete" , onComplete ) ;
250261 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 ,
253266 "packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
254267 ) ;
255- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
268+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
269+ process . pid ,
256270 "packages/benchmark.js-plugin/tests/registerOtherBenchmarks.ts::thesuite::RegExp"
257271 ) ;
258272 } ) ;
259273 it ( "should call setupCore and teardownCore only once after run()" , async ( ) => {
260- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
274+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
261275 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
262276 registerBenchmarks ( suite ) ;
263277 registerOtherBenchmarks ( suite ) ;
@@ -271,7 +285,7 @@ describe("Benchmark.Suite", () => {
271285 expect ( mockCore . teardownCore ) . toHaveBeenCalledTimes ( 1 ) ;
272286 } ) ;
273287 it ( "should call setup and teardown" , async ( ) => {
274- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
288+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
275289 const setup = jest . fn ( ) ;
276290 const teardown = jest . fn ( ) ;
277291
0 commit comments