Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nx@6 ng test runs only first app #514

Closed
DenysVuika opened this issue May 23, 2018 · 13 comments
Closed

nx@6 ng test runs only first app #514

DenysVuika opened this issue May 23, 2018 · 13 comments

Comments

@DenysVuika
Copy link

After upgrade, when running the "npm test" or "ng test", only tests for the first application are executed. And it runs in the watch mode.

Moreover, if I shut down the process, the second project test run is performed, and so for each project in the workspace I have.

Expected behaviour: it should run all tests as it did before the upgrade

@juristr
Copy link
Member

juristr commented May 23, 2018

After upgrade, when running the "npm test" or "ng test", only tests for the first application are executed. And it runs in the watch mode.

Really depends whether that's the new behavior that follows the official Angular CLI. Would be interesting to hear from the NRWL team what they think about it. Anyways, you could wire it up yourself as I did, something like (it's cumbersome, though):

"test": "npm-run-all test:p-*",
"test:p-project1": "ng test --no-watch --project=project1 --source-map=false",
"test:p-project2": "ng test --no-watch --project=project2 --source-map=false",
"test:p-project3": "ng test --no-watch --project=project3 --source-map=false",

Moreover generally speaking I guess it's preferred to use the affected:test script when possible.

Moreover, if I shut down the process, the second project test run is performed, and so for each project in the workspace I have.

yep, notice such strange behavior as well.

@DenysVuika
Copy link
Author

I just checked and this behaviour is coming from the Angular CLI. At least I am able to reproduce the same issue there.

@juristr
Copy link
Member

juristr commented May 23, 2018

@DenisVuyka Yes, guessed so. However it would be nice to have a global test script that collects all test cases. don't have the time right now, but in theory one could configure an app that points a karma and test.ts file at the root and run that. Very much like NX v1.x did it.

Also from a TDD perspective. Like if I'm working on a feature which spans across some app & libs, I'd like to run all test cases to immediately see whether I'm breaking something.

@listepo-alterpost
Copy link
Contributor

+1, very important feature. What is the position of the Angular team about this?

@emilio-martinez
Copy link
Contributor

You can change the tests to not watch by default via the angular json config. That will make it so that it goes one after another; it won't aggregate all tests across projects and run them together. Not ideal, but can work for the time being.

@vsavkin
Copy link
Member

vsavkin commented Jun 9, 2018

This is the change in the Angular CLI 6. With Nx, you can restore the old behavior.

You can test one project, like this:

ng test myproject

You can test all projects using affected:*, like this:

yarn affected:test --files=package.json

Ideally, though, you would only retest the things that were affected by your change:

yarn affected:test --base=master --head=HEAD

And you can also do it in parallel:

yarn affected:test --base=master --head=HEAD --parallel

You are also in the process of adding --only-failed, so you can retest only the failed projects that.

yarn affected:test --base=master --head=HEAD --parallel --only-failed

@Nxt3
Copy link

Nxt3 commented Jun 22, 2018

Has anyone had any luck with this in regards to multiple karmaConfig files? Part of my team's CI needs a way to run unit and component tests for all apps--and the karma.conf is different for both.

@jasedwards
Copy link

I just used one karma conf file for not watching and another for watching. then for each app I have an npm script called "test-app1", "test-app2", "live-app1", "live-app2"... the build server calls a script called "test_all" that runs "npm run all test-*". this works well enough. The live scripts all reference the same karma file so I did not need to create one for each app. the test_all takes forever though because it starts a new process after each app and library. of which I have 12.

@juristr
Copy link
Member

juristr commented Jun 25, 2018

The latest version if NX should allow doing this by using the affected:test script and appending --all (or similar). They described it in their latest blog post

@Nxt3
Copy link

Nxt3 commented Jun 25, 2018

@jasedwards That's not ideal for a project with 10+ libraries--for me, it'd be like 30 lines extra for tests.

@jasedwards
Copy link

@Nxt3 agreed. I am hoping this is a temporary workaround

@mohyeid
Copy link

mohyeid commented Jan 7, 2019

The latest version if NX should allow doing this by using the affected:test script and appending --all (or similar). They described it in their latest blog post

Just for documentation and confirming with @juristr this now works with nx affected:test --all

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants