Skip to content

Commit

Permalink
fix(testing): fix project config might not be defined (#22174)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3260f41)
  • Loading branch information
xiongemi authored and FrozenPandaz committed Mar 8, 2024
1 parent d3b9b21 commit 0668193
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ function ensureDependencies(tree: Tree, options: NormalizedSchema) {
}

function normalizeOptions(tree: Tree, options: CypressE2EConfigSchema) {
const projectConfig = readProjectConfiguration(tree, options.project);
const projectConfig: ProjectConfiguration | undefined =
readProjectConfiguration(tree, options.project);
if (projectConfig?.targets?.e2e) {
throw new Error(`Project ${options.project} already has an e2e target.
Rename or remove the existing e2e target.`);
Expand All @@ -131,7 +132,7 @@ Rename or remove the existing e2e target.`);
if (
!options.baseUrl &&
!options.devServerTarget &&
!projectConfig.targets.serve
!projectConfig?.targets?.serve
) {
throw new Error(`The project ${options.project} does not have a 'serve' target.
In this case you need to provide a devServerTarget,'<projectName>:<targetName>[:<configName>]', or a baseUrl option`);
Expand All @@ -141,7 +142,7 @@ In this case you need to provide a devServerTarget,'<projectName>:<targetName>[:

const devServerTarget =
options.devServerTarget ??
(projectConfig.targets.serve ? `${options.project}:serve` : undefined);
(projectConfig?.targets?.serve ? `${options.project}:serve` : undefined);

if (!options.baseUrl && !devServerTarget) {
throw new Error('Either baseUrl or devServerTarget must be provided');
Expand Down

0 comments on commit 0668193

Please sign in to comment.