Split up setTestingType with setCurrentProject

This commit is contained in:
Ryan Manuel
2022-03-25 13:22:51 -05:00
parent f6cc702aaa
commit 5ca23b219f
3 changed files with 22 additions and 15 deletions
+3
View File
@@ -433,6 +433,9 @@ export class DataContext {
await this.lifecycleManager.initializeRunMode()
} else if (this._config.mode === 'open') {
await this.initializeOpenMode()
if (this.coreData.currentTestingType && await this.lifecycleManager.waitForInitializeSuccess()) {
this.lifecycleManager.setCurrentTestingType(this.coreData.currentTestingType)
}
} else {
throw new Error(`Missing DataContext config "mode" setting, expected run | open`)
}
@@ -129,10 +129,6 @@ export class ProjectConfigManager {
this._cachedLoadConfig = result
this.options.onInitialConfigLoaded(result.initialConfig)
if (this._testingType && this.isTestingTypeConfigured(this._testingType) || this.options.isRunMode) {
this.setupNodeEvents(result).catch(this.onLoadError)
}
}
return result.initialConfig
@@ -296,6 +296,16 @@ export class ProjectLifecycleManager {
return this._configManager.reloadConfig()
}
async waitForInitializeSuccess (): Promise<boolean> {
try {
await this.initializeConfig()
return true
} catch (error) {
return false
}
}
async initializeConfig () {
assert(this._configManager)
@@ -362,10 +372,6 @@ export class ProjectLifecycleManager {
}
this.loadCypressEnvFile().catch(this.onLoadError)
if (this.ctx.coreData.currentTestingType) {
this.setCurrentTestingType(this.ctx.coreData.currentTestingType)
}
}
async #legacyMigration (legacyConfigPath: string) {
@@ -623,14 +629,16 @@ export class ProjectLifecycleManager {
async initializeRunMode () {
this._pendingInitialize = pDefer()
if (!this._currentTestingType) {
// e2e is assumed to be the default testing type if
// none is passed in run mode
this.setCurrentTestingType('e2e')
}
if (await this.waitForInitializeSuccess()) {
if (this._currentTestingType) {
this.setCurrentTestingType(this._currentTestingType)
} else {
this.setCurrentTestingType('e2e')
}
if (!this.metaState.hasValidConfigFile) {
return this.ctx.onError(getError('NO_DEFAULT_CONFIG_FILE_FOUND', this.projectRoot))
if (!this.metaState.hasValidConfigFile) {
return this.ctx.onError(getError('NO_DEFAULT_CONFIG_FILE_FOUND', this.projectRoot))
}
}
return this._pendingInitialize.promise.finally(() => {