Skip to content

Commit

Permalink
Merge branch 'develop' into chore/enable-runner-rebuild-gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker authored Jun 1, 2022
2 parents 5716743 + e0e5a60 commit f784b96
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 19 deletions.
7 changes: 7 additions & 0 deletions packages/data-context/src/sources/migration/codegen.ts
Original file line number Diff line number Diff line change
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
32 changes: 17 additions & 15 deletions packages/data-context/test/unit/sources/GitDataSource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ describe('GitDataSource', () => {
const onGitInfoChange = sinon.stub()
const onError = sinon.stub()

// create a file and modify a file to express all
// git states we are interested in (created, unmodified, modified)
const fooSpec = path.join(e2eFolder, 'foo.cy.js')
const aRecordSpec = path.join(e2eFolder, 'a_record.cy.js')
const xhrSpec = path.join(e2eFolder, 'xhr.cy.js')

gitInfo = new GitDataSource({
isRunMode: false,
projectRoot: projectPath,
Expand All @@ -55,28 +61,24 @@ describe('GitDataSource', () => {
onError,
})

// create a file and modify a file to express all
// git states we are interested in (created, unmodified, modified)
const fooSpec = path.join(e2eFolder, 'foo.cy.js')
const aRecordSpec = path.join(e2eFolder, 'a_record.cy.js')
const xhrSpec = path.join(e2eFolder, 'xhr.cy.js')

fs.createFileSync(fooSpec)
fs.writeFileSync(xhrSpec, 'it(\'modifies the file\', () => {})')

const dfd = pDefer()
gitInfo.setSpecs([fooSpec, aRecordSpec, xhrSpec])

onGitInfoChange.onSecondCall().callsFake(dfd.resolve)
let result: any[] = []

gitInfo.setSpecs([fooSpec, aRecordSpec, xhrSpec])
do {
result = await Promise.all([
gitInfo.gitInfoFor(fooSpec),
gitInfo.gitInfoFor(aRecordSpec),
gitInfo.gitInfoFor(xhrSpec),
])

await dfd.promise
await new Promise((resolve) => setTimeout(resolve, 100))
} while (result.some((r) => r == null))

const [created, unmodified, modified] = await Promise.all([
gitInfo.gitInfoFor(fooSpec),
gitInfo.gitInfoFor(aRecordSpec),
gitInfo.gitInfoFor(xhrSpec),
])
const [created, unmodified, modified] = result

expect(created.lastModifiedHumanReadable).to.match(/(a few|[0-9]) seconds? ago/)
expect(created.statusType).to.eql('created')
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"supportFile": "cypress/support/index.js"
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'cypress'
const { defineConfig } = require('cypress')

export default defineConfig({
module.exports = defineConfig({
component: {
supportFile: false,
devServer: {
Expand Down
2 changes: 1 addition & 1 deletion system-tests/projects/missing-webpack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"webpack": "^5.0.0",
"webpack-dev-server": "4.9.0"
}
}
}

0 comments on commit f784b96

Please sign in to comment.