@@ -41,6 +41,10 @@ describe('source_map_utils', () => {
4141 // Helper function to run tests with Windows path behavior
4242 const withWindowsPaths = async ( testFn : ( sourceMapUtils : typeof source_map_utils ) => Promise < void > | void ) => {
4343 vi . resetModules ( )
44+ global . Cypress = {
45+ config : vi . fn ( ) . mockReturnValue ( 'win32' ) ,
46+ }
47+
4448 const pathMock = await vi . importActual < typeof import ( 'path' ) > ( 'path' )
4549
4650 vi . doMock ( 'path' , ( ) => {
@@ -63,6 +67,10 @@ describe('source_map_utils', () => {
6367
6468 const withLinuxPaths = async ( testFn : ( sourceMapUtils : typeof source_map_utils ) => Promise < void > | void ) => {
6569 vi . resetModules ( )
70+ global . Cypress = {
71+ config : vi . fn ( ) . mockReturnValue ( 'linux' ) ,
72+ }
73+
6674 const pathMock = await vi . importActual < typeof import ( 'path' ) > ( 'path' )
6775
6876 vi . doMock ( 'path' , ( ) => {
@@ -73,11 +81,19 @@ describe('source_map_utils', () => {
7381 win32 : pathMock . win32 ,
7482 }
7583 } )
84+
85+ // Re-import the module to get the mocked path
86+ const { default : sourceMapUtils } = await import ( '../../../src/cypress/source_map_utils' )
87+
88+ await testFn ( sourceMapUtils )
89+
90+ // Clean up the mock
91+ vi . doUnmock ( 'path' )
7692 }
7793
7894 describe ( 'areSourceMapsAvailable' , ( ) => {
79- it ( 'should return false when no source map consumers exist' , ( ) => {
80- withLinuxPaths ( async ( sourceMapUtils ) => {
95+ it ( 'should return false when no source map consumers exist' , async ( ) => {
96+ await withLinuxPaths ( async ( sourceMapUtils ) => {
8197 const result = sourceMapUtils . areSourceMapsAvailable ( )
8298
8399 expect ( result ) . toBe ( false )
@@ -95,7 +111,7 @@ describe('source_map_utils', () => {
95111 } )
96112
97113 it ( 'should return true when multiple source map consumers exist' , async ( ) => {
98- withLinuxPaths ( async ( sourceMapUtils ) => {
114+ await withLinuxPaths ( async ( sourceMapUtils ) => {
99115 await setupSourceMapConsumer ( sourceMapUtils , '/project1/test1.spec.js' , [ 'src/components/Button.tsx' ] )
100116 await setupSourceMapConsumer ( sourceMapUtils , '/project2/test2.spec.js' , [ 'src/utils/helper.js' ] )
101117
@@ -107,8 +123,8 @@ describe('source_map_utils', () => {
107123 } )
108124
109125 describe ( 'getBaseDirectory' , ( ) => {
110- it ( 'should return the base directory when relative path matches absolute path' , ( ) => {
111- withLinuxPaths ( async ( sourceMapUtils ) => {
126+ it ( 'should return the base directory when relative path matches absolute path' , async ( ) => {
127+ await withLinuxPaths ( async ( sourceMapUtils ) => {
112128 const absolutePath = '/project/src/components/Button.tsx'
113129 const relativePath = 'src/components/Button.tsx'
114130
@@ -118,8 +134,8 @@ describe('source_map_utils', () => {
118134 } )
119135 } )
120136
121- it ( 'should return the base directory for nested paths' , ( ) => {
122- withLinuxPaths ( async ( sourceMapUtils ) => {
137+ it ( 'should return the base directory for nested paths' , async ( ) => {
138+ await withLinuxPaths ( async ( sourceMapUtils ) => {
123139 const absolutePath = '/home/user/project/lib/utils/helper.js'
124140 const relativePath = 'lib/utils/helper.js'
125141
@@ -140,8 +156,8 @@ describe('source_map_utils', () => {
140156 } )
141157 } )
142158
143- it ( 'should return null when relative path does not match absolute path' , ( ) => {
144- withLinuxPaths ( async ( sourceMapUtils ) => {
159+ it ( 'should return null when relative path does not match absolute path' , async ( ) => {
160+ await withLinuxPaths ( async ( sourceMapUtils ) => {
145161 const absolutePath = '/project/src/components/Button.tsx'
146162 const relativePath = 'different/path/Button.tsx'
147163
@@ -151,8 +167,8 @@ describe('source_map_utils', () => {
151167 } )
152168 } )
153169
154- it ( 'should return null when absolute path is shorter than relative path' , ( ) => {
155- withLinuxPaths ( async ( sourceMapUtils ) => {
170+ it ( 'should return null when absolute path is shorter than relative path' , async ( ) => {
171+ await withLinuxPaths ( async ( sourceMapUtils ) => {
156172 const absolutePath = '/project/Button.tsx'
157173 const relativePath = 'src/components/Button.tsx'
158174
@@ -162,8 +178,8 @@ describe('source_map_utils', () => {
162178 } )
163179 } )
164180
165- it ( 'should handle root directory paths' , ( ) => {
166- withLinuxPaths ( async ( sourceMapUtils ) => {
181+ it ( 'should handle root directory paths' , async ( ) => {
182+ await withLinuxPaths ( async ( sourceMapUtils ) => {
167183 const absolutePath = '/Button.tsx'
168184 const relativePath = 'Button.tsx'
169185
@@ -173,8 +189,8 @@ describe('source_map_utils', () => {
173189 } )
174190 } )
175191
176- it ( 'should handle empty relative path' , ( ) => {
177- withLinuxPaths ( async ( sourceMapUtils ) => {
192+ it ( 'should handle empty relative path' , async ( ) => {
193+ await withLinuxPaths ( async ( sourceMapUtils ) => {
178194 const absolutePath = '/project/src/components/Button.tsx'
179195 const relativePath = ''
180196
@@ -184,27 +200,27 @@ describe('source_map_utils', () => {
184200 } )
185201 } )
186202
187- it ( 'should handle identical absolute and relative paths' , ( ) => {
188- withLinuxPaths ( async ( sourceMapUtils ) => {
203+ it ( 'should handle identical absolute and relative paths' , async ( ) => {
204+ await withLinuxPaths ( async ( sourceMapUtils ) => {
189205 const absolutePath = '/project/src/components/Button.tsx'
190206 const relativePath = '/project/src/components/Button.tsx'
191207
192208 const result = sourceMapUtils . getBaseDirectory ( absolutePath , relativePath )
193209
194- expect ( result ) . toBe ( '/project/src/components ' )
210+ expect ( result ) . toBe ( '/' )
195211 } )
196212 } )
197213 } )
198214
199215 describe ( 'setSourceMapProjectRoot' , ( ) => {
200216 it ( 'should return the base directory when source map consumer exists and path matches' , async ( ) => {
201- withLinuxPaths ( async ( sourceMapUtils ) => {
217+ await withLinuxPaths ( async ( sourceMapUtils ) => {
202218 await setupSourceMapConsumer ( sourceMapUtils , '/project/cypress/integration/test.spec.js' , [ 'src/components/Button.tsx' ] )
203219
204220 const relativePath = 'cypress/integration/test.spec.js'
205221 const absolutePath = '/project/src/components/Button.tsx'
206222
207- sourceMapUtils . setSourceMapProjectRoot ( relativePath , absolutePath , '' )
223+ sourceMapUtils . setSourceMapProjectRoot ( relativePath , absolutePath , 'project-root ' )
208224
209225 const result = sourceMapUtils . getSourceMapProjectRoot ( )
210226
@@ -213,7 +229,7 @@ describe('source_map_utils', () => {
213229 } )
214230
215231 it ( 'should return project root when no source map consumer exists for the relative path' , async ( ) => {
216- withLinuxPaths ( async ( sourceMapUtils ) => {
232+ await withLinuxPaths ( async ( sourceMapUtils ) => {
217233 await setupSourceMapConsumer ( sourceMapUtils , '/project/cypress/integration/test.spec.js' , [ 'src/components/Button.tsx' ] )
218234
219235 const relativePath = 'cypress/integration/nonexistent.spec.js'
@@ -228,7 +244,7 @@ describe('source_map_utils', () => {
228244 } )
229245
230246 it ( 'should return project root when absolute path does not match any source in the consumer' , async ( ) => {
231- withLinuxPaths ( async ( sourceMapUtils ) => {
247+ await withLinuxPaths ( async ( sourceMapUtils ) => {
232248 await setupSourceMapConsumer ( sourceMapUtils , '/project/cypress/integration/test.spec.js' , [ 'src/components/Button.tsx' ] )
233249
234250 const relativePath = 'cypress/integration/test.spec.js'
@@ -243,7 +259,7 @@ describe('source_map_utils', () => {
243259 } )
244260
245261 it ( 'should handle multiple source map consumers and find the correct one' , async ( ) => {
246- withLinuxPaths ( async ( sourceMapUtils ) => {
262+ await withLinuxPaths ( async ( sourceMapUtils ) => {
247263 await setupSourceMapConsumer ( sourceMapUtils , '/project1/cypress/integration/test1.spec.js' , [ 'src/components/Button.tsx' ] )
248264 await setupSourceMapConsumer ( sourceMapUtils , '/project2/cypress/integration/test2.spec.js' , [ 'src/utils/helper.js' ] )
249265
@@ -258,8 +274,8 @@ describe('source_map_utils', () => {
258274 } )
259275 } )
260276
261- it ( 'should handle empty source map consumers' , ( ) => {
262- withLinuxPaths ( async ( sourceMapUtils ) => {
277+ it ( 'should handle empty source map consumers' , async ( ) => {
278+ await withLinuxPaths ( async ( sourceMapUtils ) => {
263279 const relativePath = 'cypress/integration/test.spec.js'
264280 const absolutePath = '/project/src/components/Button.tsx'
265281
@@ -272,7 +288,7 @@ describe('source_map_utils', () => {
272288 } )
273289
274290 it ( 'should handle consumer with no matching sources' , async ( ) => {
275- withLinuxPaths ( async ( sourceMapUtils ) => {
291+ await withLinuxPaths ( async ( sourceMapUtils ) => {
276292 await setupSourceMapConsumer ( sourceMapUtils , '/project/cypress/integration/test.spec.js' , [ 'src/other/file.js' ] )
277293
278294 const relativePath = 'cypress/integration/test.spec.js'
@@ -286,8 +302,8 @@ describe('source_map_utils', () => {
286302 } )
287303 } )
288304
289- it ( 'should handle Windows paths in source map consumers ' , async ( ) => {
290- withWindowsPaths ( async ( sourceMapUtils ) => {
305+ it ( 'should handle Windows and return the base directory when source map consumer exists and path matches ' , async ( ) => {
306+ await withWindowsPaths ( async ( sourceMapUtils ) => {
291307 await setupSourceMapConsumer ( sourceMapUtils , 'C:\\project\\cypress\\integration\\test.spec.js' , [ 'src\\components\\Button.tsx' ] )
292308
293309 const relativePath = 'cypress\\integration\\test.spec.js'
0 commit comments