Nx: `nx test` does not run all tests

Created on 18 Jun 2020  路  9Comments  路  Source: nrwl/nx

I recently updated my nrwl/nx workspace to the latest version. I noted that you aliased the ng command to nx! In this context, i noticed, that nx test does not run all tests in the monorepository!

This may be a regression!

Current Behavior


nx test does not run all tests in the monorepository,
ng test does, in fact, run all! (as before!)

Expected Behavior


This may be a regression!
previously, i was able to run all my tests in the monorepo with ng test, however nx test does not run all tests.
Running nx test from the cli, internally invokes the command ng run app-web:test

Steps to Reproduce





This issue may not be prioritized if details are not provided to help us reproduce the issue.

Failure Logs

Environment


nx report

>  NX  Report complete - copy this into the issue template

  @nrwl/angular : 9.4.3
  @nrwl/cli : 9.4.3
  @nrwl/cypress : 9.4.3
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 9.4.3
  @nrwl/linter : 9.4.3
  @nrwl/nest : 9.4.3
  @nrwl/next : Not Found
  @nrwl/node : 9.4.3
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 9.4.3
  @nrwl/web : Not Found
  @nrwl/workspace : 9.4.3
  typescript : 3.8.3
bug

Most helpful comment

This is be design. Different projects in the repo can use different test runners, different configurations etc, so there is no way for us to run all of them in the same process. npx nx run-many --all --target=test is the way to do it. You can also run them in parallel, as follows: npx nx run-many --all --target=test --parallel

All 9 comments

Same result for lint commands. nx lint run only for default project and ng lint for all projects.

confirm happens here as well:

nx report
  @nrwl/angular : 9.4.5
  @nrwl/cli : 9.4.5
  @nrwl/cypress : 9.4.5
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 9.4.5
  @nrwl/linter : Not Found
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 9.4.5
  @nrwl/web : Not Found
  @nrwl/workspace : 9.4.5
  typescript : 3.8.3

it actually runs only the default project and not all of them

I found you can run multiple projects using this:
npm run ng -- run-many --all --target=test
of if you have nx installed globally on your machine:
nx run-many --all --target=test

This is be design. Different projects in the repo can use different test runners, different configurations etc, so there is no way for us to run all of them in the same process. npx nx run-many --all --target=test is the way to do it. You can also run them in parallel, as follows: npx nx run-many --all --target=test --parallel

@vsavkin Hi, its worth mentioning that on the CI - all tests are run when running NX TEST

So our CI was failing but locally I couldn't figure it out as only the main project was being tested - all the library projects were not being run.

This isn't consistent then ?

So the CI is wrong ? it shouldn't run all tests ?

@iangregsondev , you mean, that nx test has different execution semantics on your local development machine compared to the ci?

are you sure your local dev environment and the ci have the same versions installed?

@vsavkin maybe we should document this better? i.e., moving from ng test to nx test has different semantics, therefore it may break stuff, when only changing ng to nx. Maybe we can add this to the docs? I would be willing to add a PR to the docs, if you like!

Thanks for pointing this out!

Yes 100% I spent almost a full day trying to figure it out :-(

Local same version of node, same repo.

CI : nx test - all tests are run including all libraries

LOCAL: nx test - only tests that belong to the main project are run (no libraries nothing else)

Managed to reproduce it locally by passing in the --ci parameter and it prints out

 npm run test -- --ci

> nx run-many --all --target=test "--ci"

notice that passing in the ci causes it to run

nx run-many --all --target=test "--ci"

so what is the difference with calling the command with --ci?

@johannesschobel well if you call it with the command CI (which is automatically done on the CI server anyway you do not pass the CI), it seems that it internally calls

nx run-many --all --target=test "--ci"

So it is actually calling the recommended command ie.

npx nx run-many --all --target=test

but we know of course, calling this on a NON ci machine then it does not call the nx run-many

SO there is an inconsistency there.

As stated above, I was only passing the CI command locally to simulate a CI environment.

Cheers

I am not sure if it's intended or not.

Since the semantics of nx have changed, this line in the documentation probably needs a rewrite:

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vimalraj-a picture vimalraj-a  路  3Comments

olakara picture olakara  路  3Comments

Svancara picture Svancara  路  3Comments

zachnewburgh picture zachnewburgh  路  3Comments

ZempTime picture ZempTime  路  3Comments