diff --git a/docs/generated/packages/workspace/generators/new.json b/docs/generated/packages/workspace/generators/new.json index b8ea38cd6b2f1..592c94bc15cfb 100644 --- a/docs/generated/packages/workspace/generators/new.json +++ b/docs/generated/packages/workspace/generators/new.json @@ -73,6 +73,11 @@ "description": "Enable experimental app directory for the project", "type": "boolean", "default": false + }, + "e2eTestRunner": { + "description": "The tool to use for running e2e tests.", + "type": "string", + "enum": ["cypress", "jest", "detox", "none"] } }, "additionalProperties": true, diff --git a/docs/generated/packages/workspace/generators/preset.json b/docs/generated/packages/workspace/generators/preset.json index 3b27e1e85f98d..6b00eace00845 100644 --- a/docs/generated/packages/workspace/generators/preset.json +++ b/docs/generated/packages/workspace/generators/preset.json @@ -85,6 +85,11 @@ "description": "Enable experimental app/ for the project", "type": "boolean", "default": false + }, + "e2eTestRunner": { + "description": "The tool to use for running e2e tests.", + "type": "string", + "enum": ["cypress", "jest", "detox", "none"] } }, "presets": [] diff --git a/packages/workspace/src/generators/new/generate-preset.ts b/packages/workspace/src/generators/new/generate-preset.ts index 83e6670c15ed3..ffa9be3b56349 100644 --- a/packages/workspace/src/generators/new/generate-preset.ts +++ b/packages/workspace/src/generators/new/generate-preset.ts @@ -84,6 +84,9 @@ export function generatePreset(host: Tree, opts: NormalizedSchema) { : null, parsedArgs.interactive ? '--interactive=true' : '--interactive=false', opts.routing !== undefined ? `--routing=${opts.routing}` : null, + opts.e2eTestRunner !== undefined + ? `--e2eTestRunner=${opts.e2eTestRunner}` + : null, ].filter((e) => !!e); } } @@ -92,6 +95,7 @@ function getPresetDependencies({ preset, presetVersion, bundler, + e2eTestRunner, }: NormalizedSchema) { switch (preset) { case Preset.TS: @@ -126,7 +130,7 @@ function getPresetDependencies({ dependencies: {}, dev: { '@nx/react': nxVersion, - '@nx/cypress': nxVersion, + '@nx/cypress': e2eTestRunner !== 'none' ? nxVersion : undefined, '@nx/jest': bundler !== 'vite' ? nxVersion : undefined, '@nx/vite': bundler === 'vite' ? nxVersion : undefined, '@nx/webpack': bundler === 'webpack' ? nxVersion : undefined, diff --git a/packages/workspace/src/generators/new/new.ts b/packages/workspace/src/generators/new/new.ts index bb9e7b1397826..9c83395d3a5e7 100644 --- a/packages/workspace/src/generators/new/new.ts +++ b/packages/workspace/src/generators/new/new.ts @@ -30,6 +30,7 @@ interface Schema { standaloneApi?: boolean; routing?: boolean; packageManager?: PackageManager; + e2eTestRunner?: 'cypress' | 'detox' | 'jest' | 'none'; } export interface NormalizedSchema extends Schema { diff --git a/packages/workspace/src/generators/new/schema.json b/packages/workspace/src/generators/new/schema.json index f2c6f4655e641..4a2171424be24 100644 --- a/packages/workspace/src/generators/new/schema.json +++ b/packages/workspace/src/generators/new/schema.json @@ -76,6 +76,11 @@ "description": "Enable experimental app directory for the project", "type": "boolean", "default": false + }, + "e2eTestRunner": { + "description": "The tool to use for running e2e tests.", + "type": "string", + "enum": ["cypress", "jest", "detox", "none"] } }, "additionalProperties": true diff --git a/packages/workspace/src/generators/preset/preset.ts b/packages/workspace/src/generators/preset/preset.ts index f3dc2e3522595..e791a8bff9987 100644 --- a/packages/workspace/src/generators/preset/preset.ts +++ b/packages/workspace/src/generators/preset/preset.ts @@ -33,6 +33,7 @@ async function createPreset(tree: Tree, options: Schema) { linter: options.linter, standalone: options.standaloneApi, routing: options.routing, + e2eTestRunner: options.e2eTestRunner, }); } else if (options.preset === Preset.AngularStandalone) { const { @@ -46,6 +47,7 @@ async function createPreset(tree: Tree, options: Schema) { routing: options.routing, rootProject: true, standalone: options.standaloneApi, + e2eTestRunner: options.e2eTestRunner ?? 'cypress', }); } else if (options.preset === Preset.ReactMonorepo) { const { applicationGenerator: reactApplicationGenerator } = require('@nx' + @@ -56,6 +58,7 @@ async function createPreset(tree: Tree, options: Schema) { style: options.style, linter: options.linter, bundler: options.bundler ?? 'webpack', + e2eTestRunner: options.e2eTestRunner ?? 'cypress', }); } else if (options.preset === Preset.ReactStandalone) { const { applicationGenerator: reactApplicationGenerator } = require('@nx' + @@ -67,7 +70,7 @@ async function createPreset(tree: Tree, options: Schema) { linter: options.linter, rootProject: true, bundler: options.bundler ?? 'vite', - e2eTestRunner: 'cypress', + e2eTestRunner: options.e2eTestRunner ?? 'cypress', unitTestRunner: options.bundler === 'vite' ? 'vitest' : 'jest', }); } else if (options.preset === Preset.NextJs) { @@ -78,6 +81,7 @@ async function createPreset(tree: Tree, options: Schema) { name: options.name, style: options.style, linter: options.linter, + e2eTestRunner: options.e2eTestRunner ?? 'cypress', }); } else if (options.preset === Preset.NextJsStandalone) { const { applicationGenerator: nextApplicationGenerator } = require('@nx' + @@ -98,6 +102,7 @@ async function createPreset(tree: Tree, options: Schema) { style: options.style, linter: options.linter, bundler: 'vite', + e2eTestRunner: options.e2eTestRunner ?? 'cypress', }); } else if (options.preset === Preset.Nest) { const { applicationGenerator: nestApplicationGenerator } = require('@nx' + @@ -106,6 +111,7 @@ async function createPreset(tree: Tree, options: Schema) { return nestApplicationGenerator(tree, { name: options.name, linter: options.linter, + e2eTestRunner: options.e2eTestRunner ?? 'jest', }); } else if (options.preset === Preset.Express) { const { @@ -114,6 +120,7 @@ async function createPreset(tree: Tree, options: Schema) { return expressApplicationGenerator(tree, { name: options.name, linter: options.linter, + e2eTestRunner: options.e2eTestRunner ?? 'jest', }); } else if (options.preset === Preset.ReactNative) { const { reactNativeApplicationGenerator } = require('@nx' + @@ -121,14 +128,14 @@ async function createPreset(tree: Tree, options: Schema) { return reactNativeApplicationGenerator(tree, { name: options.name, linter: options.linter, - e2eTestRunner: 'detox', + e2eTestRunner: options.e2eTestRunner ?? 'detox', }); } else if (options.preset === Preset.Expo) { const { expoApplicationGenerator } = require('@nx' + '/expo'); return expoApplicationGenerator(tree, { name: options.name, linter: options.linter, - e2eTestRunner: 'detox', + e2eTestRunner: options.e2eTestRunner ?? 'detox', }); } else if (options.preset === Preset.TS) { const c = readNxJson(tree); @@ -149,6 +156,7 @@ async function createPreset(tree: Tree, options: Schema) { framework: options.framework, docker: options.docker, rootProject: true, + e2eTestRunner: options.e2eTestRunner ?? 'jest', }); } else { throw new Error(`Invalid preset ${options.preset}`); diff --git a/packages/workspace/src/generators/preset/schema.d.ts b/packages/workspace/src/generators/preset/schema.d.ts index e91c916a785f5..56e3560b8abc6 100644 --- a/packages/workspace/src/generators/preset/schema.d.ts +++ b/packages/workspace/src/generators/preset/schema.d.ts @@ -15,4 +15,5 @@ export interface Schema { nextAppDir?: boolean; routing?: boolean; standaloneApi?: boolean; + e2eTestRunner?: 'cypress' | 'jest' | 'detox' | 'none'; } diff --git a/packages/workspace/src/generators/preset/schema.json b/packages/workspace/src/generators/preset/schema.json index 5fce098d0bf71..9e775f8dded94 100644 --- a/packages/workspace/src/generators/preset/schema.json +++ b/packages/workspace/src/generators/preset/schema.json @@ -88,6 +88,11 @@ "description": "Enable experimental app/ for the project", "type": "boolean", "default": false + }, + "e2eTestRunner": { + "description": "The tool to use for running e2e tests.", + "type": "string", + "enum": ["cypress", "jest", "detox", "none"] } } }