diff --git a/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.spec.ts b/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.spec.ts index 86cba0f3da..8716bfd725 100644 --- a/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.spec.ts +++ b/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.spec.ts @@ -121,6 +121,11 @@ function createTestProject( testingType: `e2e`, devServerTarget: 'myapp:serve', }, + configurations: { + ci: { + devServerTarget: 'myapp:static-serve', + }, + }, }, }, }; @@ -263,6 +268,7 @@ describe('Cypress - Convert Executors To Plugin', () => { ); expect(hasCypressPlugin).toBeTruthy(); if (typeof hasCypressPlugin !== 'string') { + expect(hasCypressPlugin.include).not.toBeDefined(); [ ['targetName', 'e2e'], ['ciTargetName', 'e2e-ci'], @@ -272,6 +278,21 @@ describe('Cypress - Convert Executors To Plugin', () => { ); }); } + + // cypress.config.ts modifications + expect(tree.read(`${project.root}/cypress.config.ts`, 'utf-8')) + .toMatchInlineSnapshot(` + "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; + + import { defineConfig } from 'cypress'; + + export default defineConfig({ + e2e: { + ...nxE2EPreset(__filename, {ciWebServerCommand: "npx nx run myapp:static-serve",webServerCommands: {"default":"npx nx run myapp:serve","ci":"npx nx run myapp:static-serve"}, cypressDir: 'src' }), + baseUrl: 'http://localhost:4200', + }, + });" + `); }); it('should setup Cypress plugin to match projects', async () => { @@ -429,12 +450,12 @@ describe('Cypress - Convert Executors To Plugin', () => { // project.json modifications const updatedProject = readProjectConfiguration(tree, project.name); expect(updatedProject.targets.e2e).toMatchInlineSnapshot(` - { - "options": { - "runner-ui": true, - }, - } - `); + { + "options": { + "runner-ui": true, + }, + } + `); // nx.json modifications const nxJsonPlugins = readNxJson(tree).plugins; @@ -475,12 +496,12 @@ describe('Cypress - Convert Executors To Plugin', () => { // project.json modifications const updatedProject = readProjectConfiguration(tree, project.name); expect(updatedProject.targets.e2e).toMatchInlineSnapshot(` - { - "options": { - "no-exit": true, - }, - } - `); + { + "options": { + "no-exit": true, + }, + } + `); // nx.json modifications const nxJsonPlugins = readNxJson(tree).plugins; diff --git a/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.ts b/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.ts index dabdbe82c2..1ded42517c 100644 --- a/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.ts +++ b/packages/cypress/src/generators/convert-to-inferred/convert-to-inferred.ts @@ -120,7 +120,7 @@ function postTargetTransformer( tree, configFilePath, webServerCommands, - target.configurations?.ci?.devServerTarget + webServerCommands?.['ci'] ); } diff --git a/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.spec.ts b/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.spec.ts index 9c4491311c..7130bec567 100644 --- a/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.spec.ts +++ b/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.spec.ts @@ -115,7 +115,7 @@ export default defineConfig({ tree, configFilePath, { default: 'npx nx run myorg:serve' }, - 'myorg:static-serve' + 'npx nx run myorg:static-serve' ); // ASSERT @@ -151,7 +151,7 @@ export default defineConfig({ tree, configFilePath, { default: 'npx nx run myorg:serve' }, - 'myorg:static-serve' + 'npx nx run myorg:static-serve' ); // ASSERT @@ -191,7 +191,7 @@ export default defineConfig({ production: 'npx nx run myorg:serve:production', ci: 'npx nx run myorg-static-serve', }, - 'myorg:static-serve' + 'npx nx run myorg:static-serve' ); // ASSERT diff --git a/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.ts b/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.ts index b069f4df48..55ca064ea2 100644 --- a/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.ts +++ b/packages/cypress/src/generators/convert-to-inferred/lib/add-dev-server-target-to-config.ts @@ -85,7 +85,7 @@ export function addDevServerTargetToConfig( `${configFileContents.slice( 0, ciWebServerCommandNode.getStart() - )}"npx nx run ${ciDevServerTarget}"${configFileContents.slice( + )}"${ciDevServerTarget}"${configFileContents.slice( ciWebServerCommandNode.getEnd() )}` ); @@ -96,7 +96,7 @@ export function addDevServerTargetToConfig( `${configFileContents.slice( 0, nxE2ePresetOptionsNode.getStart() + 1 - )}ciWebServerCommand: "npx nx run ${ciDevServerTarget}",${configFileContents.slice( + )}ciWebServerCommand: "${ciDevServerTarget}",${configFileContents.slice( nxE2ePresetOptionsNode.getStart() + 1 )}` ); diff --git a/packages/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator.ts b/packages/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator.ts index 4e2c9faddc..5f50d79e3f 100644 --- a/packages/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator.ts +++ b/packages/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator.ts @@ -201,6 +201,19 @@ class ExecutorToPluginMigrator { } if (!existingPlugin) { + const allConfigFilesAreIncluded = this.#configFiles.every( + (configFile) => { + for (const includePattern of plugin.include) { + if (minimatch(configFile, includePattern, { dot: true })) { + return true; + } + } + return false; + } + ); + if (allConfigFilesAreIncluded) { + plugin.include = undefined; + } this.#nxJson.plugins.push(plugin); } }