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(testing): provide descriptive message when project is missing targets for cypress-project generator #9795

Merged
merged 1 commit into from Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -413,6 +413,23 @@ describe('schematic:cypress-project', () => {
expect(projectConfig.tags).toEqual([]);
});
});

it('should not throw an error when --project does not have targets', async () => {
const projectConf = readProjectConfiguration(tree, 'my-app');
delete projectConf.targets;

updateProjectConfiguration(tree, 'my-app', projectConf);
await cypressProjectGenerator(tree, {
name: 'my-app-e2e',
project: 'my-app',
linter: Linter.EsLint,
});

const projectConfig = readProjectConfiguration(tree, 'my-app-e2e');
expect(projectConfig.targets['e2e'].options.devServerTarget).toEqual(
'my-app:serve'
);
});
});

describe('--linter', () => {
Expand Down
Expand Up @@ -13,6 +13,8 @@ import {
Tree,
updateJson,
ProjectConfiguration,
stripIndents,
logger,
} from '@nrwl/devkit';
import { Linter, lintProjectGenerator } from '@nrwl/linter';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
Expand Down Expand Up @@ -82,8 +84,15 @@ function addProject(tree: Tree, options: CypressProjectSchema) {
};
} else if (options.project) {
const project = readProjectConfiguration(tree, options.project);

if (!project.targets) {
logger.warn(stripIndents`
NOTE: Project, "${options.project}", does not have any targets defined and a baseUrl was not provided. Nx will use
"${options.project}:serve" as the devServerTarget. But you may need to define this target within the project, "${options.project}".
`);
}
const devServerTarget =
project.targets.serve && project.targets.serve.defaultConfiguration
project.targets?.serve && project.targets?.serve?.defaultConfiguration
? `${options.project}:serve:${project.targets.serve.defaultConfiguration}`
: `${options.project}:serve`;
e2eProjectConfig = {
Expand Down