Skip to content

Commit

Permalink
fix(testing): handle cypress-project generation for standalone projec…
Browse files Browse the repository at this point in the history
…ts (#13602)
  • Loading branch information
barbados-clemens authored Dec 5, 2022
1 parent 8560453 commit 6f8a849
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
6 changes: 0 additions & 6 deletions docs/generated/packages/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
22 changes: 20 additions & 2 deletions packages/cypress/src/generators/cypress-project/cypress-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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,
};
Expand Down
6 changes: 0 additions & 6 deletions packages/cypress/src/generators/cypress-project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

1 comment on commit 6f8a849

@vercel
Copy link

@vercel vercel bot commented on 6f8a849 Dec 5, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.