Skip to content

Automatically Split Slow Tasks by File (Atomizer)

Certain tasks like end-to-end (e2e) tests, integration tests, or large unit test suites can be large, monolithic tasks that take a considerable amount of time to execute. As a result, teams often push them to a nightly or even weekly build rather than running them for each PR. This approach is suboptimal as it increases the risk of merging problematic PRs.

Manually splitting these slow tasks can be complex and require ongoing maintenance. Nx's Atomizer solves this by automatically generating runnable targets for each test file. For example, a task that takes 10 minutes can be split and distributed as five 2-minute tasks per agent. This allows for:

To use automated task splitting, you need to connect your workspace to Nx Cloud (if you haven't already).

npx nx@latest connect

See the connect to Nx Cloud recipe for all the details.

Run this command to set up inferred tasks and enable task splitting for each plugin:

nx add @nx/cypress

This command will register the appropriate plugin in the plugins array of nx.json.

If you upgraded Nx from an older version, ensure that inferred tasks are enabled in nx.json:

nx.json
{
...
// turned on by default; just make sure it is not set to false
useInferencePlugins: true
}

Update an Existing Project to use Automated Task Splitting

Section titled “Update an Existing Project to use Automated Task Splitting”

If you are already using the @nx/cypress, @nx/playwright, @nx/jest, or @nx/gradle plugin, you need to manually add the appropriate configuration to the plugins array of nx.json. Follow the instructions for the plugin you are using:

Run the following command to open the project detail view for your test project:

nx show project my-project-e2e

If you configured Nx Atomizer properly, you'll see that there are tasks named e2e, e2e-ci (or similar for other test types) and a task for each test file.

During local development, you'll want to continue using the base task (e.g., e2e, test) as it is more efficient on a single machine.

nx e2e my-project-e2e

The -ci variant task truly shines when configured and run on CI.

Update your CI pipeline to run the -ci variant task (e.g., e2e-ci, test-ci), which will automatically run all the inferred tasks for the individual test files. Here's an example of a GitHub Actions workflow:

.github/workflows/ci.yml
name: CI
# ...
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- uses: pnpm/action-setup@v4
with:
version: 9
- run: pnpm dlx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci"
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- uses: nrwl/nx-set-shas@v4
- run: pnpm exec nx affected -t lint test build e2e-ci

Learn more about configuring your CI provider by following these detailed recipes.