From c2be2ade1a46397b26af3e2c0f4b9112c0c454d1 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Thu, 7 Dec 2023 16:10:17 -0500 Subject: [PATCH 1/2] =?UTF-8?q?fix(testing):=20add=20webServerCommands/ciW?= =?UTF-8?q?ebServerCommands=20option=20for=20cy=E2=80=A6=20(#20616)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/configuration.spec.ts | 5 +++++ .../generators/configuration/configuration.ts | 14 ++++++++++---- .../src/generators/application/lib/add-e2e.ts | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) 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/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': { From 61429c05a6069ef326755f50f8668852f4adc831 Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Thu, 7 Dec 2023 16:17:43 -0500 Subject: [PATCH 2/2] fix(core): listen to the write stream end unpacking lite client (#20642) --- packages/nx/src/nx-cloud/update-manager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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(); });