From 3260f4166abc3e7379aca35e09381de8ff9f7752 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Wed, 6 Mar 2024 12:53:02 -0500 Subject: [PATCH] fix(testing): fix project config might not be defined (#22174) --- .../cypress/src/generators/configuration/configuration.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/cypress/src/generators/configuration/configuration.ts b/packages/cypress/src/generators/configuration/configuration.ts index 999cb5faca921..80049da8e52c9 100644 --- a/packages/cypress/src/generators/configuration/configuration.ts +++ b/packages/cypress/src/generators/configuration/configuration.ts @@ -125,7 +125,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.`); @@ -134,7 +135,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,':[:]', or a baseUrl option`); @@ -144,7 +145,7 @@ In this case you need to provide a devServerTarget,':[: 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');