1- import { mockDeep , mockReset } from "jest-mock-extended" ;
2- const mockCore = mockDeep < typeof core > ( ) ;
3-
4- import * as core from "@codspeed/core" ;
51import { Bench } from "tinybench" ;
6- import { withCodSpeed } from ".." ;
2+ import { beforeEach , describe , expect , it , vi } from "vitest" ;
3+ import { withCodSpeed } from "../src" ;
74import { registerBenchmarks } from "./registerBenchmarks" ;
85import { registerOtherBenchmarks } from "./registerOtherBenchmarks" ;
96
10- jest . mock ( "@codspeed/core" , ( ) => {
11- mockCore . getGitDir = jest . requireActual ( "@codspeed/core" ) . getGitDir ;
12- return mockCore ;
7+ const mockCore = vi . hoisted ( ( ) => {
8+ return {
9+ mongoMeasurement : {
10+ start : vi . fn ( ) ,
11+ stop : vi . fn ( ) ,
12+ setupInstruments : vi . fn ( ) ,
13+ } ,
14+ Measurement : {
15+ isInstrumented : vi . fn ( ) ,
16+ startInstrumentation : vi . fn ( ) ,
17+ stopInstrumentation : vi . fn ( ) ,
18+ } ,
19+ optimizeFunction : vi
20+ . fn ( )
21+ . mockImplementation ( async ( fn : ( ) => Promise < void > ) => {
22+ await fn ( ) ;
23+ } ) ,
24+ setupCore : vi . fn ( ) ,
25+ teardownCore : vi . fn ( ) ,
26+ } ;
27+ } ) ;
28+
29+ vi . mock ( "@codspeed/core" , async ( importOriginal ) => {
30+ const actual = await importOriginal < typeof import ( "@codspeed/core" ) > ( ) ;
31+ return {
32+ ...actual ,
33+ ...mockCore ,
34+ } ;
1335} ) ;
1436
1537beforeEach ( ( ) => {
16- mockReset ( mockCore ) ;
17- jest . clearAllMocks ( ) ;
38+ vi . clearAllMocks ( ) ;
1839} ) ;
1940
2041describe ( "Benchmark.Suite" , ( ) => {
2142 it ( "simple suite" , async ( ) => {
2243 mockCore . Measurement . isInstrumented . mockReturnValue ( false ) ;
2344 const bench = withCodSpeed ( new Bench ( { time : 100 } ) ) ;
24- const onComplete = jest . fn ( ) ;
45+ const onComplete = vi . fn ( ) ;
2546 bench . add ( "RegExp" , function ( ) {
2647 / o / . test ( "Hello World!" ) ;
2748 } ) ;
@@ -87,8 +108,8 @@ describe("Benchmark.Suite", () => {
87108 it . each ( [ true , false ] ) (
88109 "check console output(instrumented=%p) " ,
89110 async ( instrumented ) => {
90- const logSpy = jest . spyOn ( console , "log" ) ;
91- const warnSpy = jest . spyOn ( console , "warn" ) ;
111+ const logSpy = vi . spyOn ( console , "log" ) ;
112+ const warnSpy = vi . spyOn ( console , "warn" ) ;
92113 mockCore . Measurement . isInstrumented . mockReturnValue ( instrumented ) ;
93114 await withCodSpeed ( new Bench ( { time : 100 } ) )
94115 . add ( "RegExp" , function ( ) {
@@ -128,8 +149,8 @@ describe("Benchmark.Suite", () => {
128149 ) ;
129150 } ) ;
130151 // TODO: this is not supported at the moment as tinybench does not support tasks with same name
131- // remove `.failing ` when tinybench supports it
132- it . failing (
152+ // remove `.fails ` when tinybench supports it
153+ it . fails (
133154 "check that benchmarks with same name have different URIs when registered in different files" ,
134155 async ( ) => {
135156 mockCore . Measurement . isInstrumented . mockReturnValue ( true ) ;
@@ -152,10 +173,10 @@ describe("Benchmark.Suite", () => {
152173 mockCore . optimizeFunction . mockImplementation ( async ( fn ) => {
153174 await fn ( ) ;
154175 } ) ;
155- const beforeAll = jest . fn ( ) ;
156- const beforeEach = jest . fn ( ) ;
157- const afterEach = jest . fn ( ) ;
158- const afterAll = jest . fn ( ) ;
176+ const beforeAll = vi . fn ( ) ;
177+ const beforeEach = vi . fn ( ) ;
178+ const afterEach = vi . fn ( ) ;
179+ const afterAll = vi . fn ( ) ;
159180
160181 await withCodSpeed ( new Bench ( ) )
161182 . add (
0 commit comments