@@ -10,6 +10,21 @@ const coreMocks = vi.hoisted(() => {
1010 } ;
1111} ) ;
1212
13+ const fsMocks = vi . hoisted ( ( ) => {
14+ let mockVersion = "4.0.18" ; // default to v4
15+ return {
16+ readFileSync : vi . fn ( ( path : string ) => {
17+ if ( path . includes ( "vitest/package.json" ) ) {
18+ return JSON . stringify ( { version : mockVersion } ) ;
19+ }
20+ throw new Error ( `File not found: ${ path } ` ) ;
21+ } ) ,
22+ setMockVersion : ( version : string ) => {
23+ mockVersion = version ;
24+ } ,
25+ } ;
26+ } ) ;
27+
1328const resolvedCodSpeedPlugin = codspeedPlugin ( ) ;
1429const applyPluginFunction = resolvedCodSpeedPlugin . apply ;
1530if ( typeof applyPluginFunction !== "function" )
@@ -20,6 +35,12 @@ vi.mock("@codspeed/core", async (importOriginal) => {
2035 return { ...mod , ...coreMocks } ;
2136} ) ;
2237
38+ vi . mock ( "fs" , ( ) => {
39+ return {
40+ readFileSync : fsMocks . readFileSync ,
41+ } ;
42+ } ) ;
43+
2344console . warn = vi . fn ( ) ;
2445
2546describe ( "codSpeedPlugin" , ( ) => {
@@ -79,12 +100,51 @@ describe("codSpeedPlugin", () => {
79100 } ) ;
80101 } ) ;
81102
82- it ( "should apply the codspeed config" , async ( ) => {
103+ it ( "should apply the codspeed config for v4" , ( ) => {
83104 const config = resolvedCodSpeedPlugin . config ;
84105 if ( typeof config !== "function" )
85106 throw new Error ( "config is not a function" ) ;
86107
87- expect ( config . call ( { } as never , { } , fromPartial ( { } ) ) ) . toStrictEqual ( {
108+ const result = config . call ( { } as never , { } , fromPartial ( { } ) ) ;
109+
110+ expect ( result ) . toStrictEqual ( {
111+ test : {
112+ globalSetup : [
113+ expect . stringContaining ( "packages/vitest-plugin/src/globalSetup.ts" ) ,
114+ ] ,
115+ pool : "forks" ,
116+ execArgv : [
117+ "--interpreted-frames-native-stack" ,
118+ "--allow-natives-syntax" ,
119+ "--hash-seed=1" ,
120+ "--random-seed=1" ,
121+ "--no-opt" ,
122+ "--predictable" ,
123+ "--predictable-gc-schedule" ,
124+ "--expose-gc" ,
125+ "--no-concurrent-sweeping" ,
126+ "--max-old-space-size=4096" ,
127+ ] ,
128+ runner : expect . stringContaining (
129+ "packages/vitest-plugin/src/simulation.ts"
130+ ) ,
131+ } ,
132+ } ) ;
133+ } ) ;
134+
135+ it ( "should apply the codspeed config for v3 with poolOptions" , ( ) => {
136+ // Set mock version to v3
137+ fsMocks . setMockVersion ( "3.2.0" ) ;
138+
139+ // Create a new plugin instance to pick up the mocked version
140+ const v3Plugin = codspeedPlugin ( ) ;
141+ const config = v3Plugin . config ;
142+ if ( typeof config !== "function" )
143+ throw new Error ( "config is not a function" ) ;
144+
145+ const result = config . call ( { } as never , { } , fromPartial ( { } ) ) ;
146+
147+ expect ( result ) . toStrictEqual ( {
88148 test : {
89149 globalSetup : [
90150 expect . stringContaining ( "packages/vitest-plugin/src/globalSetup.ts" ) ,
@@ -111,5 +171,8 @@ describe("codSpeedPlugin", () => {
111171 ) ,
112172 } ,
113173 } ) ;
174+
175+ // Reset mock version back to v4
176+ fsMocks . setMockVersion ( "4.0.18" ) ;
114177 } ) ;
115178} ) ;
0 commit comments