Skip to content

Commit de551f7

Browse files
authored
Merge branch '10.0-release' into zachw/ct-node-17
2 parents 56ddea8 + dcb4a61 commit de551f7

File tree

16 files changed

+94
-131
lines changed

16 files changed

+94
-131
lines changed

packages/app/cypress/e2e/cypress-in-cypress.cy.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100
208208
it(`resets selector playground validity when selecting element with playground selector in ${testingType}`, () => {
209209
startAtSpecsPage(testingType)
210210

211-
cy.get('[data-cy="spec-item"]').first().click()
212-
cy.get('#unified-reporter').should('be.visible')
211+
const spec = testingType === 'e2e' ? 'dom-content.spec.js' : 'TestComponent.spec.jsx'
212+
213+
cy.get('[data-cy="spec-item"]').contains(spec).click()
214+
cy.get('.passed > .num').should('contain', 1)
213215

214216
cy.get('[data-cy="playground-activator"]').click()
215217
cy.get('[data-cy="playground-selector"]').clear()

packages/app/cypress/e2e/specs.cy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ describe('App: Specs', () => {
509509

510510
it('shows success modal when empty spec is created', () => {
511511
cy.get('@CreateEmptySpecDialog').within(() => {
512+
cy.findByLabelText('Enter a relative path...').invoke('val').should('eq', getPathForPlatform('cypress/component/filename.cy.ts'))
513+
512514
cy.findByLabelText('Enter a relative path...').clear().type('cypress/my-empty-spec.cy.js')
513515

514516
cy.findByRole('button', { name: 'Create Spec' }).click()
@@ -533,6 +535,8 @@ describe('App: Specs', () => {
533535

534536
it('navigates to spec runner when selected', () => {
535537
cy.get('@CreateEmptySpecDialog').within(() => {
538+
cy.findByLabelText('Enter a relative path...').invoke('val').should('eq', getPathForPlatform('cypress/component/filename.cy.ts'))
539+
536540
cy.findByLabelText('Enter a relative path...').clear().type('cypress/my-empty-spec.cy.js')
537541

538542
cy.findByRole('button', { name: 'Create Spec' }).click()
@@ -551,6 +555,8 @@ describe('App: Specs', () => {
551555

552556
it('displays alert with docs link on new spec', () => {
553557
cy.get('@CreateEmptySpecDialog').within(() => {
558+
cy.findByLabelText('Enter a relative path...').invoke('val').should('eq', getPathForPlatform('cypress/component/filename.cy.ts'))
559+
554560
cy.findByLabelText('Enter a relative path...').clear().type('cypress/my-empty-spec.cy.js')
555561

556562
cy.findByRole('button', { name: 'Create Spec' }).click()

packages/app/src/specs/CreateSpecModal.cy.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ describe('<CreateSpecModal />', () => {
1414
gql={{
1515
currentProject: {
1616
id: 'id',
17-
codeGenGlobs: {
18-
id: 'super-unique-id',
19-
__typename: 'CodeGenGlobs',
20-
component: '**.vue',
21-
},
2217
currentTestingType: 'component',
2318
configFile: 'cypress.config.js',
2419
configFileAbsolutePath: '/path/to/cypress.config.js',
@@ -79,11 +74,6 @@ describe('playground', () => {
7974
gql={{
8075
currentProject: {
8176
id: 'id',
82-
codeGenGlobs: {
83-
id: 'super-unique-id',
84-
__typename: 'CodeGenGlobs',
85-
component: '**.vue',
86-
},
8777
currentTestingType: 'component',
8878
configFile: 'cypress.config.js',
8979
configFileAbsolutePath: '/path/to/cypress.config.js',

packages/app/src/specs/CreateSpecModal.vue

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
v-if="generator"
2121
:key="`${generator.id}-${iteration}`"
2222
v-model:title="title"
23-
:code-gen-glob="codeGenGlob"
2423
:gql="props.gql.currentProject"
2524
:type="props.gql.currentProject?.currentTestingType"
2625
:spec-file-name="specFileName"
@@ -78,10 +77,6 @@ fragment CreateSpecModal on Query {
7877
id
7978
fileExtensionToUse
8079
defaultSpecFileName
81-
codeGenGlobs {
82-
id
83-
component
84-
}
8580
...EmptyGenerator
8681
}
8782
}
@@ -114,14 +109,6 @@ const specFileName = computed(() => {
114109
return getPathForPlatform(fileName)
115110
})
116111
117-
const codeGenGlob = computed(() => {
118-
if (!generator.value) {
119-
return null
120-
}
121-
122-
return props.gql.currentProject?.codeGenGlobs[generator.value.id]
123-
})
124-
125112
const filteredGenerators = getFilteredGeneratorList(props.gql.currentProject?.currentTestingType)
126113
127114
const singleGenerator = computed(() => filteredGenerators.value.length === 1 ? filteredGenerators.value[0] : null)

packages/data-context/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@urql/exchange-graphcache": "4.3.6",
2424
"chokidar": "3.5.1",
2525
"common-path-prefix": "3.0.0",
26-
"create-cypress-tests": "0.0.0-development",
2726
"cross-fetch": "^3.1.4",
2827
"dataloader": "^2.0.0",
2928
"dayjs": "^1.9.3",

packages/data-context/src/actions/MigrationActions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,11 @@ export class MigrationActions {
260260
throw error
261261
})
262262

263-
// @ts-ignore configFile needs to be updated with the new one, so it finds the correct one
264-
// with the new file, instead of the deleted one which is not supported anymore
265-
this.ctx.modeOptions.configFile = this.ctx.migration.configFileNameAfterMigration
263+
if (this.ctx.modeOptions.configFile) {
264+
// @ts-ignore configFile needs to be updated with the new one, so it finds the correct one
265+
// with the new file, instead of the deleted one which is not supported anymore
266+
this.ctx.modeOptions.configFile = this.ctx.migration.configFileNameAfterMigration
267+
}
266268
}
267269

268270
async setLegacyConfigForMigration (config: LegacyCypressConfigJson) {

packages/data-context/src/sources/ProjectDataSource.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os from 'os'
22
import chokidar from 'chokidar'
3-
import type { ResolvedFromConfig, RESOLVED_FROM, FoundSpec } from '@packages/types'
4-
import { WIZARD_FRAMEWORKS } from '@packages/scaffold-config'
5-
import { scanFSForAvailableDependency } from 'create-cypress-tests'
3+
import type { ResolvedFromConfig, RESOLVED_FROM, FoundSpec, TestingType } from '@packages/types'
64
import minimatch from 'minimatch'
75
import { debounce, isEqual } from 'lodash'
86
import path from 'path'
@@ -104,7 +102,7 @@ export function transformSpec ({
104102
}
105103
}
106104

107-
export function getDefaultSpecFileName (specPattern: string, fileExtensionToUse?: 'js' | 'ts') {
105+
export function getDefaultSpecFileName (specPattern: string, testingType: TestingType, fileExtensionToUse?: 'js' | 'ts') {
108106
function replaceWildCard (s: string, fallback: string) {
109107
return s.replace(/\*/g, fallback)
110108
}
@@ -121,7 +119,7 @@ export function getDefaultSpecFileName (specPattern: string, fileExtensionToUse?
121119
dirname = dirname.replace('**', 'cypress')
122120
}
123121

124-
const splittedDirname = dirname.split('/').filter((s) => s !== '**').map((x) => replaceWildCard(x, 'e2e')).join('/')
122+
const splittedDirname = dirname.split('/').filter((s) => s !== '**').map((x) => replaceWildCard(x, testingType)).join('/')
125123
const fileName = replaceWildCard(parsedGlob.path.filename, 'filename')
126124

127125
const extnameWithoutExt = parsedGlob.path.extname.replace(parsedGlob.path.ext, '')
@@ -282,13 +280,15 @@ export class ProjectDataSource {
282280
}
283281

284282
async defaultSpecFileName () {
285-
const defaultFileName = 'cypress/e2e/filename.cy.js'
283+
const getDefaultFileName = (testingType: TestingType) => `cypress/${testingType}/filename.cy.${this.ctx.lifecycleManager.fileExtensionToUse}`
286284

287285
try {
288286
if (!this.ctx.currentProject || !this.ctx.coreData.currentTestingType) {
289287
return null
290288
}
291289

290+
const defaultFileName = getDefaultFileName(this.ctx.coreData.currentTestingType)
291+
292292
let specPatternSet: string | undefined
293293
const { specPattern = [] } = await this.ctx.project.specPatterns()
294294

@@ -300,15 +300,19 @@ export class ProjectDataSource {
300300
return defaultFileName
301301
}
302302

303-
const specFileName = getDefaultSpecFileName(specPatternSet, this.ctx.lifecycleManager.fileExtensionToUse)
303+
if (specPatternSet === defaultSpecPattern[this.ctx.coreData.currentTestingType]) {
304+
return defaultFileName
305+
}
306+
307+
const specFileName = getDefaultSpecFileName(specPatternSet, this.ctx.coreData.currentTestingType, this.ctx.lifecycleManager.fileExtensionToUse)
304308

305309
if (!specFileName) {
306310
return defaultFileName
307311
}
308312

309313
return specFileName
310314
} catch {
311-
return defaultFileName
315+
return getDefaultFileName(this.ctx.coreData.currentTestingType ?? 'e2e')
312316
}
313317
}
314318

@@ -359,31 +363,6 @@ export class ProjectDataSource {
359363
return preferences[projectTitle] ?? null
360364
}
361365

362-
private guessFramework (projectRoot: string) {
363-
const guess = WIZARD_FRAMEWORKS.find((framework) => {
364-
const lookingForDeps = framework.detectors.map((x) => x.package).reduce(
365-
(acc, dep) => ({ ...acc, [dep]: '*' }),
366-
{},
367-
)
368-
369-
return scanFSForAvailableDependency(projectRoot, lookingForDeps)
370-
})
371-
372-
return guess ?? null
373-
}
374-
375-
async getCodeGenGlobs () {
376-
assert(this.ctx.currentProject, `Cannot find glob without currentProject.`)
377-
378-
const looseComponentGlob = '*.{js,jsx,ts,tsx,.vue}'
379-
380-
const framework = this.guessFramework(this.ctx.currentProject)
381-
382-
return {
383-
component: framework?.glob ?? looseComponentGlob,
384-
}
385-
}
386-
387366
async getResolvedConfigFields (): Promise<ResolvedFromConfig[]> {
388367
const config = this.ctx.lifecycleManager.loadedFullConfig?.resolved ?? {}
389368

packages/data-context/test/unit/codegen/code-generator.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { parse } from '@babel/parser'
2-
import { WIZARD_FRAMEWORKS } from '@packages/scaffold-config'
32
import { expect } from 'chai'
43
import dedent from 'dedent'
54
import fs from 'fs-extra'
65
import path from 'path'
7-
import sinon from 'sinon'
86
import { DataContext } from '../../../src'
97
import {
108
Action, codeGenerator, CodeGenResult, CodeGenResults,
@@ -221,9 +219,6 @@ describe('code-generator', () => {
221219
target,
222220
}
223221

224-
// @ts-ignore
225-
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[0])
226-
227222
const newSpecCodeGenOptions = new SpecOptions(ctx, {
228223
codeGenPath: path.join(__dirname, 'files', 'react', 'Button.jsx'),
229224
codeGenType: 'component',
@@ -244,9 +239,6 @@ describe('code-generator', () => {
244239
target,
245240
}
246241

247-
// @ts-ignore
248-
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[1])
249-
250242
const newSpecCodeGenOptions = new SpecOptions(ctx, {
251243
codeGenPath: path.join(__dirname, 'files', 'vue', 'Button.vue'),
252244
codeGenType: 'component',

0 commit comments

Comments
 (0)