diff --git a/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap b/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap index de153cbf0f1ff0..506f8d22532b81 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap +++ b/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap @@ -20,7 +20,10 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + webServerCommands: { default: 'nx run app1:serve' }, + }), baseUrl: 'http://localhost:4200', }, }); @@ -100,7 +103,10 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + webServerCommands: { default: 'nx run app1:serve' }, + }), baseUrl: 'http://localhost:4200', }, }); diff --git a/packages/cypress/src/generators/configuration/configuration.spec.ts b/packages/cypress/src/generators/configuration/configuration.spec.ts index ddd300ea499480..7fe3031100c3db 100644 --- a/packages/cypress/src/generators/configuration/configuration.spec.ts +++ b/packages/cypress/src/generators/configuration/configuration.spec.ts @@ -118,29 +118,22 @@ describe('Cypress e2e configuration', () => { import { defineConfig } from 'cypress'; export default defineConfig({ - e2e: { ...nxE2EPreset(__filename, { cypressDir: 'src' }) }, + e2e: { + ...nxE2EPreset(__filename, { + cypressDir: 'src', + webServerCommands: { + default: 'nx run my-app:serve', + production: 'nx run my-app:serve:production', + }, + ciWebServerCommand: 'nx run my-app:serve-static', + }), + }, }); " `); - expect(readProjectConfiguration(tree, 'my-app').targets.e2e) - .toMatchInlineSnapshot(` - { - "configurations": { - "ci": { - "devServerTarget": "my-app:serve-static", - }, - "production": { - "devServerTarget": "my-app:serve:production", - }, - }, - "executor": "@nx/cypress:cypress", - "options": { - "cypressConfig": "apps/my-app/cypress.config.ts", - "devServerTarget": "my-app:serve", - "testingType": "e2e", - }, - } - `); + expect( + readProjectConfiguration(tree, 'my-app').targets.e2e + ).toMatchInlineSnapshot(`undefined`); expect(readJson(tree, 'apps/my-app/tsconfig.json')) .toMatchInlineSnapshot(` @@ -185,7 +178,16 @@ describe('Cypress e2e configuration', () => { import { defineConfig } from 'cypress'; export default defineConfig({ - e2e: { ...nxE2EPreset(__filename, { cypressDir: 'cypress' }) }, + e2e: { + ...nxE2EPreset(__filename, { + cypressDir: 'cypress', + webServerCommands: { + default: 'nx run my-app:serve', + production: 'nx run my-app:serve:production', + }, + ciWebServerCommand: 'nx run my-app:serve-static', + }), + }, }); " `); @@ -208,7 +210,14 @@ describe('Cypress e2e configuration', () => { export default defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + webServerCommands: { + default: 'nx run my-app:serve', + production: 'nx run my-app:serve:production', + }, + ciWebServerCommand: 'nx run my-app:serve-static', + }), baseUrl: 'http://localhost:4200', }, }); diff --git a/packages/cypress/src/generators/configuration/configuration.ts b/packages/cypress/src/generators/configuration/configuration.ts index 1d1a18dd58947b..be3b2c514c19d4 100644 --- a/packages/cypress/src/generators/configuration/configuration.ts +++ b/packages/cypress/src/generators/configuration/configuration.ts @@ -27,7 +27,7 @@ import { addLinterToCyProject } from '../../utils/add-linter'; import { addDefaultE2EConfig } from '../../utils/config'; import { installedCypressVersion } from '../../utils/cypress-version'; import { typesNodeVersion, viteVersion } from '../../utils/versions'; -import cypressInitGenerator from '../init/init'; +import cypressInitGenerator, { addPlugin } from '../init/init'; import { addBaseCypressSetup } from '../base-setup/base-setup'; export interface CypressE2EConfigSchema { @@ -67,7 +67,7 @@ export async function configurationGeneratorInternal( options: CypressE2EConfigSchema ) { const opts = normalizeOptions(tree, options); - + opts.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const tasks: GeneratorCallback[] = []; if (!installedCypressVersion()) { @@ -76,10 +76,12 @@ export async function configurationGeneratorInternal( await cypressInitGenerator(tree, { ...opts, skipFormat: true, - addPlugin: options.addPlugin, }) ); + } else if (opts.addPlugin) { + addPlugin(tree); } + const projectGraph = await createProjectGraphAsync(); const nxJson = readNxJson(tree); const hasPlugin = nxJson.plugins?.some((p) => @@ -96,7 +98,6 @@ export async function configurationGeneratorInternal( const linterTask = await addLinterToCyProject(tree, { ...opts, cypressDir: opts.directory, - addPlugin: opts.addPlugin, }); tasks.push(linterTask); @@ -151,7 +152,6 @@ In this case you need to provide a devServerTarget,':[: return { ...options, - addPlugin: options.addPlugin ?? process.env.NX_ADD_PLUGINS !== 'false', bundler: options.bundler ?? 'webpack', rootProject: options.rootProject ?? projectConfig.root === '.', linter: options.linter ?? Linter.EsLint, diff --git a/packages/cypress/src/generators/cypress-project/cypress-project.ts b/packages/cypress/src/generators/cypress-project/cypress-project.ts index f3b74947b28c02..2c7f4016bccd6f 100644 --- a/packages/cypress/src/generators/cypress-project/cypress-project.ts +++ b/packages/cypress/src/generators/cypress-project/cypress-project.ts @@ -283,6 +283,8 @@ async function normalizeOptions( options.linter = options.linter || Linter.EsLint; options.bundler = options.bundler || 'webpack'; + options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; + return { ...options, // other generators depend on the rootProject flag down stream diff --git a/packages/cypress/src/generators/init/init.ts b/packages/cypress/src/generators/init/init.ts index 56f3eb3962ef71..72e794d76b66a8 100644 --- a/packages/cypress/src/generators/init/init.ts +++ b/packages/cypress/src/generators/init/init.ts @@ -55,7 +55,7 @@ function updateDependencies(tree: Tree, options: Schema) { return runTasksInSerial(...tasks); } -function addPlugin(tree: Tree) { +export function addPlugin(tree: Tree) { const nxJson = readNxJson(tree); nxJson.plugins ??= []; @@ -105,7 +105,6 @@ export async function cypressInitGeneratorInternal( options: Schema ) { updateProductionFileset(tree); - options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; if (options.addPlugin) { diff --git a/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap b/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap index 9c79e5d0fb1bbf..e7155b51fa42c0 100644 --- a/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap +++ b/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap @@ -151,7 +151,11 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + webServerCommands: { default: 'nx run test:serve:development' }, + ciWebServerCommand: 'nx run test:serve-static', + }), baseUrl: 'http://localhost:4200', }, }); @@ -661,7 +665,11 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + webServerCommands: { default: 'nx run test:serve:development' }, + ciWebServerCommand: 'nx run test:serve-static', + }), baseUrl: 'http://localhost:4200', }, }); @@ -1027,7 +1035,11 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + webServerCommands: { default: 'nx run test:serve:development' }, + ciWebServerCommand: 'nx run test:serve-static', + }), baseUrl: 'http://localhost:4200', }, }); diff --git a/packages/vue/src/generators/application/application.ts b/packages/vue/src/generators/application/application.ts index ba9f2e8b3a63dc..f6efb1b7f944ee 100644 --- a/packages/vue/src/generators/application/application.ts +++ b/packages/vue/src/generators/application/application.ts @@ -28,6 +28,8 @@ export async function applicationGeneratorInternal( _options: Schema ): Promise { const options = await normalizeOptions(tree, _options); + options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; + const tasks: GeneratorCallback[] = []; addProjectConfiguration(tree, options.name, { diff --git a/packages/vue/src/generators/application/lib/add-e2e.ts b/packages/vue/src/generators/application/lib/add-e2e.ts index 600dbef16ececa..aceb81f9a6796f 100644 --- a/packages/vue/src/generators/application/lib/add-e2e.ts +++ b/packages/vue/src/generators/application/lib/add-e2e.ts @@ -64,6 +64,7 @@ export async function addE2e( implicitDependencies: [options.projectName], }); return configurationGenerator(tree, { + ...options, project: options.e2eProjectName, skipFormat: true, skipPackageJson: options.skipPackageJson,