@@ -5,8 +5,12 @@ import { IMAGE_SNAPSHOT_PREFIX, PATH_VARIABLES } from "./constants";
5
5
6
6
type NotFalsy < T > = T extends false | null | undefined ? never : T ;
7
7
8
- const MIMIC_ROOT_WIN_REGEX = new RegExp ( `^${ PATH_VARIABLES . winSystemRootPath } \\${ path . sep } ([A-Z])\\${ path . sep } ` ) ;
9
- const MIMIC_ROOT_UNIX_REGEX = new RegExp ( `^${ PATH_VARIABLES . unixSystemRootPath } \\${ path . sep } ` ) ;
8
+ const MIMIC_ROOT_WIN_REGEX = new RegExp (
9
+ `^${ PATH_VARIABLES . winSystemRootPath } \\${ path . sep } ([A-Z])\\${ path . sep } `
10
+ ) ;
11
+ const MIMIC_ROOT_UNIX_REGEX = new RegExp (
12
+ `^${ PATH_VARIABLES . unixSystemRootPath } \\${ path . sep } `
13
+ ) ;
10
14
11
15
const getConfigVariableOrThrow = < K extends keyof Cypress . PluginConfigOptions > (
12
16
config : Cypress . PluginConfigOptions ,
@@ -22,29 +26,36 @@ const getConfigVariableOrThrow = <K extends keyof Cypress.PluginConfigOptions>(
22
26
/* c8 ignore stop */
23
27
24
28
const parseAbsolutePath = ( {
25
- screenshotPath, projectRoot,
29
+ screenshotPath,
30
+ projectRoot,
26
31
} : {
27
- screenshotPath : string ; projectRoot : string ;
32
+ screenshotPath : string ;
33
+ projectRoot : string ;
28
34
} ) => {
29
35
let newAbsolutePath : string ;
30
36
const matchedMimicingWinRoot = screenshotPath . match ( MIMIC_ROOT_WIN_REGEX ) ;
31
37
const matchedMimicingUnixRoot = screenshotPath . match ( MIMIC_ROOT_UNIX_REGEX ) ;
32
38
if ( matchedMimicingWinRoot && matchedMimicingWinRoot [ 1 ] ) {
33
39
const driveLetter = matchedMimicingWinRoot [ 1 ] ;
34
- newAbsolutePath = path . join ( `${ driveLetter } :\\` , screenshotPath . substring ( matchedMimicingWinRoot [ 0 ] . length ) ) ;
40
+ newAbsolutePath = path . join (
41
+ `${ driveLetter } :\\` ,
42
+ screenshotPath . substring ( matchedMimicingWinRoot [ 0 ] . length )
43
+ ) ;
35
44
} else if ( matchedMimicingUnixRoot ) {
36
- newAbsolutePath = path . sep + screenshotPath . substring ( matchedMimicingUnixRoot [ 0 ] . length ) ;
45
+ newAbsolutePath =
46
+ path . sep + screenshotPath . substring ( matchedMimicingUnixRoot [ 0 ] . length ) ;
37
47
} else {
38
48
newAbsolutePath = path . join ( projectRoot , screenshotPath ) ;
39
49
}
40
50
return path . normalize ( newAbsolutePath ) ;
41
- }
51
+ } ;
42
52
43
53
export const initAfterScreenshotHook =
44
54
( config : Cypress . PluginConfigOptions ) =>
45
55
(
46
56
details : Cypress . ScreenshotDetails
47
- ) : void
57
+ ) :
58
+ | void
48
59
| Cypress . AfterScreenshotReturnObject
49
60
| Promise < Cypress . AfterScreenshotReturnObject > => {
50
61
// it's not a screenshot generated by FRSOURCE Cypress Plugin Visual Regression Diff
@@ -55,23 +66,21 @@ export const initAfterScreenshotHook =
55
66
config ,
56
67
"screenshotsFolder"
57
68
) ;
69
+ const screenshotPath = details . name . substring (
70
+ IMAGE_SNAPSHOT_PREFIX . length + path . sep . length
71
+ ) ;
72
+ const newAbsolutePath = parseAbsolutePath ( {
73
+ screenshotPath,
74
+ projectRoot : config . projectRoot ,
75
+ } ) ;
58
76
59
- return new Promise ( async ( resolve , reject ) => {
60
- const screenshotPath = details . name . substring (
61
- IMAGE_SNAPSHOT_PREFIX . length + path . sep . length
62
- ) ;
63
- const newAbsolutePath = parseAbsolutePath ( { screenshotPath, projectRoot : config . projectRoot } ) ;
64
-
65
- try {
66
- await moveFile ( details . path , newAbsolutePath ) ;
67
- await fs . rm (
68
- path . join ( screenshotsFolder , IMAGE_SNAPSHOT_PREFIX ) ,
69
- { recursive : true , force : true } ,
70
- ) ;
77
+ return ( async ( ) => {
78
+ await moveFile ( details . path , newAbsolutePath ) ;
79
+ await fs . rm ( path . join ( screenshotsFolder , IMAGE_SNAPSHOT_PREFIX ) , {
80
+ recursive : true ,
81
+ force : true ,
82
+ } ) ;
71
83
72
- resolve ( { path : newAbsolutePath } ) ;
73
- } catch ( e ) {
74
- reject ( e ) ;
75
- }
76
- } ) ;
84
+ return { path : newAbsolutePath } ;
85
+ } ) ( ) ;
77
86
} ;
0 commit comments