@@ -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,14 @@ 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 (
43+ mockCore . InstrumentHooks . setExecutedBenchmark
44+ ) . not . toHaveBeenCalled ( ) ;
4245 } ) ;
4346 it ( "check core methods are called" , async ( ) => {
44- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
47+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
4548
4649 const bench = withCodSpeed (
4750 new Benchmark (
@@ -56,13 +59,15 @@ describe("Benchmark", () => {
5659 bench . on ( "complete" , onComplete ) ;
5760 await bench . run ( ) ;
5861 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 ,
6166 "packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExpSingle"
6267 ) ;
6368 } ) ;
6469 it ( "check error handling" , async ( ) => {
65- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
70+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
6671 const bench = withCodSpeed (
6772 new Benchmark (
6873 "throwing" ,
@@ -79,7 +84,7 @@ describe("Benchmark", () => {
7984 async ( instrumented ) => {
8085 const logSpy = jest . spyOn ( console , "log" ) ;
8186 const warnSpy = jest . spyOn ( console , "warn" ) ;
82- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
87+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
8388 await withCodSpeed (
8489 new Benchmark (
8590 "RegExpSingle" ,
@@ -108,7 +113,7 @@ describe("Benchmark", () => {
108113 }
109114 ) ;
110115 it ( "should call setup and teardown" , async ( ) => {
111- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
116+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
112117 const setup = jest . fn ( ) ;
113118 const teardown = jest . fn ( ) ;
114119 const bench = withCodSpeed (
@@ -128,7 +133,7 @@ describe("Benchmark", () => {
128133
129134describe ( "Benchmark.Suite" , ( ) => {
130135 it ( "simple suite" , async ( ) => {
131- mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
136+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( false ) ;
132137 const suite = withCodSpeed ( new Benchmark . Suite ( ) ) ;
133138 suite . add (
134139 "RegExp" ,
@@ -141,11 +146,14 @@ describe("Benchmark.Suite", () => {
141146 suite . on ( "complete" , onComplete ) ;
142147 await suite . run ( { maxTime : 0.1 , initCount : 1 } ) ;
143148 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 ( ) ;
146154 } ) ;
147155 it ( "check core methods are called" , async ( ) => {
148- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
156+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
149157 const suite = withCodSpeed ( new Benchmark . Suite ( ) ) . add (
150158 "RegExp" ,
151159 function ( ) {
@@ -156,13 +164,15 @@ describe("Benchmark.Suite", () => {
156164 const onComplete = jest . fn ( ) ;
157165 suite . on ( "complete" , onComplete ) ;
158166 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 ,
161171 "packages/benchmark.js-plugin/tests/index.integ.test.ts::RegExp"
162172 ) ;
163173 } ) ;
164174 it ( "check suite name is in the uri" , async ( ) => {
165- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
175+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
166176 await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
167177 . add (
168178 "RegExp" ,
@@ -175,15 +185,18 @@ describe("Benchmark.Suite", () => {
175185 / o / . test ( "Hello World!" ) ;
176186 } , benchOptions )
177187 . run ( ) ;
178- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
188+ expect ( mockCore . InstrumentHooks . stopBenchmark ) . toHaveBeenCalledTimes ( 2 ) ;
189+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
190+ process . pid ,
179191 "packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::RegExp"
180192 ) ;
181- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
193+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
194+ process . pid ,
182195 "packages/benchmark.js-plugin/tests/index.integ.test.ts::thesuite::unknown_1"
183196 ) ;
184197 } ) ;
185198 it ( "check error handling" , async ( ) => {
186- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
199+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
187200 const bench = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) . add (
188201 "throwing" ,
189202 ( ) => {
@@ -197,7 +210,7 @@ describe("Benchmark.Suite", () => {
197210 async ( instrumented ) => {
198211 const logSpy = jest . spyOn ( console , "log" ) ;
199212 const warnSpy = jest . spyOn ( console , "warn" ) ;
200- mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
213+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( instrumented ) ;
201214 await withCodSpeed ( new Benchmark . Suite ( "thesuite" ) )
202215 . add (
203216 "RegExp" ,
@@ -229,35 +242,40 @@ describe("Benchmark.Suite", () => {
229242 }
230243 ) ;
231244 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 ) ;
233246 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
234247 registerBenchmarks ( suite ) ;
235248 const onComplete = jest . fn ( ) ;
236249 suite . on ( "complete" , onComplete ) ;
237250 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 ,
240255 "packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
241256 ) ;
242257 } ) ;
243258 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 ) ;
245260 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
246261 registerBenchmarks ( suite ) ;
247262 registerOtherBenchmarks ( suite ) ;
248263 const onComplete = jest . fn ( ) ;
249264 suite . on ( "complete" , onComplete ) ;
250265 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 ,
253270 "packages/benchmark.js-plugin/tests/registerBenchmarks.ts::thesuite::RegExp"
254271 ) ;
255- expect ( mockCore . Measurement . stopInstrumentation ) . toHaveBeenCalledWith (
272+ expect ( mockCore . InstrumentHooks . setExecutedBenchmark ) . toHaveBeenCalledWith (
273+ process . pid ,
256274 "packages/benchmark.js-plugin/tests/registerOtherBenchmarks.ts::thesuite::RegExp"
257275 ) ;
258276 } ) ;
259277 it ( "should call setupCore and teardownCore only once after run()" , async ( ) => {
260- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
278+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
261279 const suite = withCodSpeed ( new Benchmark . Suite ( "thesuite" ) ) ;
262280 registerBenchmarks ( suite ) ;
263281 registerOtherBenchmarks ( suite ) ;
@@ -271,7 +289,7 @@ describe("Benchmark.Suite", () => {
271289 expect ( mockCore . teardownCore ) . toHaveBeenCalledTimes ( 1 ) ;
272290 } ) ;
273291 it ( "should call setup and teardown" , async ( ) => {
274- mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
292+ mockCore . InstrumentHooks . isInstrumented . mockReturnValue ( true ) ;
275293 const setup = jest . fn ( ) ;
276294 const teardown = jest . fn ( ) ;
277295
0 commit comments