-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Total rebuild test time in medium and large projects #8579
Comments
Upgrading to cli 1.5 / angular 5 should speed things up quite a lot. Alternatively (since this is a large project), disable sourcemaps (--sourcemaps=false), that should decrease the vendor bundle by a large amount and make the build faster. |
We did some work to speed up rebuilds in 1.5.0 as @lucasvanhalst mentioned, but I know this is still a problem for many projects. There's a couple of parts to this issue:
Let's look at them individually. Rebuild timeThis is the domain of the CLI build system. We have a highly customized karma webpack plugin that allows for a vendor chunk (#6160). This helps in rebuilds by allowing your test chunk to be rebuilt separately from the vendor chunk. Generally speaking, smaller chunks are faster to rebuild so it helps to split. You can actually further split your test chunks as well using Modify your test files like this:
Splitting your tests into chunk should make rebuilds faster. Turning off sourcemaps also helps (by making rebundling faster) but then debugging will be hard. Karma test run timeAfter a rebuild Karma will load your bundles and re-run all tests. So the more tests you have, the longer this will take. I think this is the problem most people actually have. Jest solves this problem by only re-running stuff that needs to be run again. Last I checked we couldn't really plug the webpack build setup (just try to convert) into it so it's not an option. The best you can do to limit this is limit the re-run tests via JIT compilation timeAfter your code is rebuilt, it is loaded by the browser and tests are ran. Unit tests are always ran in JIT mode, which means that component templates are compiled in the browser. This takes time. It's fairly imperceptible in small projects but becomes noticeable as template complexity and number increase. Outside of unit tests, this is the time after the rebuild is done and your browser has reloaded, but your screen is white and your application hasn't actually loaded. That's the JIT compiler processing templates. The solution to reducing this time is to use AOT in unit tests, which means that the build step would also compile templates. This is still experimental so we haven't added support to it in the CLI (see #8007 (comment)). So for now there isn't much that you can do to reduce this time (apart from limiting the specs as listed in the |
Does 1.5.x require Angular v5? If so, I will have to schedule for our project to be updated (which is quite a large task in itself).
Can you elaborate on the splitting the tests into chunks? Would these files be per test? (for example,
Understand, I'm not too worried about the test run time, we have approx. ~1500 tests, and I'm actually surprised how quickly this phase runs all things considered. During development, we will focus a suite or spec with
Does the compiler compile all templates here, or just those run as part of the tests? They are declared in the Is there a way to minify just the vendor bundle for tests? If it's all 3rd party modules, I'm likely not going to debug it (that often hopefully!). |
1.5 itself doesn't require Angular 5 but the new pipeline does. So effectively the rebuild improvements are only if you update both. I'd try to just split them by folders really, to have a feel for it. So you could do something like:
And so forth for the other top level modules. Only templates for components being used at runtime are compiled. No way to minify just the vendor bundle but I don't see how that would help. Minifying takes time, and if it's unchanged between builds it's also cached. |
As an update... We are in the process of moving our code and all its libraries into a mono-repo, as part of that process I've updated to Angular 5.1.0 and CLI 1.6.1. We are now running ~ 3000 specs. The code splitting using the lazy chunks have definitely helped the build / rebuild cycle, and loading a 'suite' of tests into the browser is much faster than loading the one bundle. However, we am still hitting issues with the time taken to actually run the tests. A full run takes about 20 mins when it completes. This is generally what we get on CI, with random timeouts when running locally (note that I've disabled a lot of tests still, hence the lower numbers)
I've been looking into the suggestions posted in this issue: angular/angular#12409 I've also looked into running the tests in Jest and also following the progress on Bazel very closely here: https://github.com/alexeagle/angular-bazel-example |
I remember @wardbell had some woes in running unit tests that were individually heavy, he might have some advice here. The disconnects are bad though. That might need an increased timeout in Karma? Maybe that's not it though. |
Apologies for the slow update here, been away for the holiday period. After running though some investigation, I've managed to get our tests running without issue.
A timeout occurs and then disconnects.
After these changes, our tests run in approx 10mins, including on CI. |
Heya, I'm closing this issue as the overall discussion seems to have run its course. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Versions
Observed behavior
Running tests on medium and large projects take a long time to start, recompile and rerun tests.
We have are continually increasing the timeouts within the
karma.conf
file for the amount of time given to Chrome before it disconnects from no activity (increased bothcaptureTimeout
andbrowserNoActivityTimeout
).We have also experienced issues where, due to the timeout, we have multiple (headless) Chrome instances running the tests where Karma has started another instance (although this sounds like an issue with Karma, but I thought I'd mention it)
On our project in particular, the vendor bundle is ~15mb, which is taking a long time to load when running the test in debug mode (watching the network activity in Chrome before the tests start).
Opening this issue for a broader discussion with @filipesilva
The text was updated successfully, but these errors were encountered: