Skip to content

Commit e0e5a60

Browse files
fix: prevent adding default supportFile on migration (#21985)
* fix: prevent adding default supportFile on migration * Update unit tests Co-authored-by: Tim Griesser <[email protected]>
1 parent ae8d4b2 commit e0e5a60

File tree

10 files changed

+105
-1
lines changed

10 files changed

+105
-1
lines changed

packages/data-context/src/sources/migration/codegen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ export function reduceConfig (cfg: LegacyCypressConfigJson, options: CreateConfi
435435
component: { ...acc.component, excludeSpecPattern: val },
436436
}
437437
case 'supportFile':
438+
// If the supportFile is set, but is the same value as the default one; where
439+
// we migrate it, we do not want to put the legacy value in the migrated config.
440+
// It can be .ts or .js
441+
if (_.isNil(val) || !_.isBoolean(val) && val.match(/^cypress\/support($|\/index($|\.(ts|js)$))/)) {
442+
return acc
443+
}
444+
438445
return {
439446
...acc,
440447
e2e: { ...acc.e2e, supportFile: val },

packages/data-context/test/unit/sources/migration/codegen.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,20 @@ describe('reduceConfig', () => {
517517
})
518518

519519
it('should nest supportFile under component and e2e', () => {
520-
const config = { supportFile: 'cypress/support/index.js' }
520+
const config = { supportFile: 'cypress/support/mySupportFile.js' }
521521
const newConfig = reduceConfig(config, options)
522522

523523
expect(newConfig.e2e.supportFile).to.eq(config.supportFile)
524524
})
525525

526+
it('should not add supportFile if it is the default one', () => {
527+
expect(reduceConfig({ supportFile: null }, options).e2e.supportFile).to.not.exist
528+
expect(reduceConfig({ supportFile: undefined }, options).e2e.supportFile).to.not.exist
529+
expect(reduceConfig({ supportFile: 'cypress/support' }, options).e2e.supportFile).to.not.exist
530+
expect(reduceConfig({ supportFile: 'cypress/support/index' }, options).e2e.supportFile).to.not.exist
531+
expect(reduceConfig({ supportFile: 'cypress/support/index.js' }, options).e2e.supportFile).to.not.exist
532+
})
533+
526534
it('should exclude the pluginsFile', () => {
527535
const config = { pluginsFile: 'cypress/plugins/index.js' }
528536
const newConfig = reduceConfig(config, options)

packages/launchpad/cypress/e2e/migration.cy.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,41 @@ describe('Full migration flow for each project', { retries: { openMode: 0, runMo
503503
checkOutcome()
504504
})
505505

506+
it('completes journey for migration-e2e-custom-supportFile-default-value', () => {
507+
startMigrationFor('migration-e2e-custom-supportFile-default-value')
508+
// default testFiles but custom integration - can rename automatically
509+
cy.get(renameAutoStep).should('exist')
510+
// no CT
511+
cy.get(renameManualStep).should('not.exist')
512+
// supportFile is false - cannot migrate
513+
cy.get(renameSupportStep).should('exist')
514+
cy.get(setupComponentStep).should('not.exist')
515+
cy.get(configFileStep).should('exist')
516+
517+
// Migration workflow
518+
// before auto migration
519+
cy.contains('cypress/integration/basic.spec.js')
520+
521+
// after auto migration
522+
cy.contains('cypress/e2e/basic.cy.js')
523+
524+
runAutoRename()
525+
526+
cy.withRetryableCtx(async (ctx) => {
527+
const specs = ['cypress/e2e/basic.cy.js']
528+
529+
for (const spec of specs) {
530+
const stats = await ctx.file.checkIfFileExists(ctx.path.join(spec))
531+
532+
expect(stats).to.not.be.null
533+
}
534+
})
535+
536+
renameSupport()
537+
migrateAndVerifyConfig()
538+
checkOutcome()
539+
})
540+
506541
it('completes journey for migration-e2e-custom-integration-default-value', () => {
507542
startMigrationFor('migration-e2e-custom-integration-default-value')
508543
// default testFiles but custom integration - can rename automatically
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Migration E2E Custom SupportFile with default value
2+
3+
An e2e project with a custom `supportFile` named `cypress/support/index.js`. It uses the default `supportFile`. We will not
4+
update the config file to show the supportFile because it is the same as the default one
5+
6+
The following migration steps will be used during this migration:
7+
8+
- [x] automatic file rename
9+
- [ ] manual file rename
10+
- [x] rename support
11+
- [x] update config file
12+
- [ ] setup component testing
13+
14+
15+
## Automatic Migration
16+
17+
Unless the user skips this step, after this step, the filesystem will be:
18+
19+
| Before | After|
20+
|---|---|
21+
| `src/basic.test.js` | `src/basic.cy.js` |
22+
23+
## Manual Files
24+
25+
This step is not used.
26+
27+
## Rename supportFile
28+
29+
The project has a default support file, `cypress/support/index.js`. We can rename it for them to `cypress/support/e2e.js`.
30+
31+
| Before | After|
32+
|---|---|
33+
| `cypress/support/index.js` | `cypress/support/e2e.js` |
34+
35+
## Update Config
36+
37+
We can migrate to the new `cypress.config.js`. The expected output is in `expected-cypress.config.js`. The main points are:
38+
39+
40+
The expected output is in [`expected-cypress.config.js`](./expected-cypress.config.js).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"supportFile": "cypress/support/index.js"
3+
}

system-tests/projects/migration-e2e-custom-supportFile-default-value/cypress/integration/basic.spec.js

Whitespace-only changes.

system-tests/projects/migration-e2e-custom-supportFile-default-value/cypress/plugins/index.js

Whitespace-only changes.

system-tests/projects/migration-e2e-custom-supportFile-default-value/cypress/support/index.js

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
e2e: {
5+
// We've imported your old cypress plugins here.
6+
// You may want to clean this up later by importing these.
7+
setupNodeEvents (on, config) {
8+
return require('./cypress/plugins/index.js')(on, config)
9+
},
10+
},
11+
})

system-tests/projects/migration-e2e-custom-supportFile-default-value/src/basic.spec.js

Whitespace-only changes.

0 commit comments

Comments
 (0)