For an existing Nx React app, use Nx’s Cypress generators to configure end-to-end (e2e) tests, component tests, or both. Run e2e tests with nx e2e and component tests with nx component-test; use the project names and build target from your workspace rather than copying the placeholders below.
Choose e2e tests, component tests, or both
These are separate Cypress workflows in Nx, with different targets and server setup.
As an Amazon Associate I earn from qualifying purchases.
- E2e tests exercise the application through a configured app URL or development server. They are suited to checking user flows across the running app.
- Component tests focus on React components using Cypress’s component-testing setup. Nx uses a selected build target to prepare the configuration, while Cypress creates the component dev server.
The appropriate choice depends on what behavior you need to verify. Nx documents distinct generators for the two paths; a workspace can configure either or both.
Configure Cypress e2e testing for an existing app
-
From the workspace root, generate an e2e configuration for the app:
#1 Best Overall
nx g @nx/cypress:configuration --project=your-app-nameReplace
your-app-namewith the project name in your Nx workspace. -
If Cypress should test an already-running URL rather than serve the app through its configured target, supply a base URL, for example:
nx g @nx/cypress:configuration --project=your-app-name --baseUrl=http://localhost:4200Use the actual URL and port for your app. Whether you need this option depends on the generated configuration and how the app is served.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Run the generated e2e project:
nx e2e your-e2e-projectUse the e2e project name created in your workspace; it may not be the same as the React app’s project name.
Run a focused spec or open Cypress
Nx documents headless execution as the default for e2e runs. To narrow a run to a spec, pass a spec glob supported by the configured target, such as:
nx e2e your-e2e-project --spec="src/e2e/smoke.cy.ts"
Check your generated project’s spec path and Cypress configuration if that example does not match your files. For interactive work, Nx documents opening Cypress and watch-mode workflows; the exact target options can depend on the generated configuration and installed versions.
Configure React component testing
-
Generate component-testing configuration for the React project:
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.nx g @nx/react:cypress-component-configuration --project=your-projectReplace
your-projectwith the React project name in the workspace. -
Inspect the generated
component-testtarget and confirm that Nx selected the intended build target. If inference is unavailable or you need a particular build configuration, pass one explicitly. For example:Rank #4
nx g @nx/react:cypress-component-configuration --project=my-react-app --build-target=my-react-app:buildA configuration-specific target can be written as
my-app:build:production. Choose a target that exists in your workspace and matches the app’s bundler and build setup. -
To ask the generator to add tests for existing components, include
--generate-tests:Recommended: Fix Windows Errors and Clear Junk Files in Minutes - Free Scan →Recommended: Update Every Outdated Driver on Your PC in One Scan - Free →Recommended: PC Feels Slow? A Free Scan Shows What's Dragging Windows Down →Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.nx g @nx/react:cypress-component-configuration --project=your-project --generate-tests -
Run the component-test target:
nx component-test your-project
Why the component-test target uses skipServe: true
Check that the generated component-test target has skipServe: true. For component testing, Cypress creates its own dev server, so Nx should not try to run the target as a server. Nx still uses the selected build target to prepare Cypress configuration. Confirm the generated settings against the project’s actual bundler and build target.
Best Value
Run Nx and Cypress in local development and CI
For local iteration, start with a focused e2e spec or component-test target, then run the full configured target when you want broader coverage. E2e execution is headless by default according to Nx’s guide; the guide also describes interactive Cypress, watch mode, and spec selection.
The Nx Cypress plugin provides inferred target names for e2e and component testing. Nx documents caching for e2e and component-test tasks, including tracking Cypress screenshot and video outputs. These behaviors depend on the project and plugin configuration, so inspect the targets Nx recognizes in your repository before relying on them in CI.
For CI task splitting, Nx documents an e2e configuration option named ciWebServerCommand in cypress.config.ts. Configure it for the CI environment and your app’s server command; do not assume a copied command will fit every workspace.
Troubleshoot common setup problems
- The e2e target cannot reach the app: Check whether the generated configuration serves the app or expects an existing URL. If it expects a URL, set the correct
--baseUrland ensure the app is running at that address. nx e2ecannot find the project: Use the generated e2e project name, not automatically the React app name. Inspect the workspace’s project and target configuration.- The component-test generator cannot select a build target: Pass an explicit
--build-targetthat exists in the workspace, such asmy-react-app:build, and check that it matches the app’s bundler and configuration. - Component tests fail during server setup: Confirm the component-test target has
skipServe: trueand that its build target is valid. Cypress, not Nx, owns the component dev server in this workflow. - A spec-selection command finds no tests: Verify the spec path and pattern against the generated Cypress configuration and the files actually present in the e2e project.
- Generator options or inferred targets differ: Nx and Cypress behavior can depend on installed versions, the project graph, bundler, and target configuration. Check the options and generated target against your workspace’s installed packages; the Nx documentation does not give one version matrix covering every combination.
Or skip the browser setup
If your goal is to capture a page as an image or PDF rather than configure Cypress tests, ScreenshotNeo offers a one-request screenshot API. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000.
For example, save a screenshot of a URL as WebP:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Sign up for 1,000 free screenshots a month, with no card required.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




