Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup integration folder after moving specs to e2e #20149

Merged
merged 9 commits into from
Feb 12, 2022
8 changes: 7 additions & 1 deletion packages/data-context/src/actions/MigrationActions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import type { DataContext } from '..'
import {
cleanUpIntegrationFolder,
formatConfig,
moveSpecFiles,
NonStandardMigrationError,
Expand Down Expand Up @@ -47,7 +48,12 @@ export class MigrationActions {

const projectRoot = this.ctx.path.join(this.ctx.currentProject)

moveSpecFiles(projectRoot, specsToMove)
try {
await moveSpecFiles(projectRoot, specsToMove)
await cleanUpIntegrationFolder(this.ctx.currentProject)
} catch (err: any) {
this.ctx.coreData.baseError = err
}
}

async renameSupportFile () {
Expand Down
21 changes: 17 additions & 4 deletions packages/data-context/src/sources/migration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,26 @@ 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) {
const integrationPath = path.join(projectRoot, 'cypress', 'integration')

try {
await fs.rmdir(integrationPath)
} catch (e: any) {
// only throw if the folder exists
if (e.code !== 'ENOENT') {
throw Error(`Failed to remove ${integrationPath}`)
}
}
}

export function renameSupportFilePath (relative: string) {
Expand Down
7 changes: 7 additions & 0 deletions packages/launchpad/cypress/e2e/migration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ describe('Full migration flow for each project', { retries: { openMode: 2, runMo
renameSupport()
migrateAndVerifyConfig()
finishMigrationAndContinue()

cy.withCtx(async (ctx) => {
const integrationFolderStats = await ctx.actions.file.checkIfFileExists(ctx.path.join('cypress', 'integration'))

expect(integrationFolderStats).to.be.null
})

checkOutcome()
})

Expand Down