Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Build and Test React Apps with Nx and Cypress

Use Nx generators to configure Cypress e2e or React component testing, verify the generated targets, and run the tests locally or in CI.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure Cypress e2e testing for an existing app

  1. From the workspace root, generate an e2e configuration for the app:

    nx g @nx/cypress:configuration --project=your-app-name

    Replace your-app-name with the project name in your Nx workspace.

  2. 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:4200

    Use the actual URL and port for your app. Whether you need this option depends on the generated configuration and how the app is served.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Run the generated e2e project:

    nx e2e your-e2e-project

    Use 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

  1. 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-project

    Replace your-project with the React project name in the workspace.

  2. Inspect the generated component-test target 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:

    nx g @nx/react:cypress-component-configuration --project=my-react-app --build-target=my-react-app:build

    A 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.

  3. To ask the generator to add tests for existing components, include --generate-tests:

    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
  4. 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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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 --baseUrl and ensure the app is running at that address.
  • nx e2e cannot 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-target that exists in the workspace, such as my-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: true and 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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.