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: scaffold commands file #20398

Merged
merged 8 commits into from
Mar 2, 2022
8 changes: 5 additions & 3 deletions packages/data-context/src/actions/WizardActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class WizardActions {
const scaffolded = await Promise.all([
this.scaffoldConfig('e2e'),
this.scaffoldSupport('e2e', this.ctx.coreData.wizard.chosenLanguage),
this.scaffoldSupport('commands', this.ctx.coreData.wizard.chosenLanguage),
this.scaffoldFixtures(),
])

Expand All @@ -187,26 +188,27 @@ export class WizardActions {
this.scaffoldConfig('component'),
this.scaffoldFixtures(),
this.scaffoldSupport('component', chosenLanguage.type),
this.scaffoldSupport('commands', chosenLanguage.type),
this.getComponentIndexHtml({
chosenFramework,
chosenLanguage,
}),
])
}

private async scaffoldSupport (fileName: 'e2e' | 'component', language: CodeLanguageEnum): Promise<NexusGenObjects['ScaffoldedFile']> {
private async scaffoldSupport (fileName: 'e2e' | 'component' | 'commands', language: CodeLanguageEnum): Promise<NexusGenObjects['ScaffoldedFile']> {
const supportFile = path.join(this.projectRoot, `cypress/support/${fileName}.${language}`)
const supportDir = path.dirname(supportFile)

// @ts-ignore
await this.ctx.fs.mkdir(supportDir, { recursive: true })
await this.scaffoldFile(supportFile, dedent`
// TODO: source the example support file
// TODO: source the example ${fileName === 'commands' ? 'commands' : 'support'} file
`, 'Scaffold default support file')

return {
status: 'valid',
description: 'Added a support file, for extending the Cypress api',
description: `Added a ${fileName === 'commands' ? 'commands' : 'support'} file, for extending the Cypress api`,
file: {
absolute: supportFile,
},
Expand Down
8 changes: 8 additions & 0 deletions packages/launchpad/cypress/e2e/project-setup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ describe('Launchpad: Setup Project', () => {

cy.get('[data-cy=valid]').within(() => {
cy.containsPath('cypress/support/e2e.js')
cy.containsPath('cypress/support/commands.js')
cy.containsPath('cypress/fixtures/example.json')
})
})
Expand All @@ -217,6 +218,7 @@ describe('Launchpad: Setup Project', () => {

cy.get('[data-cy=valid]').within(() => {
cy.containsPath('cypress/support/e2e.js')
cy.containsPath('cypress/support/commands.js')
cy.containsPath('cypress/fixtures/example.json')
})
})
Expand All @@ -234,6 +236,7 @@ describe('Launchpad: Setup Project', () => {

cy.get('[data-cy=valid]').within(() => {
cy.containsPath('cypress/support/e2e.js')
cy.containsPath('cypress/support/commands.js')
cy.containsPath('cypress/fixtures/example.json')
})
})
Expand Down Expand Up @@ -282,6 +285,7 @@ describe('Launchpad: Setup Project', () => {
cy.get('[data-cy=valid]').within(() => {
cy.contains('cypress.config.js')
cy.containsPath('cypress/support/e2e.js')
cy.containsPath('cypress/support/commands.js')
cy.containsPath('cypress/fixtures/example.json')
})

Expand Down Expand Up @@ -400,6 +404,7 @@ describe('Launchpad: Setup Project', () => {
cy.get('[data-cy=valid]').within(() => {
cy.containsPath('cypress/component/index.html')
cy.containsPath('cypress/support/component.ts')
cy.containsPath('cypress/support/commands.ts')
})

cy.findByRole('button', { name: 'Continue' }).should('have.disabled')
Expand All @@ -418,6 +423,7 @@ describe('Launchpad: Setup Project', () => {

cy.get('[data-cy=valid]').within(() => {
cy.containsPath('cypress/support/e2e.js')
cy.containsPath('cypress/support/commands.js')
cy.containsPath('cypress/fixtures/example.json')
})
})
Expand Down Expand Up @@ -737,6 +743,7 @@ describe('Launchpad: Setup Project', () => {
cy.contains('cypress.config.ts')
cy.containsPath('cypress/component/index.html')
cy.containsPath(`cypress/support/component.ts`)
cy.containsPath(`cypress/support/commands.ts`)
Copy link
Contributor

@lmiller1990 lmiller1990 Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we take this chance to add some tests to actually verify the file is created on the filesystem? These tests just verify we show the file we will create in the UI, not that they are actually written.

We have a pattern for this, see this function: https://github.com/cypress-io/cypress/blob/10.0-release/packages/launchpad/cypress/e2e/scaffold-component-testing.cy.ts#L11-L19 . This one actually verifies the content, too (might be worth doing something similar here?)

I also notice the support/component.ts contains // TODO - might be worth finding out what needs to go here and adding that, too? What do you think?

cy.containsPath('cypress/fixtures/example.json')
})

Expand Down Expand Up @@ -769,6 +776,7 @@ describe('Launchpad: Setup Project', () => {
cy.contains('cypress.config.ts')
cy.containsPath('cypress/component/index.html')
cy.containsPath(`cypress/support/component.ts`)
cy.containsPath(`cypress/support/commands.ts`)
cy.containsPath('cypress/fixtures/example.json')
})

Expand Down