@@ -5,7 +5,7 @@ import disparity from 'disparity'
55import dedent from 'dedent'
66import { cyTmpDir } from '@tooling/system-tests/lib/fixtures'
77
8- const systemTestsDir = path . posix . join ( __dirname , '..' , '..' , '..' , '..' , 'system-tests' , 'projects' )
8+ const systemTestsDir = path . join ( __dirname , '..' , '..' , '..' , '..' , 'system-tests' , 'projects' )
99
1010export interface SnapshotScaffoldTestResult {
1111 status : 'ok' | 'fail'
@@ -78,9 +78,14 @@ interface SnapshotCypressDirectoryOptions {
7878 currentProject : string
7979 language : 'js' | 'ts'
8080 testingType : Cypress . TestingType
81+ ctFramework ?: string
8182}
8283
83- export async function snapshotCypressDirectory ( { currentProject, language, testingType } : SnapshotCypressDirectoryOptions ) : Promise < SnapshotScaffoldTestResult > {
84+ function removeHyphensAndBrackets ( str : string ) {
85+ return str . toLowerCase ( ) . replaceAll ( ' ' , '-' ) . replaceAll ( '(' , '' ) . replaceAll ( ')' , '' )
86+ }
87+
88+ export async function snapshotCypressDirectory ( { currentProject, language, testingType, ctFramework } : SnapshotCypressDirectoryOptions ) : Promise < SnapshotScaffoldTestResult > {
8489 if ( ! currentProject . startsWith ( cyTmpDir ) ) {
8590 throw Error ( dedent `
8691 snapshotCypressDirectory is designed to be used with system-tests infrastructure.
@@ -93,14 +98,18 @@ export async function snapshotCypressDirectory ({ currentProject, language, test
9398 const projectDir = currentProject . replace ( cyTmpDir , systemTestsDir )
9499 const projectName = projectDir . replace ( systemTestsDir , '' ) . slice ( 1 )
95100
96- const expectedScaffoldDir = path . posix . join ( projectDir , `expected-cypress-${ language } -${ testingType } ` )
101+ let expectedScaffoldDir = path . join ( projectDir , `expected-cypress-${ language } -${ testingType } ` )
102+
103+ if ( ctFramework ) {
104+ expectedScaffoldDir += `-${ removeHyphensAndBrackets ( ctFramework ) } `
105+ }
97106
98- const currentProjectPosix = currentProject . split ( path . sep ) . join ( path . posix . sep )
107+ const joinPosix = ( ... s : string [ ] ) => path . join ( ... s ) . split ( path . sep ) . join ( path . posix . sep )
99108
100109 const files = (
101110 await Promise . all ( [
102- globby ( path . posix . join ( currentProjectPosix , 'cypress' ) , { onlyFiles : true } ) ,
103- globby ( path . posix . join ( currentProjectPosix , 'cypress.config.*' ) , { onlyFiles : true } ) ,
111+ globby ( joinPosix ( currentProject , 'cypress' ) , { onlyFiles : true } ) ,
112+ globby ( joinPosix ( currentProject , 'cypress.config.*' ) , { onlyFiles : true } ) ,
104113 ] )
105114 ) . reduce ( ( acc , curr ) => {
106115 return [ acc , curr ] . flat ( 2 )
@@ -112,8 +121,8 @@ export async function snapshotCypressDirectory ({ currentProject, language, test
112121
113122 const filesToDiff = actualRelativeFiles . map < FileToDiff > ( ( file ) => {
114123 return {
115- actual : path . posix . join ( currentProjectPosix , file ) ,
116- expected : path . posix . join ( expectedScaffoldDir , file ) ,
124+ actual : path . join ( currentProject , file ) ,
125+ expected : path . join ( expectedScaffoldDir , file ) ,
117126 }
118127 } )
119128
0 commit comments