diff --git a/packages/cypress/src/generators/configuration/configuration.spec.ts b/packages/cypress/src/generators/configuration/configuration.spec.ts index 43f0d6363062f..7d411ebba82c1 100644 --- a/packages/cypress/src/generators/configuration/configuration.spec.ts +++ b/packages/cypress/src/generators/configuration/configuration.spec.ts @@ -43,6 +43,11 @@ describe('Cypress e2e configuration', () => { await cypressE2EConfigurationGenerator(tree, { project: 'my-app', baseUrl: 'http://localhost:4200', + webServerCommands: { + default: 'nx run my-app:serve', + production: 'nx run my-app:serve:production', + }, + ciWebServerCommand: 'nx run my-app:serve-static', }); expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` diff --git a/packages/cypress/src/generators/configuration/configuration.ts b/packages/cypress/src/generators/configuration/configuration.ts index 40a9876d0572d..6885065af980b 100644 --- a/packages/cypress/src/generators/configuration/configuration.ts +++ b/packages/cypress/src/generators/configuration/configuration.ts @@ -40,6 +40,9 @@ export interface CypressE2EConfigSchema { port?: number | 'cypress-auto'; jsx?: boolean; rootProject?: boolean; + + webServerCommands?: Record; + ciWebServerCommand?: string; } type NormalizedSchema = ReturnType; @@ -166,9 +169,12 @@ async function addFiles( const cyFile = joinPathFragments(projectConfig.root, 'cypress.config.ts'); let webServerCommands: Record; - let ciDevServerTarget: string; + let ciWebServerCommand: string; - if (hasPlugin && options.devServerTarget) { + if (hasPlugin && options.webServerCommands && options.ciWebServerCommand) { + webServerCommands = options.webServerCommands; + ciWebServerCommand = options.ciWebServerCommand; + } else if (hasPlugin && options.devServerTarget) { webServerCommands = {}; webServerCommands.default = 'nx run ' + options.devServerTarget; @@ -192,7 +198,7 @@ async function addFiles( } // Add ci/static e2e target if serve target is found if (devServerProjectConfig.targets?.['serve-static']) { - ciDevServerTarget = `nx run ${parsedTarget.project}:serve-static`; + ciWebServerCommand = `nx run ${parsedTarget.project}:serve-static`; } } const updatedCyConfig = await addDefaultE2EConfig( @@ -201,7 +207,7 @@ async function addFiles( cypressDir: options.directory, bundler: options.bundler === 'vite' ? 'vite' : undefined, webServerCommands, - ciWebServerCommand: ciDevServerTarget, + ciWebServerCommand: ciWebServerCommand, }, options.baseUrl ); diff --git a/packages/nx/src/nx-cloud/update-manager.ts b/packages/nx/src/nx-cloud/update-manager.ts index be98d0021d36e..945fa7de8626c 100644 --- a/packages/nx/src/nx-cloud/update-manager.ts +++ b/packages/nx/src/nx-cloud/update-manager.ts @@ -315,7 +315,8 @@ async function downloadAndExtractClientBundle( const writeStream = createWriteStream(outputFilePath); stream.pipe(writeStream); - stream.on('end', function () { + // Continue the tar stream after the write stream closes + writeStream.on('close', () => { next(); }); diff --git a/packages/react/src/generators/application/lib/add-e2e.ts b/packages/react/src/generators/application/lib/add-e2e.ts index 2b58d966331d6..80bb1c2fe61c6 100644 --- a/packages/react/src/generators/application/lib/add-e2e.ts +++ b/packages/react/src/generators/application/lib/add-e2e.ts @@ -18,10 +18,10 @@ export async function addE2e( ): Promise { switch (options.e2eTestRunner) { case 'cypress': { - if ( - (options.bundler === 'webpack' && !hasWebpackPlugin(tree)) || - (options.bundler === 'vite' && !hasVitePlugin(tree)) - ) { + const hasNxBuildPlugin = + (options.bundler === 'webpack' && hasWebpackPlugin(tree)) || + (options.bundler === 'vite' && hasVitePlugin(tree)); + if (!hasNxBuildPlugin) { webStaticServeGenerator(tree, { buildTarget: `${options.projectName}:build`, targetName: 'serve-static', @@ -52,6 +52,15 @@ export async function addE2e( baseUrl: 'http://localhost:4200', jsx: true, rootProject: options.rootProject, + webServerCommands: hasNxBuildPlugin + ? { + default: `nx run ${options.projectName}:serve`, + production: `nx run ${options.projectName}:preview`, + } + : undefined, + ciWebServerCommand: hasNxBuildPlugin + ? `nx run ${options.projectName}:serve-static` + : undefined, }); } case 'playwright': {