|
| 1 | +import type { FRONTEND_FRAMEWORKS } from '@packages/scaffold-config' |
| 2 | +import type { SnapshotScaffoldTestResult } from '@packages/launchpad/cypress/tasks/snapshotsScaffold' |
| 3 | + |
| 4 | +// The tests in this file take an existing project without Cypress Configured |
| 5 | +// and add Cypress using the launchpad setup wizard. |
| 6 | +// |
| 7 | +// See `system-tests/projects/pristine` for an example. |
| 8 | +// |
| 9 | +// After adding a test for a project for the first time and running |
| 10 | +// this spec, it will see what files are scaffolded and save them |
| 11 | +// in a directory named `expected-cypress-{lang}-{testingType}`. |
| 12 | +// For example, when configuring the `pristine` project using |
| 13 | +// plain JS for E2E testing, it will make |
| 14 | +// a new directory in `pristine` named `expected-cypress-js-e2e` |
| 15 | +// containing the scaffolded files. |
| 16 | +// |
| 17 | +// Each subsequent run will compare the scaffolded files in the |
| 18 | +// `expected-cypress-js-e2e` directory to the newly created ones. |
| 19 | +// |
| 20 | +// If there is a discrepancy, the test will fail and show the diff in the command log. |
| 21 | +// |
| 22 | +// To update your expected files, just delete the `expected-cypress` and re-run the test, |
| 23 | +// or modify them by hand. |
| 24 | +function scaffoldAndOpenE2EProject ( |
| 25 | + name: Parameters<typeof cy.scaffoldProject>[0], |
| 26 | + language: 'js' | 'ts', |
| 27 | + args?: Parameters<typeof cy.openProject>[1], |
| 28 | +) { |
| 29 | + cy.scaffoldProject(name) |
| 30 | + cy.openProject(name, args) |
| 31 | + |
| 32 | + cy.visitLaunchpad() |
| 33 | + |
| 34 | + cy.contains('Welcome to Cypress!').should('be.visible') |
| 35 | + cy.contains('[data-cy-testingtype="e2e"]', 'Not Configured') |
| 36 | + cy.contains('[data-cy-testingtype="component"]', 'Not Configured') |
| 37 | + cy.contains('E2E Testing').click() |
| 38 | + cy.contains(language === 'js' ? 'JavaScript' : 'TypeScript').click() |
| 39 | + cy.contains('Next').click() |
| 40 | + cy.contains('We added the following files to your project.') |
| 41 | + cy.contains('Continue').click() |
| 42 | + cy.contains('Choose a Browser') |
| 43 | +} |
| 44 | + |
| 45 | +function scaffoldAndOpenCTProject ( |
| 46 | + name: Parameters<typeof cy.scaffoldProject>[0], |
| 47 | + language: 'js' | 'ts', |
| 48 | + framework: typeof FRONTEND_FRAMEWORKS[number]['name'], |
| 49 | + bundler?: typeof FRONTEND_FRAMEWORKS[number]['supportedBundlers'][number]['name'], |
| 50 | + args?: Parameters<typeof cy.openProject>[1], |
| 51 | +) { |
| 52 | + cy.scaffoldProject(name) |
| 53 | + cy.openProject(name, args) |
| 54 | + |
| 55 | + cy.visitLaunchpad() |
| 56 | + |
| 57 | + cy.contains('Welcome to Cypress!').should('be.visible') |
| 58 | + cy.contains('[data-cy-testingtype="e2e"]', 'Not Configured') |
| 59 | + cy.contains('[data-cy-testingtype="component"]', 'Not Configured') |
| 60 | + cy.contains('Component Testing').click() |
| 61 | + cy.contains(language === 'js' ? 'JavaScript' : 'TypeScript').click() |
| 62 | + |
| 63 | + cy.contains('Pick a framework').click() |
| 64 | + cy.contains(framework).click() |
| 65 | + if (bundler) { |
| 66 | + cy.contains(bundler).click() |
| 67 | + } |
| 68 | + |
| 69 | + cy.contains('Next Step').click() |
| 70 | + cy.contains('Skip').click() |
| 71 | + cy.contains('We added the following files to your project.') |
| 72 | + cy.contains('Continue').click() |
| 73 | + cy.contains('Choose a Browser') |
| 74 | +} |
| 75 | + |
| 76 | +function assertScaffoldedFilesAreCorrect (language: 'js' | 'ts', testingType: Cypress.TestingType, ctFramework?: string) { |
| 77 | + cy.withCtx((ctx) => ctx.currentProject).then((currentProject) => { |
| 78 | + cy.task<SnapshotScaffoldTestResult>('snapshotCypressDirectory', { |
| 79 | + currentProject, |
| 80 | + testingType, |
| 81 | + language, |
| 82 | + ctFramework, |
| 83 | + }) |
| 84 | + .then((result) => { |
| 85 | + if (result.status === 'ok') { |
| 86 | + return result |
| 87 | + } |
| 88 | + |
| 89 | + throw new Error(result.message) |
| 90 | + }) |
| 91 | + .then((res) => { |
| 92 | + cy.log(`✅ ${res.message}`) |
| 93 | + }) |
| 94 | + }) |
| 95 | +} |
| 96 | + |
| 97 | +describe('scaffolding new projects', () => { |
| 98 | + it('scaffolds E2E for a JS project', () => { |
| 99 | + scaffoldAndOpenE2EProject('pristine', 'js') |
| 100 | + assertScaffoldedFilesAreCorrect('js', 'e2e') |
| 101 | + }) |
| 102 | + |
| 103 | + it('scaffolds E2E for a TS project', () => { |
| 104 | + scaffoldAndOpenE2EProject('pristine', 'ts') |
| 105 | + assertScaffoldedFilesAreCorrect('ts', 'e2e') |
| 106 | + }) |
| 107 | + |
| 108 | + it('scaffolds CT for a JS project', () => { |
| 109 | + scaffoldAndOpenCTProject('pristine', 'js', 'Create React App (v5)') |
| 110 | + assertScaffoldedFilesAreCorrect('js', 'component', 'Create React App (v5)') |
| 111 | + }) |
| 112 | + |
| 113 | + it('scaffolds CT for a TS project', () => { |
| 114 | + scaffoldAndOpenCTProject('pristine', 'ts', 'Create React App (v5)') |
| 115 | + assertScaffoldedFilesAreCorrect('ts', 'component', 'Create React App (v5)') |
| 116 | + }) |
| 117 | +}) |
0 commit comments