Skip to content

@nx/cypress - Generators

The @nx/cypress plugin provides various generators to help you create and configure cypress projects within your Nx workspace. Below is a complete reference for all available generators and their options.

For an overview of the plugin and setup instructions, see the @nx/cypress introduction.

Add a Cypress configuration to an existing project.

This is a generator to add a cypress e2e configuration to an existing project.

Terminal window
nx g @nx/cypress:configuration --project=my-cool-project --devServerTarget=some-app:serve

Running this generator, adds the required files to run cypress tests for a project, Mainly a cypress.config.ts file and default files in the <project-root>/cypress/ directory. Tests will be located in <project-root>/cypress/e2e/* by default.

You can customize the directory used via the --directory flag, the value is relative to the project root.

For example if you wanted to place the files inside an e2e folder

Terminal window
nx g @nx/cypress:configuration --project=my-cool-project --devServerTarget=some-app:serve --directory=e2e

Providing a --devServerTarget is optional if you provide a --baseUrl or the project you’re adding the configuration to has a serve target already. Otherwise, a --devServerTarget is recommend for the @nx/cypress:cypress executor to spin up the dev server for you automatically when needed.

Usage:

Terminal window
nx generate @nx/cypress:configuration [options]

Aliases: cypress-e2e-configuration, e2e, e2e-config

OptionTypeDescriptionDefault
--projectstring [required]The project to add a Cypress configuration to
--baseUrlstringThe address (with the port) which your application is running on. If you wish to start your application when running the e2e target, then use —devServerTarget instead.
--bundlerstringThe Cypress bundler to use."webpack"
--devServerTargetstringA devServerTarget,’:[:], that will be used to run tests against. This is usually the app this project will be used in. Pass —baseUrl if you wish to not use a devServerTarget.
--directorystringA directory where the project is placed relative from the project root"cypress"
--enableTypedLintingbooleanWhether to enable typed linting. For flat configs, this configures the recommended parserOptions.projectService and tsconfigRootDir. For legacy .eslintrc configs, this configures parserOptions.project. We do not enable this by default for lint performance reasons.false
--jsbooleanGenerate JavaScript files rather than TypeScript files.false
--jsxbooleanWhether or not this project uses JSX.true
--linterstringThe tool to use for running lint checks.
--portstringSet the ‘port’ option on the e2e target. It’s recommend to set a different port so you can run tests e2e targets in parallel. Most dev servers support using ‘0’ to automatically find a free port. The value ‘cypress-auto’ can be used if the underlying dev server does not support automatically finding a free port.
--rootProjectbooleanCreate a application at the root of the workspacefalse
--setParserOptionsProjectbooleanDeprecated alias for enableTypedLinting.false
--skipFormatbooleanSkip formatting files.false
--skipPackageJsonbooleanDo not add dependencies to package.json.false

Convert existing Cypress project(s) using @nx/cypress:cypress executor to use @nx/cypress/plugin.

Usage:

Terminal window
nx generate @nx/cypress:convert-to-inferred [options]
OptionTypeDescriptionDefault
--projectstringThe project to convert from using the @nx/cypress:cypress executor to use @nx/cypress/plugin.
--skipFormatbooleanWhether to format files at the end of the migration.false

Migrate Cypress e2e project from v8/v9 to Cypress v11.

Usage:

Terminal window
nx generate @nx/cypress:migrate-to-cypress-11 [options]

You can get help for any generator by adding the --help flag:

Terminal window
nx generate @nx/cypress:<generator> --help