@@ -15,6 +15,24 @@ const resetMap = (map: Record<string, unknown>) => {
15
15
for ( const key in map ) delete map [ key ] ;
16
16
} ;
17
17
18
+ const parsePathPartVariables = (
19
+ specPath : string ,
20
+ pathPart : string ,
21
+ i : number
22
+ ) => {
23
+ if ( pathPart === PATH_VARIABLES . specPath ) {
24
+ return path . dirname ( specPath ) ;
25
+ } else if ( i === 0 && ! pathPart ) {
26
+ // when unix-like absolute path
27
+ return PATH_VARIABLES . unixSystemRootPath ;
28
+ } else if ( i === 0 && WINDOWS_LIKE_DRIVE_REGEX . test ( pathPart ) ) {
29
+ // when win-like absolute path
30
+ return path . join ( PATH_VARIABLES . winSystemRootPath , pathPart [ 0 ] ) ;
31
+ }
32
+
33
+ return pathPart ;
34
+ } ;
35
+
18
36
export const generateScreenshotPath = ( {
19
37
titleFromOptions,
20
38
imagesPath,
@@ -26,22 +44,8 @@ export const generateScreenshotPath = ({
26
44
specPath : string ;
27
45
currentRetryNumber : number ;
28
46
} ) => {
29
- const parsePathPartVariables = ( pathPart : string , i : number ) => {
30
- if ( pathPart === PATH_VARIABLES . specPath ) {
31
- return path . dirname ( specPath ) ;
32
- } else if ( i === 0 && ! pathPart ) {
33
- // when unix-like absolute path
34
- return PATH_VARIABLES . unixSystemRootPath ;
35
- } else if ( i === 0 && WINDOWS_LIKE_DRIVE_REGEX . test ( pathPart ) ) {
36
- // when win-like absolute path
37
- return path . join ( PATH_VARIABLES . winSystemRootPath , pathPart [ 0 ] ) ;
38
- }
39
-
40
- return pathPart ;
41
- } ;
42
-
43
47
const screenshotPath = path . join (
44
- ...imagesPath . split ( "/" ) . map ( parsePathPartVariables ) ,
48
+ ...imagesPath . split ( "/" ) . map ( parsePathPartVariables . bind ( void 0 , specPath ) ) ,
45
49
sanitize ( titleFromOptions )
46
50
) ;
47
51
0 commit comments