Skip to content

Commit

Permalink
fix: prevent adding default supportFile on migration (#21985)
Browse files Browse the repository at this point in the history
* fix: prevent adding default supportFile on migration

* Update unit tests

Co-authored-by: Tim Griesser <tgriesser10@gmail.com>
  • Loading branch information
estrada9166 and tgriesser committed Jun 1, 2022
1 parent ae8d4b2 commit e0e5a60
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/data-context/src/sources/migration/codegen.ts
Expand Up @@ -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 },
Expand Down
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions packages/launchpad/cypress/e2e/migration.cy.ts
Expand Up @@ -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
Expand Down
@@ -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).
@@ -0,0 +1,3 @@
{
"supportFile": "cypress/support/index.js"
}
@@ -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)
},
},
})
Empty file.

3 comments on commit e0e5a60

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e0e5a60 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.0/linux-x64/develop-e0e5a60ef69a0d73fabf5e84334b5e097be366a6/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e0e5a60 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.0/darwin-x64/develop-e0e5a60ef69a0d73fabf5e84334b5e097be366a6/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e0e5a60 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.0/win32-x64/develop-e0e5a60ef69a0d73fabf5e84334b5e097be366a6/cypress.tgz

Please sign in to comment.