Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not show incorrectly support file migration step #22015

Merged
merged 11 commits into from
Jun 1, 2022
Merged
4 changes: 2 additions & 2 deletions packages/data-context/src/sources/migration/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toPosix } from '../../util'
import Debug from 'debug'
import dedent from 'dedent'
import { hasDefaultExport } from './parserUtils'
import { LegacyCypressConfigJson, legacyIntegrationFolder } from '..'
import { isDefaultSupportFile, LegacyCypressConfigJson, legacyIntegrationFolder } from '..'
import { parse } from '@babel/parser'
import generate from '@babel/generator'
import _ from 'lodash'
Expand Down Expand Up @@ -438,7 +438,7 @@ export function reduceConfig (cfg: LegacyCypressConfigJson, options: CreateConfi
// If the supportFile is set, but is the same value as the default one; where
// we migrate it, we do not want to put the legacy value in the migrated config.
// It can be .ts or .js
if (_.isNil(val) || !_.isBoolean(val) && val.match(/^cypress\/support($|\/index($|\.(ts|js)$))/)) {
if (isDefaultSupportFile(val)) {
return acc
}

Expand Down
1 change: 1 addition & 0 deletions packages/data-context/src/sources/migration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './legacyOptions'
export * from './parserUtils'
export * from './regexps'
export * from './shouldShowSteps'
export * from './utils'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import globby from 'globby'
import path from 'path'
import { MIGRATION_STEPS } from '@packages/types'
import { applyMigrationTransform, getSpecs, legacyIntegrationFolder, tryGetDefaultLegacySupportFile } from '.'
import { applyMigrationTransform, getSpecs, isDefaultSupportFile, legacyIntegrationFolder, tryGetDefaultLegacySupportFile } from '.'
import type { LegacyCypressConfigJson } from '..'

export const defaultTestFilesGlob = '**/*.{js,ts,jsx,tsx,coffee,cjsx}'
Expand Down Expand Up @@ -117,7 +117,6 @@ export async function shouldShowRenameSupport (projectRoot: string, config: Lega
return false
}

const defaultSupportFile = 'cypress/support/index.'
let supportFile = config.e2e?.supportFile ?? config.supportFile

if (supportFile === undefined) {
Expand All @@ -136,7 +135,7 @@ export async function shouldShowRenameSupport (projectRoot: string, config: Lega

// if the support file is custom, we don't show the rename step
// only if the support file matches the default do we show the rename step
return supportFile.includes(defaultSupportFile)
return isDefaultSupportFile(supportFile)
}

// if they have component testing configured using the defaults, they will need to
Expand Down
9 changes: 9 additions & 0 deletions packages/data-context/src/sources/migration/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import _ from 'lodash'

export const isDefaultSupportFile = (supportFile: string) => {
if (_.isNil(supportFile) || !_.isBoolean(supportFile) && supportFile.match(/^cypress\/support($|\/index($|\.(ts|js|coffee)$))/)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the coffee ext here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this code was lifted, but what happens if the user has ./cypress/support/index.js (prefixed with "./"). This is the default file but the regex wouldn't match

Copy link
Member Author

@estrada9166 estrada9166 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should update the regex for something like (^|\.+\/)cypress\/support($|\/index($|\.(ts|js|coffee)$)) what do you think?

Copy link
Member Author

@estrada9166 estrada9166 Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 2e5b5d6

return true
}

return false
}
34 changes: 34 additions & 0 deletions packages/launchpad/cypress/e2e/migration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,40 @@ describe('Full migration flow for each project', { retries: { openMode: 0, runMo
checkOutcome()
})

it('completes journey for migration-e2e-custom-supportFile', () => {
flotwig marked this conversation as resolved.
Show resolved Hide resolved
startMigrationFor('migration-e2e-custom-supportFile')
// default testFiles but custom integration - can rename automatically
cy.get(renameAutoStep).should('exist')
// no CT
cy.get(renameManualStep).should('not.exist')
// supportFile is false - cannot migrate
cy.get(renameSupportStep).should('not.exist')
cy.get(setupComponentStep).should('not.exist')
cy.get(configFileStep).should('exist')

// Migration workflow
// before auto migration
cy.contains('cypress/integration/basic.spec.js')

// after auto migration
cy.contains('cypress/e2e/basic.cy.js')

runAutoRename()

cy.withRetryableCtx(async (ctx) => {
const specs = ['cypress/e2e/basic.cy.js']

for (const spec of specs) {
const stats = await ctx.file.checkIfFileExists(ctx.path.join(spec))

expect(stats).to.not.be.null
}
})

migrateAndVerifyConfig()
checkOutcome()
})

it('completes journey for migration-e2e-custom-supportFile-default-value', () => {
startMigrationFor('migration-e2e-custom-supportFile-default-value')
// default testFiles but custom integration - can rename automatically
Expand Down
32 changes: 32 additions & 0 deletions system-tests/projects/migration-e2e-custom-supportFile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Migration E2E Custom SupportFile

An e2e project with a custom `supportFile` named `src/platform/testing/e2e/cypress/support/index.js`. It includes
the default value on the path but is not the default.

The following migration steps will be used during this migration:

- [x] automatic file rename
- [ ] manual file rename
- [] rename support
- [x] update config file
- [ ] setup component testing


## Automatic Migration

Unless the user skips this step, after this step, the filesystem will be:

| Before | After|
|---|---|
| `src/basic.test.js` | `src/basic.cy.js` |

## Manual Files

This step is not used.

## Update Config

We can migrate to the new `cypress.config.js`. The expected output is in `expected-cypress.config.js`. The main points are:


The expected output is in [`expected-cypress.config.js`](./expected-cypress.config.js).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"supportFile": "src/platform/testing/e2e/cypress/support/index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents (on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
supportFile: 'src/platform/testing/e2e/cypress/support/index.js',
},
})
Empty file.