From 17f5f8eba5fbdd3466265da3be4302636ebead93 Mon Sep 17 00:00:00 2001 From: Cesar Avitia Date: Thu, 10 Feb 2022 20:27:29 -0700 Subject: [PATCH 1/5] cleanup integration folder after moving specs to e2e --- .../src/actions/MigrationActions.ts | 4 ++++ .../src/sources/migration/utils.ts | 19 +++++++++++++++++++ .../launchpad/cypress/e2e/migration.cy.ts | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/packages/data-context/src/actions/MigrationActions.ts b/packages/data-context/src/actions/MigrationActions.ts index 38e69c0fe84e..7cba6e5d20e1 100644 --- a/packages/data-context/src/actions/MigrationActions.ts +++ b/packages/data-context/src/actions/MigrationActions.ts @@ -1,6 +1,7 @@ import path from 'path' import type { DataContext } from '..' import { + cleanUpIntegrationFolder, formatConfig, moveSpecFiles, NonStandardMigrationError, @@ -48,6 +49,9 @@ export class MigrationActions { const projectRoot = this.ctx.path.join(this.ctx.currentProject) moveSpecFiles(projectRoot, specsToMove) + cleanUpIntegrationFolder(this.ctx.currentProject).catch((error) => { + throw error + }) } async renameSupportFile () { diff --git a/packages/data-context/src/sources/migration/utils.ts b/packages/data-context/src/sources/migration/utils.ts index c22546e96976..b77b20953218 100644 --- a/packages/data-context/src/sources/migration/utils.ts +++ b/packages/data-context/src/sources/migration/utils.ts @@ -289,6 +289,25 @@ export function moveSpecFiles (projectRoot: string, specs: SpecToMove[]) { }) } +export async function cleanupIntegrationFolder (projectRoot: string) { + const integrationPath = path.join(projectRoot, 'cypress', 'integration') + let dirContents: string[] = [] + + try { + dirContents = await fs.readdir(integrationPath) + } catch (e) { + // integration folder already cleaned up + } + + try { + if (dirContents.length === 0) { + await fs.rmdir(integrationPath) + } + } catch { + throw Error(`Failed to remove ${integrationPath}`) + } +} + export function renameSupportFilePath (relative: string) { const re = /cypress\/support\/(?index)\.[j|t|s[x]?/ const res = new RegExp(re).exec(relative) diff --git a/packages/launchpad/cypress/e2e/migration.cy.ts b/packages/launchpad/cypress/e2e/migration.cy.ts index 8070feb900f9..2ef37140c705 100644 --- a/packages/launchpad/cypress/e2e/migration.cy.ts +++ b/packages/launchpad/cypress/e2e/migration.cy.ts @@ -162,9 +162,16 @@ describe('Full migration flow for each project', { retries: { openMode: 2, runMo }) skipCTMigration() + // cy.findByText('Continue to next step').click() renameSupport() migrateAndVerifyConfig() finishMigrationAndContinue() + + cy.withCtx(async (ctx) => { + const integrationFolderStats = await ctx.actions.file.checkIfFileExists(ctx.path.join('cypress', 'integration')) + + expect(integrationFolderStats).to.be.null + }) }) it('completes journey for migration-e2e-component-default-test-files', () => { From 093d8051444372340e07029d467192a20703b2ce Mon Sep 17 00:00:00 2001 From: Cesar Avitia Date: Thu, 10 Feb 2022 20:36:09 -0700 Subject: [PATCH 2/5] cleanup comment --- packages/launchpad/cypress/e2e/migration.cy.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/launchpad/cypress/e2e/migration.cy.ts b/packages/launchpad/cypress/e2e/migration.cy.ts index 2ef37140c705..d8ba104934ab 100644 --- a/packages/launchpad/cypress/e2e/migration.cy.ts +++ b/packages/launchpad/cypress/e2e/migration.cy.ts @@ -162,7 +162,6 @@ describe('Full migration flow for each project', { retries: { openMode: 2, runMo }) skipCTMigration() - // cy.findByText('Continue to next step').click() renameSupport() migrateAndVerifyConfig() finishMigrationAndContinue() From b958e7e64adf2d115af34f533b5457267d8ee088 Mon Sep 17 00:00:00 2001 From: ElevateBart Date: Fri, 11 Feb 2022 11:34:15 -0600 Subject: [PATCH 3/5] update the way rmdir errors --- .../data-context/src/sources/migration/utils.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/data-context/src/sources/migration/utils.ts b/packages/data-context/src/sources/migration/utils.ts index b77b20953218..df136863e519 100644 --- a/packages/data-context/src/sources/migration/utils.ts +++ b/packages/data-context/src/sources/migration/utils.ts @@ -291,20 +291,14 @@ export function moveSpecFiles (projectRoot: string, specs: SpecToMove[]) { export async function cleanupIntegrationFolder (projectRoot: string) { const integrationPath = path.join(projectRoot, 'cypress', 'integration') - let dirContents: string[] = [] try { - dirContents = await fs.readdir(integrationPath) - } catch (e) { - // integration folder already cleaned up - } - - try { - if (dirContents.length === 0) { - await fs.rmdir(integrationPath) + await fs.rmdir(integrationPath) + } catch (e: any) { + // only throw if the folder exists + if (e.code !== 'ENOENT') { + throw Error(`Failed to remove ${integrationPath}`) } - } catch { - throw Error(`Failed to remove ${integrationPath}`) } } From 1329522444e03a1f56f4183f9942d1997ca92952 Mon Sep 17 00:00:00 2001 From: ElevateBart Date: Fri, 11 Feb 2022 12:07:51 -0600 Subject: [PATCH 4/5] fix typings oops --- packages/data-context/src/sources/migration/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/sources/migration/utils.ts b/packages/data-context/src/sources/migration/utils.ts index df136863e519..e9bf360a65fd 100644 --- a/packages/data-context/src/sources/migration/utils.ts +++ b/packages/data-context/src/sources/migration/utils.ts @@ -289,7 +289,7 @@ export function moveSpecFiles (projectRoot: string, specs: SpecToMove[]) { }) } -export async function cleanupIntegrationFolder (projectRoot: string) { +export async function cleanUpIntegrationFolder (projectRoot: string) { const integrationPath = path.join(projectRoot, 'cypress', 'integration') try { From ba74d755a91613ffdce923efb707b6d598c64cd8 Mon Sep 17 00:00:00 2001 From: ElevateBart Date: Fri, 11 Feb 2022 13:04:44 -0600 Subject: [PATCH 5/5] last couple of fixes --- packages/data-context/src/actions/MigrationActions.ts | 10 ++++++---- packages/data-context/src/sources/migration/utils.ts | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/data-context/src/actions/MigrationActions.ts b/packages/data-context/src/actions/MigrationActions.ts index 7cba6e5d20e1..d4086e0f4fc7 100644 --- a/packages/data-context/src/actions/MigrationActions.ts +++ b/packages/data-context/src/actions/MigrationActions.ts @@ -48,10 +48,12 @@ export class MigrationActions { const projectRoot = this.ctx.path.join(this.ctx.currentProject) - moveSpecFiles(projectRoot, specsToMove) - cleanUpIntegrationFolder(this.ctx.currentProject).catch((error) => { - throw error - }) + try { + await moveSpecFiles(projectRoot, specsToMove) + await cleanUpIntegrationFolder(this.ctx.currentProject) + } catch (err: any) { + this.ctx.coreData.baseError = err + } } async renameSupportFile () { diff --git a/packages/data-context/src/sources/migration/utils.ts b/packages/data-context/src/sources/migration/utils.ts index e9bf360a65fd..b064aa78a670 100644 --- a/packages/data-context/src/sources/migration/utils.ts +++ b/packages/data-context/src/sources/migration/utils.ts @@ -280,13 +280,13 @@ export interface SpecToMove { to: string } -export function moveSpecFiles (projectRoot: string, specs: SpecToMove[]) { - specs.forEach((spec) => { +export async function moveSpecFiles (projectRoot: string, specs: SpecToMove[]) { + await Promise.all(specs.map(async (spec) => { const from = path.join(projectRoot, spec.from) const to = path.join(projectRoot, spec.to) - fs.moveSync(from, to) - }) + await fs.move(from, to) + })) } export async function cleanUpIntegrationFolder (projectRoot: string) {