diff --git a/docs/generated/packages/cypress.json b/docs/generated/packages/cypress.json index b9cc223a5cc79..69c9b5c26d1d3 100644 --- a/docs/generated/packages/cypress.json +++ b/docs/generated/packages/cypress.json @@ -111,12 +111,6 @@ "type": "boolean", "default": false, "description": "Do not add dependencies to `package.json`." - }, - "rootProject": { - "description": "Create a application at the root of the workspace", - "type": "boolean", - "default": false, - "hidden": true } }, "required": ["name"], diff --git a/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts b/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts index ff77c2858f205..89892dcc0e95d 100644 --- a/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts +++ b/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts @@ -245,6 +245,32 @@ describe('Cypress Project', () => { const tsConfig = readJson(tree, 'apps/my-dir/my-app-e2e/tsconfig.json'); expect(tsConfig.extends).toBe('../../../tsconfig.json'); }); + + describe('root project', () => { + it('should generate in option.name when root project detected', async () => { + addProjectConfiguration(tree, 'root', { + root: '.', + }); + await cypressProjectGenerator(tree, { + ...defaultOptions, + name: 'e2e-tests', + baseUrl: 'http://localhost:1234', + project: 'root', + rootProject: true, + }); + expect(tree.listChanges().map((c) => c.path)).toEqual( + expect.arrayContaining([ + 'e2e-tests/cypress.config.ts', + 'e2e-tests/src/e2e/app.cy.ts', + 'e2e-tests/src/fixtures/example.json', + 'e2e-tests/src/support/app.po.ts', + 'e2e-tests/src/support/commands.ts', + 'e2e-tests/src/support/e2e.ts', + 'e2e-tests/tsconfig.json', + ]) + ); + }); + }); }); describe('--project', () => { diff --git a/packages/cypress/src/generators/cypress-project/cypress-project.ts b/packages/cypress/src/generators/cypress-project/cypress-project.ts index 6b048d0ac7b4c..243d547ce1b11 100644 --- a/packages/cypress/src/generators/cypress-project/cypress-project.ts +++ b/packages/cypress/src/generators/cypress-project/cypress-project.ts @@ -16,6 +16,7 @@ import { toJS, Tree, updateJson, + getProjects, } from '@nrwl/devkit'; import { Linter, lintProjectGenerator } from '@nrwl/linter'; import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial'; @@ -285,11 +286,26 @@ function normalizeOptions(host: Tree, options: Schema): CypressProjectSchema { options.directory ); const appsDir = layoutDirectory ?? getWorkspaceLayout(host).appsDir; - let projectName, projectRoot; + let projectName: string; + let projectRoot: string; + let maybeRootProject: ProjectConfiguration; + let isRootProject = false; - if (options.rootProject) { + const projects = getProjects(host); + // nx will set the project option for generators when ran within a project. + // since the root project will always be set for standlone projects we can just check it here. + if (options.project) { + maybeRootProject = projects.get(options.project); + } + + if ( + maybeRootProject?.root === '.' || + // should still check to see if we are in a standalone based workspace + Array.from(projects.values()).some((config) => config.root === '.') + ) { projectName = options.name; projectRoot = options.name; + isRootProject = true; } else { projectName = filePathPrefix( projectDirectory ? `${projectDirectory}-${options.name}` : options.name @@ -306,6 +322,8 @@ function normalizeOptions(host: Tree, options: Schema): CypressProjectSchema { options.linter = options.linter || Linter.EsLint; return { ...options, + // other generators depend on the rootProject flag down stream + rootProject: isRootProject, projectName, projectRoot, }; diff --git a/packages/cypress/src/generators/cypress-project/schema.json b/packages/cypress/src/generators/cypress-project/schema.json index 0888c92ab5abd..18ede4e4bd3d5 100644 --- a/packages/cypress/src/generators/cypress-project/schema.json +++ b/packages/cypress/src/generators/cypress-project/schema.json @@ -59,12 +59,6 @@ "type": "boolean", "default": false, "description": "Do not add dependencies to `package.json`." - }, - "rootProject": { - "description": "Create a application at the root of the workspace", - "type": "boolean", - "default": false, - "hidden": true } }, "required": ["name"],