Skip to content

Commit

Permalink
fix: do not show incorrectly support file migration step (#22015)
Browse files Browse the repository at this point in the history
* fix: do not show incorrectly support file migration step

* Add supportFile

* Delete supportFile

* Update regexp

* Update comment

Co-authored-by: Matt Henkes <mjhenkes@gmail.com>
  • Loading branch information
estrada9166 and mjhenkes authored Jun 1, 2022
1 parent d875564 commit 9caf623
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 5 deletions.
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 @@ -421,7 +421,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)$))/)) {
return true
}

return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ describe('reduceConfig', () => {
expect(reduceConfig({ supportFile: 'cypress/support' }, options).e2e.supportFile).to.not.exist
expect(reduceConfig({ supportFile: 'cypress/support/index' }, options).e2e.supportFile).to.not.exist
expect(reduceConfig({ supportFile: 'cypress/support/index.js' }, options).e2e.supportFile).to.not.exist
expect(reduceConfig({ supportFile: './cypress/support/index.js' }, options).e2e.supportFile).to.not.exist
expect(reduceConfig({ supportFile: '../cypress/support/index.js' }, options).e2e.supportFile).to.not.exist
})

it('should exclude the pluginsFile', () => {
Expand Down
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', () => {
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 custom - cannot rename
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"
}
Empty file.
Empty file.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

3 comments on commit 9caf623

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9caf623 Jun 1, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.1/linux-x64/develop-9caf623531a615ba9f8484eca961303450f0b9bd/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9caf623 Jun 1, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.1/darwin-x64/develop-9caf623531a615ba9f8484eca961303450f0b9bd/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9caf623 Jun 1, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.1/win32-x64/develop-9caf623531a615ba9f8484eca961303450f0b9bd/cypress.tgz

Please sign in to comment.