ng test, multiple requests for files
🐞 Bug report
Command (mark with an x)
- [ ] new
- [ ] build
- [ ] serve
- [x] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Description
Can't figure out why karma with ng-cli, requires main.js/vendors.js/boot.js multiple times ( 3 times )
In our case, this is a problem, because final size of all sources that downloaded by browser ~ 760mb
🔬 Minimal Reproduction
ng new karma-app ng test open devtools, see network tab
🌍 Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 8.3.18
Node: 12.12.0
OS: darwin x64
Angular: 8.2.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.803.18
@angular-devkit/build-angular 0.803.18
@angular-devkit/build-optimizer 0.803.18
@angular-devkit/build-webpack 0.803.18
@angular-devkit/core 8.3.18
@angular-devkit/schematics 8.3.18
@angular/cli 8.3.18
@ngtools/webpack 8.3.18
@schematics/angular 8.3.18
@schematics/update 0.803.18
rxjs 6.4.0
typescript 3.5.3
webpack 4.39.2
I played around a bit in a local project and it seems that zone.js is interfering with this:
with import 'zone.js/dist/long-stack-trace-zone';

without:

This is also a reason why we had issues with unit tests failing with out of memory errors with ~5000 tests and code coverage enabled.
@novathore are you using long stack trace import?
EDIT: Looking it the long-stack-trace-zone.js, its kind of hard to see how such side effect could happen
Experiencing the same issue here, this seems to causes memory problems on CI builds when there are a very large number of tests. We've been running tests with source maps and code coverage enabled. We have observed that if we turn off source maps (--source-map=false) the issue does not occur and only single files are added.
@devoto13, can you please chime in? I think this is expected with Karma.
It's expected that karma would load files over for every test run. As each test run is effectively loading a web page containing all tests.
But what happens here is not that, because there was only one test run therefore one page load. First file load (of type script) is actually done by karma to run tests, but two others (of type xhr) seems to be done by jasmine-core for something related to source mapping of stack traces (judging from the stack trace which has triggered those requests). I'm not sure if that is expected or not and why it is performed twice. I'll try to look deeper into it when I've got some time.
UPD ~~Thinking more about it, https://github.com/angular/angular-cli/issues/16160#issuecomment-562737527 may actually be on the right track, but I'm not so familiar with zone.js internals to say for sure.~~ Nah, sounds more like jasmine-core thing.
Thanks @devoto13 for the pointer. It turns out that this happens only when sourcemaps are enabled. And the is a side effect of source-map-support which initiates XHR requests to JS files.
This really is a problem, as regularly, when running tests in CI you'd want enabled source maps to get meaningful coverage reports (see e.g. https://stackoverflow.com/questions/56011993/why-does-the-source-maps-flag-effect-the-code-coverage-report-in-angular-7 ). Could someone please address this?
@daniel-sc, from my investigate this turns out to be working as expected when source-maps are enabled due to how https://github.com/evanw/node-source-map-support/ works.
At this point there is not much we can do around this.
Closing as this is not actionable since this is expected when source maps are enable as explained above.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.