mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-21 14:40:05 -05:00
Add test for migration scenario
This commit is contained in:
@@ -286,7 +286,6 @@ export class ProjectConfigManager {
|
||||
|
||||
onLoadError = (error: any) => {
|
||||
this.closeWatchers()
|
||||
// TODO: this isn't i18n'd
|
||||
this.options.onError(error, 'Error Loading Config')
|
||||
}
|
||||
|
||||
|
||||
@@ -271,9 +271,16 @@ export class ProjectLifecycleManager {
|
||||
}
|
||||
|
||||
async reloadConfig () {
|
||||
assert(this._projectRoot)
|
||||
assert(this._configManager)
|
||||
|
||||
return this._configManager.reloadConfig()
|
||||
if (this.readyToInitialize(this._projectRoot)) {
|
||||
await this._configManager.reloadConfig()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
async waitForInitializeSuccess (): Promise<boolean> {
|
||||
@@ -330,22 +337,9 @@ export class ProjectLifecycleManager {
|
||||
|
||||
this._configManager = this.createConfigManager()
|
||||
|
||||
const { needsCypressJsonMigration } = this.refreshMetaState()
|
||||
|
||||
const legacyConfigPath = path.join(projectRoot, this.legacyConfigFile)
|
||||
|
||||
if (needsCypressJsonMigration && !this.ctx.isRunMode && this.ctx.fs.existsSync(legacyConfigPath)) {
|
||||
this.legacyMigration(legacyConfigPath).catch(this.onLoadError)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
this.legacyPluginGuard()
|
||||
|
||||
// Preemptively load these so that they are available when we need them later
|
||||
this.ctx.browser.machineBrowsers().catch(this.onLoadError)
|
||||
|
||||
this.verifyProjectRoot(projectRoot)
|
||||
const packageManagerUsed = this.getPackageManagerUsed(projectRoot)
|
||||
|
||||
this.ctx.update((s) => {
|
||||
@@ -353,13 +347,31 @@ export class ProjectLifecycleManager {
|
||||
s.packageManager = packageManagerUsed
|
||||
})
|
||||
|
||||
this.configFileWarningCheck()
|
||||
|
||||
if (this.metaState.hasValidConfigFile) {
|
||||
if (this.readyToInitialize(this._projectRoot)) {
|
||||
this._configManager.initializeConfig().catch(this.onLoadError)
|
||||
}
|
||||
}
|
||||
|
||||
readyToInitialize (projectRoot: string): boolean {
|
||||
this.verifyProjectRoot(projectRoot)
|
||||
|
||||
const { needsCypressJsonMigration } = this.refreshMetaState()
|
||||
|
||||
const legacyConfigPath = path.join(projectRoot, this.legacyConfigFile)
|
||||
|
||||
if (needsCypressJsonMigration && !this.ctx.isRunMode && this.ctx.fs.existsSync(legacyConfigPath)) {
|
||||
this.legacyMigration(legacyConfigPath).catch(this.onLoadError)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
this.legacyPluginGuard()
|
||||
|
||||
this.configFileWarningCheck()
|
||||
|
||||
return this.metaState.hasValidConfigFile
|
||||
}
|
||||
|
||||
async legacyMigration (legacyConfigPath: string) {
|
||||
try {
|
||||
// we run the legacy plugins/index.js in a child process
|
||||
@@ -370,6 +382,8 @@ export class ProjectLifecycleManager {
|
||||
// should never throw, unless there existing pluginsFile errors out,
|
||||
// in which case they are attempting to migrate an already broken project.
|
||||
await this.ctx.actions.migration.initialize(legacyConfig)
|
||||
|
||||
this.ctx.emitter.toLaunchpad()
|
||||
} catch (error) {
|
||||
this.onLoadError(error)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// created by autobarrel, do not modify directly
|
||||
|
||||
export * from './CypressEnv'
|
||||
export * from './EventRegistrar'
|
||||
export * from './LegacyPluginsIpc'
|
||||
export * from './ProjectConfigIpc'
|
||||
export * from './ProjectConfigManager'
|
||||
|
||||
@@ -180,8 +180,6 @@ export class ProjectDataSource {
|
||||
}
|
||||
|
||||
async getConfig () {
|
||||
assert(this.ctx.coreData.currentTestingType)
|
||||
|
||||
return await this.ctx.lifecycleManager.getFullInitialConfig()
|
||||
}
|
||||
|
||||
|
||||
@@ -5,4 +5,5 @@ export * from './autoBindDebug'
|
||||
export * from './cached'
|
||||
export * from './config-file-updater'
|
||||
export * from './file'
|
||||
export * from './pluginHandlers'
|
||||
export * from './urqlCacheKeys'
|
||||
|
||||
@@ -638,8 +638,6 @@ export const mutation = mutationType({
|
||||
await ctx.actions.project.reconfigureProject()
|
||||
}
|
||||
|
||||
// TODO: do i need to scaffold here too?
|
||||
|
||||
return true
|
||||
},
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ export const Query = objectType({
|
||||
t.field('migration', {
|
||||
type: Migration,
|
||||
description: 'Metadata about the migration, null if we aren\'t showing it',
|
||||
resolve: (root, args, ctx) => ctx.coreData.migration,
|
||||
resolve: (root, args, ctx) => ctx.coreData.migration.legacyConfigForMigration ? ctx.coreData.migration : null,
|
||||
})
|
||||
|
||||
t.nonNull.field('dev', {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { e2eProjectDirs } from '@packages/frontend-shared/cypress/e2e/support/e2eProjectDirs'
|
||||
import { decodeBase64Unicode } from '@packages/frontend-shared/src/utils/base64'
|
||||
|
||||
const renameAutoStep = `[data-cy="migration-step renameAuto"]`
|
||||
const renameManualStep = `[data-cy="migration-step renameManual"]`
|
||||
@@ -6,6 +7,16 @@ const renameSupportStep = `[data-cy="migration-step renameSupport"]`
|
||||
const configFileStep = `[data-cy="migration-step configFile"]`
|
||||
const setupComponentStep = `[data-cy="migration-step setupComponent"]`
|
||||
|
||||
function getPathForPlatform (posixPath: string) {
|
||||
// @ts-ignore
|
||||
const cy = window.Cypress
|
||||
const platform = cy?.platform || JSON.parse(decodeBase64Unicode(window.__CYPRESS_CONFIG__.base64Config)).platform
|
||||
|
||||
if (platform === 'win32') return posixPath.replaceAll('/', '\\')
|
||||
|
||||
return posixPath
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
@@ -941,6 +952,14 @@ describe('Full migration flow for each project', { retries: { openMode: 2, runMo
|
||||
cy.get('[data-testid="error-code-frame"]').contains(`cypress/plugins/index.js:2:9`)
|
||||
// correct error from pluginsFile
|
||||
cy.contains(`throw Error('Uh oh, there was an error!')`)
|
||||
|
||||
cy.withCtx(async (ctx, o) => {
|
||||
await ctx.actions.file.writeFileInProject(o.path, 'module.exports = (on, config) => {}')
|
||||
}, { path: getPathForPlatform('cypress/plugins/index.js') })
|
||||
|
||||
cy.findByRole('button', { name: 'Try again' }).click()
|
||||
|
||||
cy.waitForWizard()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -186,11 +186,6 @@ describe('Routes', () => {
|
||||
|
||||
this.proxy = `http://localhost:${port}`
|
||||
}),
|
||||
|
||||
// pluginsModule.init(cfg, {
|
||||
// projectRoot: cfg.projectRoot,
|
||||
// testingType: 'e2e',
|
||||
// }, ctx),
|
||||
])
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
Reference in New Issue
Block a user