fix: prevent adding default supportFile on migration (#21985)

* fix: prevent adding default supportFile on migration

* Update unit tests

Co-authored-by: Tim Griesser <tgriesser10@gmail.com>
This commit is contained in:
Alejandro Estrada
2022-06-01 08:26:18 -05:00
committed by GitHub
parent ae8d4b2b05
commit e0e5a60ef6
10 changed files with 105 additions and 1 deletions

View File

@@ -435,6 +435,13 @@ export function reduceConfig (cfg: LegacyCypressConfigJson, options: CreateConfi
component: { ...acc.component, excludeSpecPattern: val },
}
case 'supportFile':
// 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)$))/)) {
return acc
}
return {
...acc,
e2e: { ...acc.e2e, supportFile: val },

View File

@@ -517,12 +517,20 @@ describe('reduceConfig', () => {
})
it('should nest supportFile under component and e2e', () => {
const config = { supportFile: 'cypress/support/index.js' }
const config = { supportFile: 'cypress/support/mySupportFile.js' }
const newConfig = reduceConfig(config, options)
expect(newConfig.e2e.supportFile).to.eq(config.supportFile)
})
it('should not add supportFile if it is the default one', () => {
expect(reduceConfig({ supportFile: null }, options).e2e.supportFile).to.not.exist
expect(reduceConfig({ supportFile: undefined }, options).e2e.supportFile).to.not.exist
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
})
it('should exclude the pluginsFile', () => {
const config = { pluginsFile: 'cypress/plugins/index.js' }
const newConfig = reduceConfig(config, options)

View File

@@ -503,6 +503,41 @@ describe('Full migration flow for each project', { retries: { openMode: 0, runMo
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
cy.get(renameAutoStep).should('exist')
// no CT
cy.get(renameManualStep).should('not.exist')
// supportFile is false - cannot migrate
cy.get(renameSupportStep).should('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
}
})
renameSupport()
migrateAndVerifyConfig()
checkOutcome()
})
it('completes journey for migration-e2e-custom-integration-default-value', () => {
startMigrationFor('migration-e2e-custom-integration-default-value')
// default testFiles but custom integration - can rename automatically

View File

@@ -0,0 +1,40 @@
## Migration E2E Custom SupportFile with default value
An e2e project with a custom `supportFile` named `cypress/support/index.js`. It uses the default `supportFile`. We will not
update the config file to show the supportFile because it is the same as the default one
The following migration steps will be used during this migration:
- [x] automatic file rename
- [ ] manual file rename
- [x] 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.
## Rename supportFile
The project has a default support file, `cypress/support/index.js`. We can rename it for them to `cypress/support/e2e.js`.
| Before | After|
|---|---|
| `cypress/support/index.js` | `cypress/support/e2e.js` |
## 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).

View File

@@ -0,0 +1,3 @@
{
"supportFile": "cypress/support/index.js"
}

View File

@@ -0,0 +1,11 @@
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)
},
},
})