idea: run failed tests first and fail fast
The recently added feature of PRs #576 #587 allows us to re-run the failed tests of previously failed projects (apps/libs) only, when we add the --only-failed flag to the next execution of the affected:test script. This reduces the number of tests to run when fixing things quite a lot, if a lot of projects are affected. If only a few projects are affected the benefit is not as big.
My idea now is to extend this by running the failed tests only instead of all the tests of a failed project. Somehow each test needs to be tracked in addition to the information of what project failed. This would reduce the number of tests to re-run when fixing things even more, and only after this tests are green I would re-run without the --only-failed flag to check if the other tests are still passing.
Another option for situations like this can be a new flag, or 2 new flags:
-
--failed-first: if you pass this flag to theaffected:testcommand you only change the order of the tests to be executed, still all tests will be executed but the previously failed ones run first. This could be useful in combination with the--only-failedflag (or maybe rename to--only-failed-projects) too, still all tests of the previously failed projects will be executed. If you omit the--only-failedflag all affected tests will be executed, but the previously failed ones first. -
--fail-fast: if you pass this flag to the execution of anaffected:*task the execution will stop immediately. if you use the combination--failed-first --fail-fastthere is no need to separately execute all tests after fixing things, they will be executed automatically if everything is fine after fixing, and if there still is an error, the execution will stop immediately. fixing things one by one ...
What do you think about the ideas?
ps: I will create two more issues for some ideas (adding --watch for affected:* tasks, create a custom architect builder for the angular cli to configure nx tasks using angular.json)
Great ideas and write up :+1:
Increasing the granularity is indeed very useful. Saving the information is the hard part. I believe jest might do this quite well right now...
I like the flags:
--failed-first should be used during CI where you want to eventually run all tests. It's not that great of a choice for development though since you don't want to run all of your tests immediately after making a change to fix it.
--fail-fast I actually had this while I was developing it originally :)
- One consideration here is that the order might not be ideal. If you're not fixing the first one here, it's not as useful. The test you altered might not even get run. For CI it's okay if you expect your result to be a boolean. It will probably default to false
Thx for your feedback @FrozenPandaz !!
When I read jest is doing this quite well, I thought about the responsibility of that kind of feature once more and think the testrunner tool should handle this kind of features, as you mentioned. --only-failed is doing a great job independently of the testrunner being used.
When I migrated to V6 I was very sad about the fact that the tests were separated, because the execution time of running all tests increased quite heavily. I am very happy about the --parallel flag, and after deactivating source maps when I run the tests during CI the execution time was all good again. The compilation takes quite a long time, and things get compiled more than once during test execution, if projects have dependend projects they get compiled for every project that depends on it - at least it seems like, previously this was done just once for all projects and then the tests ran. Am I right on that? I did use karma-parallel to speed it up a little, now I deactivated karma-parallel because the amount of tests within one execution is now not big enough to do parallelization within one project (maybe for some...). Now with --only-failed the development is smooth again too, still using fdescribe, and nx is running the right projects.
--fail-fast - how did you activate it? :) I still think this is something nx should handle, at project level for every task and not just tests, and could be passed separately to the test runner with a separate flag, if the testrunner supports that, just found karma-fail-fast-reporter ...
... back from my summer timeout and started to think about this issue again - I am still interested in optimizing this, and just on time jest is supported now by nx, with the custom nrwl builder. great choice to do it that way, this offers a lot - still configuring at angular.json. I included jest myself with the help of the infos I got out of #497 and I am very happy with it at the moment. As I mentioned, just right on time (for me) nx is supporting that out of the box. It is only supported for apps at the moment for what I saw, have to check this. We are thinking about replacing karma with jest, the experience using jest was really good. No browser related errors (timeouts ...) that occur from time to time when the par. execution comes to its limit (if you have no par. max. set) and things like that. Jest was faster with a single execution, no need to par. jest - it comes out of the box. Have to check the options of jest itself. It should be possible to configure the jest architect builder in angular.json, setting the jest parameters there - is this already possible? A lot of things to check out, just wanted to say great work with the jest integration and the cusom architect builder!!
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.