Skip to content

Commit 1af1e6c

Browse files
committed
correct paths and add ct framework to expected dir
1 parent c32483a commit 1af1e6c

File tree

12 files changed

+21
-11
lines changed

12 files changed

+21
-11
lines changed

packages/launchpad/cypress/e2e/scaffold-project.cy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ function scaffoldAndOpenCTProject (
7373
cy.contains('Choose a Browser')
7474
}
7575

76-
function assertScaffoldedFilesAreCorrect (language: 'js' | 'ts', testingType: Cypress.TestingType) {
76+
function assertScaffoldedFilesAreCorrect (language: 'js' | 'ts', testingType: Cypress.TestingType, ctFramework?: string) {
7777
cy.withCtx((ctx) => ctx.currentProject).then((currentProject) => {
7878
cy.task<SnapshotScaffoldTestResult>('snapshotCypressDirectory', {
7979
currentProject,
8080
testingType,
8181
language,
82+
ctFramework,
8283
})
8384
.then((result) => {
8485
if (result.status === 'ok') {
@@ -106,11 +107,11 @@ describe('scaffolding new projects', () => {
106107

107108
it('scaffolds CT for a JS project', () => {
108109
scaffoldAndOpenCTProject('pristine', 'js', 'Create React App (v5)')
109-
assertScaffoldedFilesAreCorrect('js', 'component')
110+
assertScaffoldedFilesAreCorrect('js', 'component', 'Create React App (v5)')
110111
})
111112

112113
it('scaffolds CT for a TS project', () => {
113114
scaffoldAndOpenCTProject('pristine', 'ts', 'Create React App (v5)')
114-
assertScaffoldedFilesAreCorrect('ts', 'component')
115+
assertScaffoldedFilesAreCorrect('ts', 'component', 'Create React App (v5)')
115116
})
116117
})

packages/launchpad/cypress/tasks/snapshotsScaffold.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import disparity from 'disparity'
55
import dedent from 'dedent'
66
import { 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

1010
export 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

Comments
 (0)