Getting started
Tutorial
Fundamentals
Training
Tutorial total points: 0 / 92

Step 10: Test Affected Projects

Because Nx understands the dependency graph of your workspace, Nx can be efficient at retesting and rebuilding your projects.

Commit all the changes in the repo:

git add .
git commit -am 'init'

Open todos.component.html and change the template:

<ul>
  <li *ngFor="let t of todos">{{ t.title }}!</li>
</ul>

Run npm run affected:apps -- --base=master, and you should see todos printed out. The affected:apps looks at what you have changed compared to base (in this case master) and uses the dependency graph to figure out which apps can be affected by this change.

Run npm run affected:libs -- --base=master, and you should see ui printed out. This command works similarly, but instead of printing the affected apps, it prints the affected libs.

Test Affected Projects

Printing the affected projects can be handy, but usually you want to do something with them. For instance, you may want to test everything that has been affected.

Run npm run affected:test -- --base=master to retest all the affected projects.

You will see the following:

Running test for affected projects failed.
Failed projects: todos
You can isolate the above projects by passing --only-failed

One of the projects failed. Instead of retesting every single project on every change, pass --only-failed to only retest the failed ones.

Run npm run affected:test -- --base=master --only-failed to retest the failed projects.

Testing in Parallel

Some changes affect every single project in the repository. To speed up the testing of this change, pass --parallel.

Run npm run affected:test -- --base=master --parallel to test all projects in parallel

Quiz

Check in the changes into master and run "npm run affected:test -- --base=master". What do you see?

  • Cannot run tests against master error

  • The todos project failed as before

  • No tests ran